Skip to content

Commit 3cf2fba

Browse files
committed
Remove span from hir::Local.
1 parent 1fcff64 commit 3cf2fba

File tree

15 files changed

+37
-29
lines changed

15 files changed

+37
-29
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18481848
ty,
18491849
pat: self.lower_pat(&l.pat),
18501850
init,
1851-
span: l.span,
18521851
source: hir::LocalSource::Normal,
18531852
},
18541853
ids,
@@ -2568,7 +2567,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25682567
debug_assert!(!a.is_empty());
25692568
self.attrs.insert(hir_id, a);
25702569
}
2571-
let local = hir::Local { hir_id, init, pat, source, span, ty: None };
2570+
let local = hir::Local { hir_id, init, pat, source, ty: None };
25722571
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
25732572
}
25742573

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,6 @@ pub struct Local<'hir> {
11661166
/// Initializer expression to set the value, if any.
11671167
pub init: Option<&'hir Expr<'hir>>,
11681168
pub hir_id: HirId,
1169-
pub span: Span,
11701169
/// Can be `ForLoopDesugar` if the `let` statement is part of a `for` loop
11711170
/// desugaring. Otherwise will be `Normal`.
11721171
pub source: LocalSource,

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'tcx> Visitor<'tcx> for MatchVisitor<'_, 'tcx> {
6565
intravisit::walk_local(self, loc);
6666

6767
let (msg, sp) = match loc.source {
68-
hir::LocalSource::Normal => ("local binding", Some(loc.span)),
68+
hir::LocalSource::Normal => ("local binding", Some(self.tcx.hir().span(loc.hir_id))),
6969
hir::LocalSource::ForLoopDesugar => ("`for` loop binding", None),
7070
hir::LocalSource::AsyncFn => ("async fn binding", None),
7171
hir::LocalSource::AwaitDesugar => ("`await` future binding", None),

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
518518
/// Type check a `let` statement.
519519
pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) {
520520
// Determine and write the type which we'll check the pattern against.
521-
let ty = self.local_ty(local.span, local.hir_id).decl_ty;
521+
let local_span = self.tcx().hir().span(local.hir_id);
522+
let ty = self.local_ty(local_span, local.hir_id).decl_ty;
522523
self.write_ty(local.hir_id, ty);
523524

524525
// Type check the initializer.

compiler/rustc_typeck/src/check/gather_locals.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
8080
}
8181
None => None,
8282
};
83-
self.assign(local.span, local.hir_id, local_ty);
83+
let local_span = self.fcx.tcx.hir().span(local.hir_id);
84+
self.assign(local_span, local.hir_id, local_ty);
8485

8586
debug!(
8687
"local variable {:?} is assigned type {}",

compiler/rustc_typeck/src/check/writeback.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,9 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
319319

320320
fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) {
321321
intravisit::walk_local(self, l);
322-
let var_ty = self.fcx.local_ty(l.span, l.hir_id).decl_ty;
323-
let var_ty = self.resolve(var_ty, &l.span);
322+
let span = self.tcx().hir().span(l.hir_id);
323+
let var_ty = self.fcx.local_ty(span, l.hir_id).decl_ty;
324+
let var_ty = self.resolve(var_ty, &span);
324325
self.write_ty_to_typeck_results(l.hir_id, var_ty);
325326
}
326327

src/tools/clippy/clippy_lints/src/default.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,13 @@ impl LateLintPass<'_> for Default {
210210

211211
// span lint once per statement that binds default
212212
let first_assign_span = cx.tcx.hir().span(first_assign.unwrap().hir_id);
213+
let local_span = cx.tcx.hir().span(local.hir_id);
213214
span_lint_and_note(
214215
cx,
215216
FIELD_REASSIGN_WITH_DEFAULT,
216217
first_assign_span,
217218
"field assignment outside of initializer for an instance created with Default::default()",
218-
Some(local.span),
219+
Some(local_span),
219220
&format!(
220221
"consider initializing the variable with `{}` and removing relevant reassignments",
221222
sugg

src/tools/clippy/clippy_lints/src/let_underscore.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ const SYNC_GUARD_PATHS: [&[&str]; 3] = [
109109

110110
impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
111111
fn check_local(&mut self, cx: &LateContext<'_>, local: &Local<'_>) {
112-
if in_external_macro(cx.tcx.sess, local.span) {
112+
let local_span = cx.tcx.hir().span(local.hir_id);
113+
if in_external_macro(cx.tcx.sess, local_span) {
113114
return;
114115
}
115116

@@ -129,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
129130
span_lint_and_help(
130131
cx,
131132
LET_UNDERSCORE_LOCK,
132-
local.span,
133+
local_span,
133134
"non-binding let on a synchronization lock",
134135
None,
135136
"consider using an underscore-prefixed named \
@@ -139,7 +140,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
139140
span_lint_and_help(
140141
cx,
141142
LET_UNDERSCORE_DROP,
142-
local.span,
143+
local_span,
143144
"non-binding `let` on a type that implements `Drop`",
144145
None,
145146
"consider using an underscore-prefixed named \
@@ -149,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
149150
span_lint_and_help(
150151
cx,
151152
LET_UNDERSCORE_MUST_USE,
152-
local.span,
153+
local_span,
153154
"non-binding let on an expression with `#[must_use]` type",
154155
None,
155156
"consider explicitly using expression value"
@@ -158,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
158159
span_lint_and_help(
159160
cx,
160161
LET_UNDERSCORE_MUST_USE,
161-
local.span,
162+
local_span,
162163
"non-binding let on a result of a `#[must_use]` function",
163164
None,
164165
"consider explicitly using function result"

src/tools/clippy/clippy_lints/src/map_unit_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) ->
141141
// If block only contains statements,
142142
// reduce `{ X; }` to `X` or `X;`
143143
match inner_stmt.kind {
144-
hir::StmtKind::Local(ref local) => Some(local.span),
144+
hir::StmtKind::Local(ref local) => Some(cx.tcx.hir().span(local.hir_id)),
145145
hir::StmtKind::Expr(ref e) => Some(e.span),
146146
hir::StmtKind::Semi(..) => Some(cx.tcx.hir().span(inner_stmt.hir_id)),
147147
hir::StmtKind::Item(..) => None,

src/tools/clippy/clippy_lints/src/matches.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,10 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
608608
}
609609

610610
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) {
611+
let local_span = cx.tcx.hir().span(local.hir_id);
611612
if_chain! {
612-
if !in_external_macro(cx.sess(), local.span);
613-
if !in_macro(local.span);
613+
if !in_external_macro(cx.sess(), local_span);
614+
if !in_macro(local_span);
614615
if let Some(ref expr) = local.init;
615616
if let ExprKind::Match(ref target, ref arms, MatchSource::Normal) = expr.kind;
616617
if arms.len() == 1 && arms[0].guard.is_none();
@@ -627,7 +628,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
627628
span_lint_and_sugg(
628629
cx,
629630
INFALLIBLE_DESTRUCTURING_MATCH,
630-
local.span,
631+
local_span,
631632
"you seem to be trying to use `match` to destructure a single infallible pattern. \
632633
Consider using `let`",
633634
"try this",
@@ -1340,7 +1341,7 @@ fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[A
13401341
// If this match is in a local (`let`) stmt
13411342
let (target_span, sugg) = if let Some(parent_let_node) = opt_parent_let(cx, ex) {
13421343
(
1343-
parent_let_node.span,
1344+
cx.tcx.hir().span(parent_let_node.hir_id),
13441345
format!(
13451346
"let {} = {};\n{}let {} = {};",
13461347
snippet_with_applicability(cx, bind_names, "..", &mut applicability),

0 commit comments

Comments
 (0)