Skip to content

Commit 21a6f0c

Browse files
authored
Rollup merge of rust-lang#122780 - GuillaumeGomez:rename-hir-local, r=oli-obk
Rename `hir::Local` into `hir::LetStmt` Follow-up of rust-lang#122776. As discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Improve.20naming.20of.20.60ExprKind.3A.3ALet.60.3F). I made this change into a separate PR because I'm less sure about this change as is. For example, we have `visit_local` and `LocalSource` items. Is it fine to keep these two as is (I supposed it is but I prefer to ask) or not? Having `Node::Local(LetStmt)` makes things more explicit but is it going too far? r? ```@oli-obk```
2 parents e5ece90 + 43a61e9 commit 21a6f0c

Some content is hidden

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

47 files changed

+96
-96
lines changed

clippy_lints/src/assigning_clones.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallC
163163
// TODO: This check currently bails if the local variable has no initializer.
164164
// That is overly conservative - the lint should fire even if there was no initializer,
165165
// but the variable has been initialized before `lhs` was evaluated.
166-
if let Some(Node::Local(local)) = cx.tcx.hir().parent_id_iter(local).next().map(|p| cx.tcx.hir_node(p))
166+
if let Some(Node::LetStmt(local)) = cx.tcx.hir().parent_id_iter(local).next().map(|p| cx.tcx.hir_node(p))
167167
&& local.init.is_none()
168168
{
169169
return false;

clippy_lints/src/box_default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::{is_default_equivalent, path_def_id};
66
use rustc_errors::Applicability;
77
use rustc_hir::def::Res;
88
use rustc_hir::intravisit::{walk_ty, Visitor};
9-
use rustc_hir::{Block, Expr, ExprKind, Local, Node, QPath, Ty, TyKind};
9+
use rustc_hir::{Block, Expr, ExprKind, LetStmt, Node, QPath, Ty, TyKind};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
1111
use rustc_middle::lint::in_external_macro;
1212
use rustc_middle::ty::print::with_forced_trimmed_paths;
@@ -139,7 +139,7 @@ impl<'tcx> Visitor<'tcx> for InferVisitor {
139139

140140
fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
141141
match cx.tcx.parent_hir_node(expr.hir_id) {
142-
Node::Local(Local { ty: Some(ty), .. }) => {
142+
Node::LetStmt(LetStmt { ty: Some(ty), .. }) => {
143143
let mut v = InferVisitor::default();
144144
v.visit_ty(ty);
145145
!v.0

clippy_lints/src/casts/ref_as_ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(
2424
&& let ty::RawPtr(_, to_mutbl) = cast_to.kind()
2525
&& let Some(use_cx) = expr_use_ctxt(cx, expr)
2626
// TODO: only block the lint if `cast_expr` is a temporary
27-
&& !matches!(use_cx.node, ExprUseNode::Local(_) | ExprUseNode::ConstStatic(_))
27+
&& !matches!(use_cx.node, ExprUseNode::LetStmt(_) | ExprUseNode::ConstStatic(_))
2828
{
2929
let core_or_std = if is_no_std_crate(cx) { "core" } else { "std" };
3030
let fn_name = match to_mutbl {

clippy_lints/src/casts/unnecessary_cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub(super) fn check<'tcx>(
6666
&& let QPath::Resolved(None, Path { res, .. }) = qpath
6767
&& let Res::Local(hir_id) = res
6868
&& let parent = cx.tcx.parent_hir_node(*hir_id)
69-
&& let Node::Local(local) = parent
69+
&& let Node::LetStmt(local) = parent
7070
{
7171
if let Some(ty) = local.ty
7272
&& let TyKind::Path(qpath) = ty.kind
@@ -275,7 +275,7 @@ fn is_cast_from_ty_alias<'tcx>(cx: &LateContext<'tcx>, expr: impl Visitable<'tcx
275275
}
276276
// Local usage
277277
} else if let Res::Local(hir_id) = res
278-
&& let Node::Local(l) = cx.tcx.parent_hir_node(hir_id)
278+
&& let Node::LetStmt(l) = cx.tcx.parent_hir_node(hir_id)
279279
{
280280
if let Some(e) = l.init
281281
&& is_cast_from_ty_alias(cx, e, cast_from)

clippy_lints/src/collection_is_never_read.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
33
use clippy_utils::visitors::for_each_expr_with_closures;
44
use clippy_utils::{get_enclosing_block, path_to_local_id};
55
use core::ops::ControlFlow;
6-
use rustc_hir::{Block, ExprKind, HirId, LangItem, Local, Node, PatKind};
6+
use rustc_hir::{Block, ExprKind, HirId, LangItem, LetStmt, Node, PatKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::declare_lint_pass;
99
use rustc_span::symbol::sym;
@@ -58,7 +58,7 @@ static COLLECTIONS: [Symbol; 9] = [
5858
];
5959

6060
impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead {
61-
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
61+
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx LetStmt<'tcx>) {
6262
// Look for local variables whose type is a container. Search surrounding bock for read access.
6363
if match_acceptable_type(cx, local, &COLLECTIONS)
6464
&& let PatKind::Binding(_, local_id, _, _) = local.pat.kind
@@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for CollectionIsNeverRead {
7070
}
7171
}
7272

73-
fn match_acceptable_type(cx: &LateContext<'_>, local: &Local<'_>, collections: &[rustc_span::Symbol]) -> bool {
73+
fn match_acceptable_type(cx: &LateContext<'_>, local: &LetStmt<'_>, collections: &[rustc_span::Symbol]) -> bool {
7474
let ty = cx.typeck_results().pat_ty(local.pat);
7575
collections.iter().any(|&sym| is_type_diagnostic_item(cx, ty, sym))
7676
// String type is a lang item but not a diagnostic item for now so we need a separate check

clippy_lints/src/ignored_unit_patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns {
4646
// Ignore function parameters
4747
return;
4848
},
49-
Node::Local(local) if local.ty.is_some() => {
49+
Node::LetStmt(local) if local.ty.is_some() => {
5050
// Ignore let bindings with explicit type
5151
return;
5252
},

clippy_lints/src/let_underscore.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::ty::{implements_trait, is_must_use_ty, match_type};
33
use clippy_utils::{is_from_proc_macro, is_must_use_func_call, paths};
4-
use rustc_hir::{Local, LocalSource, PatKind};
4+
use rustc_hir::{LetStmt, LocalSource, PatKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_middle::lint::in_external_macro;
77
use rustc_middle::ty::{GenericArgKind, IsSuggestable};
@@ -138,7 +138,7 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
138138
];
139139

140140
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
141-
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &Local<'tcx>) {
141+
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &LetStmt<'tcx>) {
142142
if matches!(local.source, LocalSource::Normal)
143143
&& !in_external_macro(cx.tcx.sess, local.span)
144144
&& let PatKind::Wild = local.pat.kind

clippy_lints/src/let_with_type_underscore.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::source::snippet;
3-
use rustc_hir::{Local, TyKind};
3+
use rustc_hir::{LetStmt, TyKind};
44
use rustc_lint::{LateContext, LateLintPass};
55
use rustc_middle::lint::in_external_macro;
66
use rustc_session::declare_lint_pass;
@@ -26,7 +26,7 @@ declare_clippy_lint! {
2626
declare_lint_pass!(UnderscoreTyped => [LET_WITH_TYPE_UNDERSCORE]);
2727

2828
impl LateLintPass<'_> for UnderscoreTyped {
29-
fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
29+
fn check_local(&mut self, cx: &LateContext<'_>, local: &LetStmt<'_>) {
3030
if !in_external_macro(cx.tcx.sess, local.span)
3131
&& let Some(ty) = local.ty // Ensure that it has a type defined
3232
&& let TyKind::Infer = &ty.kind // that type is '_'

clippy_lints/src/loops/same_item_push.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(super) fn check<'tcx>(
6262
if let Node::Pat(pat) = node
6363
&& let PatKind::Binding(bind_ann, ..) = pat.kind
6464
&& !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut))
65-
&& let Node::Local(parent_let_expr) = cx.tcx.parent_hir_node(hir_id)
65+
&& let Node::LetStmt(parent_let_expr) = cx.tcx.parent_hir_node(hir_id)
6666
&& let Some(init) = parent_let_expr.init
6767
{
6868
match init.kind {

clippy_lints/src/loops/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::{get_parent_expr, is_integer_const, path_to_local, path_to_loc
33
use rustc_ast::ast::{LitIntType, LitKind};
44
use rustc_errors::Applicability;
55
use rustc_hir::intravisit::{walk_expr, walk_local, Visitor};
6-
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, Local, Mutability, PatKind};
6+
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, HirId, HirIdMap, LetStmt, Mutability, PatKind};
77
use rustc_lint::LateContext;
88
use rustc_middle::hir::nested_filter;
99
use rustc_middle::ty::{self, Ty};
@@ -141,7 +141,7 @@ impl<'a, 'tcx> InitializeVisitor<'a, 'tcx> {
141141
impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
142142
type NestedFilter = nested_filter::OnlyBodies;
143143

144-
fn visit_local(&mut self, l: &'tcx Local<'_>) {
144+
fn visit_local(&mut self, l: &'tcx LetStmt<'_>) {
145145
// Look for declarations of the variable
146146
if l.pat.hir_id == self.var_id
147147
&& let PatKind::Binding(.., ident, _) = l.pat.kind

0 commit comments

Comments
 (0)