Skip to content

Commit 1f4aff7

Browse files
authored
Rollup merge of #122487 - GuillaumeGomez:rename-stmtkind-local, r=oli-obk
Rename `StmtKind::Local` variant into `StmtKind::Let` It comes from this [discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Improve.20naming.20of.20.60ExprKind.3A.3ALet.60.3F). Starting point was: > I often end up looking at [ExprKind::Let](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/enum.ExprKind.html#variant.Let) instead of Local because of the name. I think renaming it (both the `ExprKind` variant and the Let struct) to `LetPattern` or LetPat could improve the situation as I'm not sure I'm not the only one encountering this issue. And then it evolved into: > It's already `Expr::Let` instead of `StmtKind::Local`. Counterproposal: rename `StmtKind::Local` to `StmtKind::Let`. The goal here is to clear this confusion. r? `@oli-obk`
2 parents 5d41186 + ac1b857 commit 1f4aff7

File tree

74 files changed

+103
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+103
-103
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ impl Stmt {
10211021
#[derive(Clone, Encodable, Decodable, Debug)]
10221022
pub enum StmtKind {
10231023
/// A local (let) binding.
1024-
Local(P<Local>),
1024+
Let(P<Local>),
10251025
/// An item definition.
10261026
Item(P<Item>),
10271027
/// Expr without trailing semi-colon.

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<T: HasTokens> HasTokens for Option<T> {
182182
impl HasTokens for StmtKind {
183183
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
184184
match self {
185-
StmtKind::Local(local) => local.tokens.as_ref(),
185+
StmtKind::Let(local) => local.tokens.as_ref(),
186186
StmtKind::Item(item) => item.tokens(),
187187
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens(),
188188
StmtKind::Empty => return None,
@@ -191,7 +191,7 @@ impl HasTokens for StmtKind {
191191
}
192192
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
193193
match self {
194-
StmtKind::Local(local) => Some(&mut local.tokens),
194+
StmtKind::Let(local) => Some(&mut local.tokens),
195195
StmtKind::Item(item) => item.tokens_mut(),
196196
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.tokens_mut(),
197197
StmtKind::Empty => return None,
@@ -355,7 +355,7 @@ impl HasAttrs for StmtKind {
355355

356356
fn attrs(&self) -> &[Attribute] {
357357
match self {
358-
StmtKind::Local(local) => &local.attrs,
358+
StmtKind::Let(local) => &local.attrs,
359359
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.attrs(),
360360
StmtKind::Item(item) => item.attrs(),
361361
StmtKind::Empty => &[],
@@ -365,7 +365,7 @@ impl HasAttrs for StmtKind {
365365

366366
fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) {
367367
match self {
368-
StmtKind::Local(local) => f(&mut local.attrs),
368+
StmtKind::Let(local) => f(&mut local.attrs),
369369
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr.visit_attrs(f),
370370
StmtKind::Item(item) => item.visit_attrs(f),
371371
StmtKind::Empty => {}

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
15671567
vis: &mut T,
15681568
) -> SmallVec<[StmtKind; 1]> {
15691569
match kind {
1570-
StmtKind::Local(mut local) => smallvec![StmtKind::Local({
1570+
StmtKind::Let(mut local) => smallvec![StmtKind::Let({
15711571
vis.visit_local(&mut local);
15721572
local
15731573
})],

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) -> V::R
787787

788788
pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result {
789789
match &statement.kind {
790-
StmtKind::Local(local) => try_visit!(visitor.visit_local(local)),
790+
StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
791791
StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),
792792
StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(visitor.visit_expr(expr)),
793793
StmtKind::Empty => {}

compiler/rustc_ast_lowering/src/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3232
let mut expr = None;
3333
while let [s, tail @ ..] = ast_stmts {
3434
match &s.kind {
35-
StmtKind::Local(local) => {
35+
StmtKind::Let(local) => {
3636
let hir_id = self.lower_node_id(s.id);
3737
let local = self.lower_local(local);
3838
self.alias_attrs(hir_id, local.hir_id);
39-
let kind = hir::StmtKind::Local(local);
39+
let kind = hir::StmtKind::Let(local);
4040
let span = self.lower_span(s.span);
4141
stmts.push(hir::Stmt { hir_id, kind, span });
4242
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2356,7 +2356,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23562356
span: self.lower_span(span),
23572357
ty: None,
23582358
};
2359-
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
2359+
self.stmt(span, hir::StmtKind::Let(self.arena.alloc(local)))
23602360
}
23612361

23622362
fn block_expr(&mut self, expr: &'hir hir::Expr<'hir>) -> &'hir hir::Block<'hir> {

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ impl<'a> State<'a> {
12121212
fn print_stmt(&mut self, st: &ast::Stmt) {
12131213
self.maybe_print_comment(st.span.lo());
12141214
match &st.kind {
1215-
ast::StmtKind::Local(loc) => {
1215+
ast::StmtKind::Let(loc) => {
12161216
self.print_outer_attributes(&loc.attrs);
12171217
self.space_if_not_bol();
12181218
self.ibox(INDENT_UNIT);

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
616616

617617
// FIXME: We make sure that this is a normal top-level binding,
618618
// but we could suggest `todo!()` for all uninitalized bindings in the pattern pattern
619-
if let hir::StmtKind::Local(hir::Local { span, ty, init: None, pat, .. }) =
619+
if let hir::StmtKind::Let(hir::Local { span, ty, init: None, pat, .. }) =
620620
&ex.kind
621621
&& let hir::PatKind::Binding(..) = pat.kind
622622
&& span.contains(self.decl_span)

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
558558
hir::intravisit::walk_stmt(self, stmt);
559559
let expr = match stmt.kind {
560560
hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr,
561-
hir::StmtKind::Local(hir::Local { init: Some(expr), .. }) => expr,
561+
hir::StmtKind::Let(hir::Local { init: Some(expr), .. }) => expr,
562562
_ => {
563563
return;
564564
}
@@ -1305,7 +1305,7 @@ struct BindingFinder {
13051305
impl<'tcx> Visitor<'tcx> for BindingFinder {
13061306
type Result = ControlFlow<hir::HirId>;
13071307
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) -> Self::Result {
1308-
if let hir::StmtKind::Local(local) = s.kind
1308+
if let hir::StmtKind::Let(local) = s.kind
13091309
&& local.pat.span == self.span
13101310
{
13111311
ControlFlow::Break(local.hir_id)

compiler/rustc_expand/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<'a> ExtCtxt<'a> {
218218
}
219219

220220
pub fn stmt_local(&self, local: P<ast::Local>, span: Span) -> ast::Stmt {
221-
ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Local(local), span }
221+
ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Let(local), span }
222222
}
223223

224224
pub fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt {

0 commit comments

Comments
 (0)