Skip to content

Commit 1f05c3d

Browse files
committed
Remove span from hir::Local.
1 parent f94dac7 commit 1f05c3d

File tree

12 files changed

+29
-26
lines changed

12 files changed

+29
-26
lines changed

src/librustc_ast_lowering/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17331733
ty,
17341734
pat: self.lower_pat(&l.pat),
17351735
init,
1736-
span: l.span,
17371736
attrs: l.attrs.clone(),
17381737
source: hir::LocalSource::Normal,
17391738
},
@@ -2455,8 +2454,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24552454
pat: &'hir hir::Pat<'hir>,
24562455
source: hir::LocalSource,
24572456
) -> hir::Stmt<'hir> {
2458-
let local =
2459-
hir::Local { attrs, hir_id: self.next_id(span), init, pat, source, span, ty: None };
2457+
let local = hir::Local { attrs, hir_id: self.next_id(span), init, pat, source, ty: None };
24602458
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
24612459
}
24622460

src/librustc_hir/hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,6 @@ pub struct Local<'hir> {
11281128
/// Initializer expression to set the value, if any.
11291129
pub init: Option<&'hir Expr<'hir>>,
11301130
pub hir_id: HirId,
1131-
pub span: Span,
11321131
pub attrs: AttrVec,
11331132
/// Can be `ForLoopDesugar` if the `let` statement is part of a `for` loop
11341133
/// desugaring. Otherwise will be `Normal`.

src/librustc_middle/hir/map/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
493493
}
494494

495495
fn visit_local(&mut self, l: &'hir Local<'hir>) {
496-
self.insert(l.span, l.hir_id, Node::Local(l));
496+
self.insert(DUMMY_SP, l.hir_id, Node::Local(l));
497497
self.with_parent(l.hir_id, |this| intravisit::walk_local(this, l))
498498
}
499499

src/librustc_mir_build/hair/pattern/check_match.rs

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

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

src/librustc_typeck/check/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,8 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
12071207
}
12081208
None => None,
12091209
};
1210-
self.assign(local.span, local.hir_id, local_ty);
1210+
let local_span = self.fcx.tcx.hir().span(local.hir_id);
1211+
self.assign(local_span, local.hir_id, local_ty);
12111212

12121213
debug!(
12131214
"local variable {:?} is assigned type {}",
@@ -4564,7 +4565,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
45644565
/// Type check a `let` statement.
45654566
pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) {
45664567
// Determine and write the type which we'll check the pattern against.
4567-
let ty = self.local_ty(local.span, local.hir_id).decl_ty;
4568+
let local_span = self.tcx.hir().span(local.hir_id);
4569+
let ty = self.local_ty(local_span, local.hir_id).decl_ty;
45684570
self.write_ty(local.hir_id, ty);
45694571

45704572
// Type check the initializer.

src/librustc_typeck/check/writeback.rs

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

311311
fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) {
312312
intravisit::walk_local(self, l);
313-
let var_ty = self.fcx.local_ty(l.span, l.hir_id).decl_ty;
314-
let var_ty = self.resolve(&var_ty, &l.span);
313+
let span = self.tcx().hir().span(l.hir_id);
314+
let var_ty = self.fcx.local_ty(span, l.hir_id).decl_ty;
315+
let var_ty = self.resolve(&var_ty, &span);
315316
self.write_ty_to_tables(l.hir_id, var_ty);
316317
}
317318

src/tools/clippy/clippy_lints/src/let_and_return.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,23 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetReturn {
5656
if !last_statement_borrows(cx, initexpr);
5757
if !in_external_macro(cx.sess(), initexpr.span);
5858
if !in_external_macro(cx.sess(), retexpr.span);
59-
if !in_external_macro(cx.sess(), local.span);
60-
if !in_macro(local.span);
59+
let local_span = cx.tcx.hir().span(local.hir_id);
60+
if !in_external_macro(cx.sess(), local_span);
61+
if !in_macro(local_span);
6162
then {
6263
span_lint_and_then(
6364
cx,
6465
LET_AND_RETURN,
6566
retexpr.span,
6667
"returning the result of a `let` binding from a block",
6768
|err| {
68-
err.span_label(local.span, "unnecessary `let` binding");
69+
err.span_label(local_span, "unnecessary `let` binding");
6970

7071
if let Some(snippet) = snippet_opt(cx, initexpr.span) {
7172
err.multipart_suggestion(
7273
"return the expression directly",
7374
vec![
74-
(local.span, String::new()),
75+
(local_span, String::new()),
7576
(retexpr.span, snippet),
7677
],
7778
Applicability::MachineApplicable,

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

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

6969
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
7070
fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &Local<'_>) {
71-
if in_external_macro(cx.tcx.sess, local.span) {
71+
let local_span = cx.tcx.hir().span(local.hir_id);
72+
if in_external_macro(cx.tcx.sess, local_span) {
7273
return;
7374
}
7475

@@ -88,7 +89,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
8889
span_lint_and_help(
8990
cx,
9091
LET_UNDERSCORE_LOCK,
91-
local.span,
92+
local_span,
9293
"non-binding let on a synchronization lock",
9394
None,
9495
"consider using an underscore-prefixed named \
@@ -98,7 +99,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
9899
span_lint_and_help(
99100
cx,
100101
LET_UNDERSCORE_MUST_USE,
101-
local.span,
102+
local_span,
102103
"non-binding let on an expression with `#[must_use]` type",
103104
None,
104105
"consider explicitly using expression value"
@@ -107,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
107108
span_lint_and_help(
108109
cx,
109110
LET_UNDERSCORE_MUST_USE,
110-
local.span,
111+
local_span,
111112
"non-binding let on a result of a `#[must_use]` function",
112113
None,
113114
"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
@@ -140,7 +140,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr<'_>)
140140
// If block only contains statements,
141141
// reduce `{ X; }` to `X` or `X;`
142142
match inner_stmt.kind {
143-
hir::StmtKind::Local(ref local) => Some(local.span),
143+
hir::StmtKind::Local(ref local) => Some(cx.tcx.hir().span(local.hir_id)),
144144
hir::StmtKind::Expr(ref e) => Some(e.span),
145145
hir::StmtKind::Semi(..) => Some(cx.tcx.hir().span(inner_stmt.hir_id)),
146146
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
@@ -456,9 +456,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
456456
}
457457

458458
fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>) {
459+
let local_span = cx.tcx.hir().span(local.hir_id);
459460
if_chain! {
460-
if !in_external_macro(cx.sess(), local.span);
461-
if !in_macro(local.span);
461+
if !in_external_macro(cx.sess(), local_span);
462+
if !in_macro(local_span);
462463
if let Some(ref expr) = local.init;
463464
if let ExprKind::Match(ref target, ref arms, MatchSource::Normal) = expr.kind;
464465
if arms.len() == 1 && arms[0].guard.is_none();
@@ -475,7 +476,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
475476
span_lint_and_sugg(
476477
cx,
477478
INFALLIBLE_DESTRUCTURING_MATCH,
478-
local.span,
479+
local_span,
479480
"you seem to be trying to use `match` to destructure a single infallible pattern. \
480481
Consider using `let`",
481482
"try this",
@@ -1025,7 +1026,7 @@ fn check_match_single_binding<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>, arms:
10251026
// If this match is in a local (`let`) stmt
10261027
let (target_span, sugg) = if let Some(parent_let_node) = opt_parent_let(cx, ex) {
10271028
(
1028-
parent_let_node.span,
1029+
cx.tcx.hir().span(parent_let_node.hir_id),
10291030
format!(
10301031
"let {} = {};\n{}let {} = {};",
10311032
snippet_with_applicability(cx, bind_names, "..", &mut applicability),

src/tools/clippy/clippy_lints/src/mut_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableKeyType {
7676
if let hir::PatKind::Wild = local.pat.kind {
7777
return;
7878
}
79-
check_ty(cx, local.span, cx.tables.pat_ty(&*local.pat));
79+
check_ty(cx, cx.tcx.hir().span(local.hir_id), cx.tables.pat_ty(&*local.pat));
8080
}
8181
}
8282

src/tools/clippy/clippy_lints/src/shadow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>, bin
138138
}
139139

140140
fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>, bindings: &mut Vec<(Name, Span)>) {
141-
if in_external_macro(cx.sess(), local.span) {
141+
let span = cx.tcx.hir().span(local.hir_id);
142+
if in_external_macro(cx.sess(), span) {
142143
return;
143144
}
144145
if higher::is_from_for_desugar(local) {
@@ -148,7 +149,6 @@ fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>, bin
148149
ref pat,
149150
ref ty,
150151
ref init,
151-
span,
152152
..
153153
} = *local;
154154
if let Some(ref t) = *ty {

0 commit comments

Comments
 (0)