Skip to content

Commit 76f16ed

Browse files
committed
Remove span from hir::Stmt.
1 parent 0bf0ea2 commit 76f16ed

File tree

18 files changed

+50
-40
lines changed

18 files changed

+50
-40
lines changed

src/librustc_ast_lowering/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,7 +2385,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23852385
hir::Stmt {
23862386
hir_id: self.lower_node_id(s.id, s.span),
23872387
kind: hir::StmtKind::Local(self.arena.alloc(l)),
2388-
span: s.span,
23892388
}
23902389
});
23912390
return ids;
@@ -2402,7 +2401,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24022401
.map(|id| self.lower_node_id(id, s.span))
24032402
.unwrap_or_else(|| self.next_id(s.span));
24042403

2405-
hir::Stmt { hir_id, kind: hir::StmtKind::Item(item_id), span: s.span }
2404+
hir::Stmt { hir_id, kind: hir::StmtKind::Item(item_id) }
24062405
})
24072406
.collect();
24082407
}
@@ -2411,7 +2410,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24112410
StmtKind::Empty => return smallvec![],
24122411
StmtKind::MacCall(..) => panic!("shouldn't exist here"),
24132412
};
2414-
smallvec![hir::Stmt { hir_id: self.lower_node_id(s.id, s.span), kind, span: s.span }]
2413+
smallvec![hir::Stmt { hir_id: self.lower_node_id(s.id, s.span), kind }]
24152414
}
24162415

24172416
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {
@@ -2446,7 +2445,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24462445
// Helper methods for building HIR.
24472446

24482447
fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
2449-
hir::Stmt { span, kind, hir_id: self.next_id(span) }
2448+
hir::Stmt { kind, hir_id: self.next_id(span) }
24502449
}
24512450

24522451
fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {

src/librustc_hir/hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,6 @@ impl UnOp {
11031103
pub struct Stmt<'hir> {
11041104
pub hir_id: HirId,
11051105
pub kind: StmtKind<'hir>,
1106-
pub span: Span,
11071106
}
11081107

11091108
/// The contents of a statement.

src/librustc_hir_pretty/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,8 @@ impl<'a> State<'a> {
10401040
}
10411041

10421042
pub fn print_stmt(&mut self, st: &hir::Stmt<'_>) {
1043-
self.maybe_print_comment(st.span.lo());
1043+
let span = self.span(st.hir_id);
1044+
self.maybe_print_comment(span.lo());
10441045
match st.kind {
10451046
hir::StmtKind::Local(ref loc) => {
10461047
self.print_local(loc.init.as_deref(), |this| this.print_local_decl(&loc));
@@ -1059,7 +1060,7 @@ impl<'a> State<'a> {
10591060
if stmt_ends_with_semi(&st.kind) {
10601061
self.s.word(";");
10611062
}
1062-
self.maybe_print_trailing_comment(st.span, None)
1063+
self.maybe_print_trailing_comment(span, None)
10631064
}
10641065

10651066
pub fn print_block(&mut self, blk: &hir::Block<'_>) {

src/librustc_lint/unused.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
4747
}
4848

4949
let ty = cx.tables.expr_ty(&expr);
50-
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span, "", "", 1);
50+
let span = cx.tcx.hir().span(s.hir_id);
51+
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, span, "", "", 1);
5152

5253
let mut fn_warned = false;
5354
let mut op_warned = false;
@@ -69,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
6970
_ => None,
7071
};
7172
if let Some(def_id) = maybe_def_id {
72-
fn_warned = check_must_use_def(cx, def_id, s.span, "return value of ", "");
73+
fn_warned = check_must_use_def(cx, def_id, span, "return value of ", "");
7374
} else if type_permits_lack_of_use {
7475
// We don't warn about unused unit or uninhabited types.
7576
// (See https://github.com/rust-lang/rust/issues/43806 for details.)
@@ -111,7 +112,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
111112
}
112113

113114
if !(type_permits_lack_of_use || fn_warned || op_warned) {
114-
cx.struct_span_lint(UNUSED_RESULTS, s.span, |lint| lint.build("unused result").emit());
115+
cx.struct_span_lint(UNUSED_RESULTS, span, |lint| lint.build("unused result").emit());
115116
}
116117

117118
// Returns whether an error has been emitted (and thus another does not need to be later).
@@ -255,7 +256,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathStatements {
255256
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt<'_>) {
256257
if let hir::StmtKind::Semi(ref expr) = s.kind {
257258
if let hir::ExprKind::Path(_) = expr.kind {
258-
cx.struct_span_lint(PATH_STATEMENTS, s.span, |lint| {
259+
let span = cx.tcx.hir().span(s.hir_id);
260+
cx.struct_span_lint(PATH_STATEMENTS, span, |lint| {
259261
lint.build("path statement with no effect").emit()
260262
});
261263
}

src/librustc_middle/hir/map/collector.rs

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

446446
fn visit_stmt(&mut self, stmt: &'hir Stmt<'hir>) {
447-
self.insert(stmt.span, stmt.hir_id, Node::Stmt(stmt));
447+
self.insert(DUMMY_SP, stmt.hir_id, Node::Stmt(stmt));
448448

449449
self.with_parent(stmt.hir_id, |this| {
450450
intravisit::walk_stmt(this, stmt);

src/librustc_middle/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl Scope {
184184
// (This is the special case alluded to in the
185185
// doc-comment for this method)
186186

187-
let stmt_span = blk.stmts[first_statement_index.index()].span;
187+
let stmt_span = tcx.hir().span(blk.stmts[first_statement_index.index()].hir_id);
188188

189189
// To avoid issues with macro-generated spans, the span
190190
// of the statement must be nested in that of the block.

src/librustc_passes/check_attr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,14 @@ impl CheckAttrVisitor<'tcx> {
357357
if let hir::StmtKind::Local(ref l) = stmt.kind {
358358
for attr in l.attrs.iter() {
359359
if attr.check_name(sym::inline) {
360-
self.check_inline(l.hir_id, attr, &stmt.span, Target::Statement);
360+
let span = self.tcx.hir().span(stmt.hir_id);
361+
self.check_inline(l.hir_id, attr, &span, Target::Statement);
361362
}
362363
if attr.check_name(sym::repr) {
364+
let span = self.tcx.hir().span(stmt.hir_id);
363365
self.emit_repr_error(
364366
attr.span,
365-
stmt.span,
367+
span,
366368
"attribute should not be applied to a statement",
367369
"not a struct, enum, or union",
368370
);

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
922922
// no return, suggest removal of semicolon on last statement.
923923
// Once that is added, close #54771.
924924
if let Some(ref stmt) = blk.stmts.last() {
925-
let sp = self.tcx.sess.source_map().end_point(stmt.span);
925+
let span = self.tcx.hir().span(stmt.hir_id);
926+
let sp = self.tcx.sess.source_map().end_point(span);
926927
err.span_label(sp, "consider removing this semicolon");
927928
}
928929
}

src/librustc_typeck/check/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
300300
} else if let Some(stmt) = block.stmts.last() {
301301
// possibly incorrect trailing `;` in the else arm
302302
remove_semicolon = self.could_remove_semicolon(block, then_ty);
303-
stmt.span
303+
self.tcx.hir().span(stmt.hir_id)
304304
} else {
305305
// empty block; point at its entirety
306306
// Avoid overlapping spans that aren't as readable:
@@ -347,7 +347,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
347347
} else if let Some(stmt) = block.stmts.last() {
348348
// possibly incorrect trailing `;` in the else arm
349349
remove_semicolon = remove_semicolon.or(self.could_remove_semicolon(block, else_ty));
350-
stmt.span
350+
self.tcx.hir().span(stmt.hir_id)
351351
} else {
352352
// empty block; point at its entirety
353353
outer_sp = None; // same as in `error_sp`; cleanup output

src/librustc_typeck/check/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4618,7 +4618,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
46184618
hir::StmtKind::Local(..) | hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => {}
46194619
}
46204620

4621-
self.warn_if_unreachable(stmt.hir_id, stmt.span, "statement");
4621+
let span = self.tcx.hir().span(stmt.hir_id);
4622+
self.warn_if_unreachable(stmt.hir_id, span, "statement");
46224623

46234624
// Hide the outer diverging and `has_errors` flags.
46244625
let old_diverges = self.diverges.replace(Diverges::Maybe);
@@ -5406,7 +5407,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
54065407
{
54075408
return None;
54085409
}
5409-
let original_span = original_sp(last_stmt.span, blk.span);
5410+
let last_stmt_span = self.tcx.hir().span(last_stmt.hir_id);
5411+
let original_span = original_sp(last_stmt_span, blk.span);
54105412
Some(original_span.with_lo(original_span.hi() - BytePos(1)))
54115413
}
54125414

0 commit comments

Comments
 (0)