Skip to content

Commit afc6e69

Browse files
committed
Remove span from hir::Local.
1 parent 0373228 commit afc6e69

File tree

14 files changed

+35
-29
lines changed

14 files changed

+35
-29
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17761776
ty,
17771777
pat: self.lower_pat(&l.pat),
17781778
init,
1779-
span: l.span,
17801779
attrs: l.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into(),
17811780
source: hir::LocalSource::Normal,
17821781
},
@@ -2495,8 +2494,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24952494
pat: &'hir hir::Pat<'hir>,
24962495
source: hir::LocalSource,
24972496
) -> hir::Stmt<'hir> {
2498-
let local =
2499-
hir::Local { attrs, hir_id: self.next_id(span), init, pat, source, span, ty: None };
2497+
let local = hir::Local { attrs, hir_id: self.next_id(span), init, pat, source, ty: None };
25002498
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
25012499
}
25022500

compiler/rustc_hir/src/hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,6 @@ pub struct Local<'hir> {
11351135
/// Initializer expression to set the value, if any.
11361136
pub init: Option<&'hir Expr<'hir>>,
11371137
pub hir_id: HirId,
1138-
pub span: Span,
11391138
pub attrs: AttrVec,
11401139
/// Can be `ForLoopDesugar` if the `let` statement is part of a `for` loop
11411140
/// desugaring. Otherwise will be `Normal`.

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
@@ -514,7 +514,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
514514
/// Type check a `let` statement.
515515
pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) {
516516
// Determine and write the type which we'll check the pattern against.
517-
let ty = self.local_ty(local.span, local.hir_id).decl_ty;
517+
let local_span = self.tcx().hir().span(local.hir_id);
518+
let ty = self.local_ty(local_span, local.hir_id).decl_ty;
518519
self.write_ty(local.hir_id, ty);
519520

520521
// 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
@@ -205,12 +205,13 @@ impl LateLintPass<'_> for Default {
205205

206206
// span lint once per statement that binds default
207207
let first_assign_span = cx.tcx.hir().span(first_assign.unwrap().hir_id);
208+
let local_span = cx.tcx.hir().span(local.hir_id);
208209
span_lint_and_note(
209210
cx,
210211
FIELD_REASSIGN_WITH_DEFAULT,
211212
first_assign_span,
212213
"field assignment outside of initializer for an instance created with Default::default()",
213-
Some(local.span),
214+
Some(local_span),
214215
&format!(
215216
"consider initializing the variable with `{}` and removing relevant reassignments",
216217
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

@@ -138,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
138139
span_lint_and_help(
139140
cx,
140141
LET_UNDERSCORE_LOCK,
141-
local.span,
142+
local_span,
142143
"non-binding let on a synchronization lock",
143144
None,
144145
"consider using an underscore-prefixed named \
@@ -148,7 +149,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
148149
span_lint_and_help(
149150
cx,
150151
LET_UNDERSCORE_DROP,
151-
local.span,
152+
local_span,
152153
"non-binding `let` on a type that implements `Drop`",
153154
None,
154155
"consider using an underscore-prefixed named \
@@ -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 an expression with `#[must_use]` type",
163164
None,
164165
"consider explicitly using expression value"
@@ -167,7 +168,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
167168
span_lint_and_help(
168169
cx,
169170
LET_UNDERSCORE_MUST_USE,
170-
local.span,
171+
local_span,
171172
"non-binding let on a result of a `#[must_use]` function",
172173
None,
173174
"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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,10 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
607607
}
608608

609609
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'_>) {
610+
let local_span = cx.tcx.hir().span(local.hir_id);
610611
if_chain! {
611-
if !in_external_macro(cx.sess(), local.span);
612-
if !in_macro(local.span);
612+
if !in_external_macro(cx.sess(), local_span);
613+
if !in_macro(local_span);
613614
if let Some(ref expr) = local.init;
614615
if let ExprKind::Match(ref target, ref arms, MatchSource::Normal) = expr.kind;
615616
if arms.len() == 1 && arms[0].guard.is_none();
@@ -626,7 +627,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
626627
span_lint_and_sugg(
627628
cx,
628629
INFALLIBLE_DESTRUCTURING_MATCH,
629-
local.span,
630+
local_span,
630631
"you seem to be trying to use `match` to destructure a single infallible pattern. \
631632
Consider using `let`",
632633
"try this",
@@ -1245,7 +1246,7 @@ fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[A
12451246
// a macro. See PR #6435
12461247
if_chain! {
12471248
if let Some(match_snippet) = snippet_opt(cx, expr.span);
1248-
if let Some(arm_snippet) = snippet_opt(cx, arms[0].span);
1249+
if let Some(arm_snippet) = snippet_opt(cx, cx.tcx.hir().span(arms[0].hir_id));
12491250
if let Some(ex_snippet) = snippet_opt(cx, ex.span);
12501251
let rest_snippet = match_snippet.replace(&arm_snippet, "").replace(&ex_snippet, "");
12511252
if rest_snippet.contains("=>");
@@ -1288,7 +1289,7 @@ fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[A
12881289
// If this match is in a local (`let`) stmt
12891290
let (target_span, sugg) = if let Some(parent_let_node) = opt_parent_let(cx, ex) {
12901291
(
1291-
parent_let_node.span,
1292+
cx.tcx.hir().span(parent_let_node.hir_id),
12921293
format!(
12931294
"let {} = {};\n{}let {} = {};",
12941295
snippet_with_applicability(cx, bind_names, "..", &mut applicability),

0 commit comments

Comments
 (0)