Rename ast::StmtKind::Local into ast::StmtKind::Let

This commit is contained in:
Guillaume Gomez 2024-03-14 11:25:05 +01:00
parent 6f3eb1ce3d
commit ca9f0630a9
17 changed files with 24 additions and 24 deletions

View File

@ -1021,7 +1021,7 @@ impl Stmt {
#[derive(Clone, Encodable, Decodable, Debug)] #[derive(Clone, Encodable, Decodable, Debug)]
pub enum StmtKind { pub enum StmtKind {
/// A local (let) binding. /// A local (let) binding.
Local(P<Local>), Let(P<Local>),
/// An item definition. /// An item definition.
Item(P<Item>), Item(P<Item>),
/// Expr without trailing semi-colon. /// Expr without trailing semi-colon.

View File

@ -182,7 +182,7 @@ impl<T: HasTokens> HasTokens for Option<T> {
impl HasTokens for StmtKind { impl HasTokens for StmtKind {
fn tokens(&self) -> Option<&LazyAttrTokenStream> { fn tokens(&self) -> Option<&LazyAttrTokenStream> {
match self { match self {
StmtKind::Local(local) => local.tokens.as_ref(), StmtKind::Let(local) => local.tokens.as_ref(),
StmtKind::Item(item) => item.tokens(), StmtKind::Item(item) => item.tokens(),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens(), StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens(),
StmtKind::Empty => return None, StmtKind::Empty => return None,
@ -191,7 +191,7 @@ impl HasTokens for StmtKind {
} }
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> { fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
match self { match self {
StmtKind::Local(local) => Some(&mut local.tokens), StmtKind::Let(local) => Some(&mut local.tokens),
StmtKind::Item(item) => item.tokens_mut(), StmtKind::Item(item) => item.tokens_mut(),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens_mut(), StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens_mut(),
StmtKind::Empty => return None, StmtKind::Empty => return None,
@ -355,7 +355,7 @@ impl HasAttrs for StmtKind {
fn attrs(&self) -> &[Attribute] { fn attrs(&self) -> &[Attribute] {
match self { match self {
StmtKind::Local(local) => &local.attrs, StmtKind::Let(local) => &local.attrs,
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.attrs(), StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.attrs(),
StmtKind::Item(item) => item.attrs(), StmtKind::Item(item) => item.attrs(),
StmtKind::Empty => &[], StmtKind::Empty => &[],
@ -365,7 +365,7 @@ impl HasAttrs for StmtKind {
fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) { fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) {
match self { match self {
StmtKind::Local(local) => f(&mut local.attrs), StmtKind::Let(local) => f(&mut local.attrs),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f), StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f),
StmtKind::Item(item) => item.visit_attrs(f), StmtKind::Item(item) => item.visit_attrs(f),
StmtKind::Empty => {} StmtKind::Empty => {}

View File

@ -1567,7 +1567,7 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
vis: &mut T, vis: &mut T,
) -> SmallVec<[StmtKind; 1]> { ) -> SmallVec<[StmtKind; 1]> {
match kind { match kind {
StmtKind::Local(mut local) => smallvec![StmtKind::Local({ StmtKind::Let(mut local) => smallvec![StmtKind::Let({
vis.visit_local(&mut local); vis.visit_local(&mut local);
local local
})], })],

View File

@ -787,7 +787,7 @@ pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) -> V::R
pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result { pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result {
match &statement.kind { match &statement.kind {
StmtKind::Local(local) => try_visit!(visitor.visit_local(local)), StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
StmtKind::Item(item) => try_visit!(visitor.visit_item(item)), StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(visitor.visit_expr(expr)), StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(visitor.visit_expr(expr)),
StmtKind::Empty => {} StmtKind::Empty => {}

View File

@ -32,7 +32,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let mut expr = None; let mut expr = None;
while let [s, tail @ ..] = ast_stmts { while let [s, tail @ ..] = ast_stmts {
match &s.kind { match &s.kind {
StmtKind::Local(local) => { StmtKind::Let(local) => {
let hir_id = self.lower_node_id(s.id); let hir_id = self.lower_node_id(s.id);
let local = self.lower_local(local); let local = self.lower_local(local);
self.alias_attrs(hir_id, local.hir_id); self.alias_attrs(hir_id, local.hir_id);

View File

@ -1212,7 +1212,7 @@ impl<'a> State<'a> {
fn print_stmt(&mut self, st: &ast::Stmt) { fn print_stmt(&mut self, st: &ast::Stmt) {
self.maybe_print_comment(st.span.lo()); self.maybe_print_comment(st.span.lo());
match &st.kind { match &st.kind {
ast::StmtKind::Local(loc) => { ast::StmtKind::Let(loc) => {
self.print_outer_attributes(&loc.attrs); self.print_outer_attributes(&loc.attrs);
self.space_if_not_bol(); self.space_if_not_bol();
self.ibox(INDENT_UNIT); self.ibox(INDENT_UNIT);

View File

@ -218,7 +218,7 @@ impl<'a> ExtCtxt<'a> {
} }
pub fn stmt_local(&self, local: P<ast::Local>, span: Span) -> ast::Stmt { pub fn stmt_local(&self, local: P<ast::Local>, span: Span) -> ast::Stmt {
ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Local(local), span } ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Let(local), span }
} }
pub fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt { pub fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt {

View File

@ -1389,7 +1389,7 @@ impl InvocationCollectorNode for ast::Stmt {
StmtKind::Item(item) => matches!(item.kind, ItemKind::MacCall(..)), StmtKind::Item(item) => matches!(item.kind, ItemKind::MacCall(..)),
StmtKind::Semi(expr) => matches!(expr.kind, ExprKind::MacCall(..)), StmtKind::Semi(expr) => matches!(expr.kind, ExprKind::MacCall(..)),
StmtKind::Expr(..) => unreachable!(), StmtKind::Expr(..) => unreachable!(),
StmtKind::Local(..) | StmtKind::Empty => false, StmtKind::Let(..) | StmtKind::Empty => false,
} }
} }
fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) { fn take_mac_call(self) -> (P<ast::MacCall>, Self::AttrsTy, AddSemicolon) {

View File

@ -989,7 +989,7 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &
impl EarlyLintPass for UnusedDocComment { impl EarlyLintPass for UnusedDocComment {
fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) { fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) {
let kind = match stmt.kind { let kind = match stmt.kind {
ast::StmtKind::Local(..) => "statements", ast::StmtKind::Let(..) => "statements",
// Disabled pending discussion in #78306 // Disabled pending discussion in #78306
ast::StmtKind::Item(..) => return, ast::StmtKind::Item(..) => return,
// expressions will be reported by `check_expr`. // expressions will be reported by `check_expr`.

View File

@ -914,7 +914,7 @@ trait UnusedDelimLint {
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) { fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
match s.kind { match s.kind {
StmtKind::Local(ref local) if Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX => { StmtKind::Let(ref local) if Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX => {
if let Some((init, els)) = local.kind.init_else_opt() { if let Some((init, els)) = local.kind.init_else_opt() {
let ctx = match els { let ctx = match els {
None => UnusedDelimsCtx::AssignedValue, None => UnusedDelimsCtx::AssignedValue,
@ -1189,7 +1189,7 @@ impl EarlyLintPass for UnusedParens {
} }
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) { fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
if let StmtKind::Local(ref local) = s.kind { if let StmtKind::Let(ref local) = s.kind {
self.check_unused_parens_pat(cx, &local.pat, true, false, (true, false)); self.check_unused_parens_pat(cx, &local.pat, true, false, (true, false));
} }

View File

@ -254,7 +254,7 @@ impl<'a> Parser<'a> {
let local = this.parse_local(attrs)?; let local = this.parse_local(attrs)?;
// FIXME - maybe capture semicolon in recovery? // FIXME - maybe capture semicolon in recovery?
Ok(( Ok((
this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Local(local)), this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Let(local)),
TrailingToken::None, TrailingToken::None,
)) ))
})?; })?;
@ -278,7 +278,7 @@ impl<'a> Parser<'a> {
} else { } else {
TrailingToken::None TrailingToken::None
}; };
Ok((this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Local(local)), trailing)) Ok((this.mk_stmt(lo.to(this.prev_token.span), StmtKind::Let(local)), trailing))
}) })
} }
@ -764,7 +764,7 @@ impl<'a> Parser<'a> {
} }
} }
StmtKind::Expr(_) | StmtKind::MacCall(_) => {} StmtKind::Expr(_) | StmtKind::MacCall(_) => {}
StmtKind::Local(local) if let Err(mut e) = self.expect_semi() => { StmtKind::Let(local) if let Err(mut e) = self.expect_semi() => {
// We might be at the `,` in `let x = foo<bar, baz>;`. Try to recover. // We might be at the `,` in `let x = foo<bar, baz>;`. Try to recover.
match &mut local.kind { match &mut local.kind {
LocalKind::Init(expr) | LocalKind::InitElse(expr, _) => { LocalKind::Init(expr) | LocalKind::InitElse(expr, _) => {
@ -820,7 +820,7 @@ impl<'a> Parser<'a> {
} }
eat_semi = false; eat_semi = false;
} }
StmtKind::Empty | StmtKind::Item(_) | StmtKind::Local(_) | StmtKind::Semi(_) => { StmtKind::Empty | StmtKind::Item(_) | StmtKind::Let(_) | StmtKind::Semi(_) => {
eat_semi = false eat_semi = false
} }
} }

View File

@ -539,7 +539,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
fn visit_stmt(&mut self, s: &'v ast::Stmt) { fn visit_stmt(&mut self, s: &'v ast::Stmt) {
record_variants!( record_variants!(
(self, s, s.kind, Id::None, ast, Stmt, StmtKind), (self, s, s.kind, Id::None, ast, Stmt, StmtKind),
[Local, Item, Expr, Semi, Empty, MacCall] [Let, Item, Expr, Semi, Empty, MacCall]
); );
ast_visit::walk_stmt(self, s) ast_visit::walk_stmt(self, s)
} }

View File

@ -267,7 +267,7 @@ pub fn eq_block(l: &Block, r: &Block) -> bool {
pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool { pub fn eq_stmt(l: &Stmt, r: &Stmt) -> bool {
use StmtKind::*; use StmtKind::*;
match (&l.kind, &r.kind) { match (&l.kind, &r.kind) {
(Local(l), Local(r)) => { (Let(l), Let(r)) => {
eq_pat(&l.pat, &r.pat) eq_pat(&l.pat, &r.pat)
&& both(&l.ty, &r.ty, |l, r| eq_ty(l, r)) && both(&l.ty, &r.ty, |l, r| eq_ty(l, r))
&& eq_local_kind(&l.kind, &r.kind) && eq_local_kind(&l.kind, &r.kind)

View File

@ -26,7 +26,7 @@ pub(crate) fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {
pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span { pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
match stmt.kind { match stmt.kind {
ast::StmtKind::Local(ref local) => local.span, ast::StmtKind::Let(ref local) => local.span,
ast::StmtKind::Item(ref item) => item.span, ast::StmtKind::Item(ref item) => item.span,
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => expr.span, ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => expr.span,
ast::StmtKind::MacCall(ref mac_stmt) => mac_stmt.mac.span(), ast::StmtKind::MacCall(ref mac_stmt) => mac_stmt.mac.span(),

View File

@ -61,7 +61,7 @@ implement_spanned!(ast::Local);
impl Spanned for ast::Stmt { impl Spanned for ast::Stmt {
fn span(&self) -> Span { fn span(&self) -> Span {
match self.kind { match self.kind {
ast::StmtKind::Local(ref local) => mk_sp(local.span().lo(), self.span.hi()), ast::StmtKind::Let(ref local) => mk_sp(local.span().lo(), self.span.hi()),
ast::StmtKind::Item(ref item) => mk_sp(item.span().lo(), self.span.hi()), ast::StmtKind::Item(ref item) => mk_sp(item.span().lo(), self.span.hi()),
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => { ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => {
mk_sp(expr.span().lo(), self.span.hi()) mk_sp(expr.span().lo(), self.span.hi())

View File

@ -115,7 +115,7 @@ fn format_stmt(
skip_out_of_file_lines_range!(context, stmt.span()); skip_out_of_file_lines_range!(context, stmt.span());
let result = match stmt.kind { let result = match stmt.kind {
ast::StmtKind::Local(ref local) => local.rewrite(context, shape), ast::StmtKind::Let(ref local) => local.rewrite(context, shape),
ast::StmtKind::Expr(ref ex) | ast::StmtKind::Semi(ref ex) => { ast::StmtKind::Expr(ref ex) | ast::StmtKind::Semi(ref ex) => {
let suffix = if semicolon_for_stmt(context, stmt, is_last_expr) { let suffix = if semicolon_for_stmt(context, stmt, is_last_expr) {
";" ";"

View File

@ -150,7 +150,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
self.visit_item(item); self.visit_item(item);
self.last_pos = stmt.span().hi(); self.last_pos = stmt.span().hi();
} }
ast::StmtKind::Local(..) | ast::StmtKind::Expr(..) | ast::StmtKind::Semi(..) => { ast::StmtKind::Let(..) | ast::StmtKind::Expr(..) | ast::StmtKind::Semi(..) => {
let attrs = get_attrs_from_stmt(stmt.as_ast_node()); let attrs = get_attrs_from_stmt(stmt.as_ast_node());
if contains_skip(attrs) { if contains_skip(attrs) {
self.push_skipped_with_span( self.push_skipped_with_span(