Skip to content

Commit 8197821

Browse files
committed
Remove span from hir::Block.
1 parent 76f16ed commit 8197821

File tree

14 files changed

+38
-33
lines changed

14 files changed

+38
-33
lines changed

src/librustc_ast_lowering/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
17701770
expr: Some(expr),
17711771
hir_id,
17721772
rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated),
1773-
span,
17741773
targeted_by_break: false,
17751774
}),
17761775
None,
@@ -1790,7 +1789,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
17901789
b: &'hir hir::Block<'hir>,
17911790
attrs: AttrVec,
17921791
) -> hir::Expr<'hir> {
1793-
self.expr(b.span, hir::ExprKind::Block(b, None), attrs)
1792+
let span = self.spans[b.hir_id];
1793+
self.expr(span, hir::ExprKind::Block(b, None), attrs)
17941794
}
17951795

17961796
pub(super) fn expr(

src/librustc_ast_lowering/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,7 +2350,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23502350
stmts: self.arena.alloc_from_iter(stmts),
23512351
expr,
23522352
rules: self.lower_block_check_mode(&b.rules),
2353-
span: b.span,
23542353
targeted_by_break,
23552354
}
23562355
}
@@ -2480,7 +2479,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24802479
expr,
24812480
hir_id: self.next_id(span),
24822481
rules: hir::BlockCheckMode::DefaultBlock,
2483-
span,
24842482
targeted_by_break: false,
24852483
};
24862484
self.arena.alloc(blk)

src/librustc_hir/hir.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,6 @@ pub struct Block<'hir> {
743743
pub hir_id: HirId,
744744
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
745745
pub rules: BlockCheckMode,
746-
pub span: Span,
747746
/// If true, then there may exist `break 'a` values that aim to
748747
/// break out of this block early.
749748
/// Used by `'label: {}` blocks and by `try {}` blocks.

src/librustc_hir_pretty/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,8 @@ impl<'a> State<'a> {
10871087
hir::BlockCheckMode::PopUnsafeBlock(..) => self.word_space("pop_unsafe"),
10881088
hir::BlockCheckMode::DefaultBlock => (),
10891089
}
1090-
self.maybe_print_comment(blk.span.lo());
1090+
let span = self.span(blk.hir_id);
1091+
self.maybe_print_comment(span.lo());
10911092
self.ann.pre(self, AnnNode::Block(blk));
10921093
self.bopen();
10931094

@@ -1099,9 +1100,9 @@ impl<'a> State<'a> {
10991100
if let Some(ref expr) = blk.expr {
11001101
self.space_if_not_bol();
11011102
self.print_expr(&expr);
1102-
self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi()));
1103+
self.maybe_print_trailing_comment(expr.span, Some(span.hi()));
11031104
}
1104-
self.bclose_maybe_open(blk.span, close_box);
1105+
self.bclose_maybe_open(span, close_box);
11051106
self.ann.post(self, AnnNode::Block(blk))
11061107
}
11071108

src/librustc_middle/hir/map/collector.rs

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

488488
fn visit_block(&mut self, block: &'hir Block<'hir>) {
489-
self.insert(block.span, block.hir_id, Node::Block(block));
489+
self.insert(DUMMY_SP, block.hir_id, Node::Block(block));
490490
self.with_parent(block.hir_id, |this| {
491491
intravisit::walk_block(this, block);
492492
});

src/librustc_mir_build/hair/cx/block.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block<'tcx> {
1717
let stmts = mirror_stmts(cx, self.hir_id.local_id, &*self.stmts);
1818
let opt_destruction_scope =
1919
cx.region_scope_tree.opt_destruction_scope(self.hir_id.local_id);
20+
let span = cx.tcx.hir().span(self.hir_id);
2021
Block {
2122
targeted_by_break: self.targeted_by_break,
2223
region_scope: region::Scope { id: self.hir_id.local_id, data: region::ScopeData::Node },
2324
opt_destruction_scope,
24-
span: self.span,
25+
span,
2526
stmts,
2627
expr: self.expr.to_ref(),
2728
safety_mode: match self.rules {
@@ -106,12 +107,8 @@ crate fn to_expr_ref<'a, 'tcx>(
106107
block: &'tcx hir::Block<'tcx>,
107108
) -> ExprRef<'tcx> {
108109
let block_ty = cx.tables().node_type(block.hir_id);
110+
let span = cx.tcx.hir().span(block.hir_id);
109111
let temp_lifetime = cx.region_scope_tree.temporary_scope(block.hir_id.local_id);
110-
let expr = Expr {
111-
ty: block_ty,
112-
temp_lifetime,
113-
span: block.span,
114-
kind: ExprKind::Block { body: block },
115-
};
112+
let expr = Expr { ty: block_ty, temp_lifetime, span, kind: ExprKind::Block { body: block } };
116113
expr.to_ref()
117114
}

src/librustc_passes/loops.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,15 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
144144
match destination.target_id {
145145
Ok(loop_id) => {
146146
if let Node::Block(block) = self.hir_map.find(loop_id).unwrap() {
147+
let block_span = self.hir_map.span(block.hir_id);
147148
struct_span_err!(
148149
self.sess,
149150
e.span,
150151
E0696,
151152
"`continue` pointing to a labeled block"
152153
)
153154
.span_label(e.span, "labeled blocks cannot be `continue`'d")
154-
.span_label(block.span, "labeled block the `continue` points to")
155+
.span_label(block_span, "labeled block the `continue` points to")
155156
.emit();
156157
}
157158
}

src/librustc_typeck/check/expr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
795795
let coerce = match source {
796796
// you can only use break with a value from a normal `loop { }`
797797
hir::LoopSource::Loop => {
798-
let coerce_to = expected.coercion_target_type(self, body.span);
798+
let span = self.tcx.hir().span(body.hir_id);
799+
let coerce_to = expected.coercion_target_type(self, span);
799800
Some(CoerceMany::new(coerce_to))
800801
}
801802

@@ -823,8 +824,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
823824
// (which would have type !) are only possible iff we
824825
// permit break with a value [1].
825826
if ctxt.coerce.is_none() && !ctxt.may_break {
827+
let span = self.tcx.hir().span(body.hir_id);
826828
// [1]
827-
self.tcx.sess.delay_span_bug(body.span, "no coercion, but loop may not break");
829+
self.tcx.sess.delay_span_bug(span, "no coercion, but loop may not break");
828830
}
829831
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.mk_unit())
830832
}

src/librustc_typeck/check/mod.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4654,7 +4654,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
46544654
// if the block produces a `!` value, that can always be
46554655
// (effectively) coerced to unit.
46564656
if !ty.is_never() {
4657-
self.demand_suptype(blk.span, unit, ty);
4657+
let span = self.tcx.hir().span(blk.hir_id);
4658+
self.demand_suptype(span, unit, ty);
46584659
}
46594660
}
46604661

@@ -4679,7 +4680,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
46794680
Some(match &arm.body.kind {
46804681
// Point at the tail expression when possible.
46814682
hir::ExprKind::Block(block, _) => {
4682-
block.expr.as_ref().map(|e| e.span).unwrap_or(block.span)
4683+
let span = self.tcx.hir().span(block.hir_id);
4684+
block.expr.as_ref().map(|e| e.span).unwrap_or(span)
46834685
}
46844686
_ => arm.body.span,
46854687
})
@@ -4722,7 +4724,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
47224724
// break 'a 22; }` would not force the type of the block
47234725
// to be `()`).
47244726
let tail_expr = blk.expr.as_ref();
4725-
let coerce_to_ty = expected.coercion_target_type(self, blk.span);
4727+
let span = self.tcx.hir().span(blk.hir_id);
4728+
let coerce_to_ty = expected.coercion_target_type(self, span);
47264729
let coerce = if blk.targeted_by_break {
47274730
CoerceMany::new(coerce_to_ty)
47284731
} else {
@@ -4770,15 +4773,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
47704773
// `consider_hint_about_removing_semicolon` will point at the last expression
47714774
// if it were a relevant part of the error. This improves usability in editors
47724775
// that highlight errors inline.
4773-
let mut sp = blk.span;
4776+
let mut sp = span;
47744777
let mut fn_span = None;
47754778
if let Some((decl, ident)) = self.get_parent_fn_decl(blk.hir_id) {
47764779
let ret_sp = decl.output.span();
47774780
if let Some(block_sp) = self.parent_item_span(blk.hir_id) {
47784781
// HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the
47794782
// output would otherwise be incorrect and even misleading. Make sure
47804783
// the span we're aiming at correspond to a `fn` body.
4781-
if block_sp == blk.span {
4784+
if block_sp == span {
47824785
sp = ret_sp;
47834786
fn_span = Some(ident.span);
47844787
}
@@ -4830,7 +4833,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
48304833
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(_, body_id), .. }) => {
48314834
let body = self.tcx.hir().body(body_id);
48324835
if let ExprKind::Block(block, _) = &body.value.kind {
4833-
return Some(block.span);
4836+
let span = self.tcx.hir().span(block.hir_id);
4837+
return Some(span);
48344838
}
48354839
}
48364840
_ => {}
@@ -5408,7 +5412,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
54085412
return None;
54095413
}
54105414
let last_stmt_span = self.tcx.hir().span(last_stmt.hir_id);
5411-
let original_span = original_sp(last_stmt_span, blk.span);
5415+
let blk_span = self.tcx.hir().span(blk.hir_id);
5416+
let original_span = original_sp(last_stmt_span, blk_span);
54125417
Some(original_span.with_lo(original_span.hi() - BytePos(1)))
54135418
}
54145419

src/librustc_typeck/check/writeback.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
281281
}
282282

283283
fn visit_block(&mut self, b: &'tcx hir::Block<'tcx>) {
284-
self.visit_node_id(b.span, b.hir_id);
284+
let span = self.tcx().hir().span(b.hir_id);
285+
self.visit_node_id(span, b.hir_id);
285286
intravisit::walk_block(self, b);
286287
}
287288

src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlocksInIfConditions {
123123
"let res = {}; if res",
124124
snippet_block_with_applicability(
125125
cx,
126-
block.span,
126+
cx.tcx.hir().span(block.hir_id),
127127
"..",
128128
Some(expr.span),
129129
&mut applicability

src/tools/clippy/clippy_lints/src/copies.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) {
181181
span_lint_and_note(
182182
cx,
183183
IF_SAME_THEN_ELSE,
184-
j.span,
184+
cx.tcx.hir().span(j.hir_id),
185185
"this `if` has identical blocks",
186-
Some(i.span),
186+
Some(cx.tcx.hir().span(i.hir_id)),
187187
"same as this",
188188
);
189189
}

src/tools/clippy/clippy_lints/src/manual_async_fn.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ManualAsyncFn {
8080
Applicability::MachineApplicable
8181
);
8282

83-
let body_snip = snippet_block(cx, closure_body.value.span, "..", Some(block.span));
83+
let block_span = cx.tcx.hir().span(block.hir_id);
84+
let body_snip = snippet_block(cx, closure_body.value.span, "..", Some(block_span));
8485
diag.span_suggestion(
85-
block.span,
86+
block_span,
8687
"move the body of the async block to the enclosing function",
8788
body_snip.to_string(),
8889
Applicability::MachineApplicable

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ fn check_match_single_binding<'a>(cx: &LateContext<'_, 'a>, ex: &Expr<'a>, arms:
10071007
match match_body.kind {
10081008
ExprKind::Block(block, _) => {
10091009
// macro + expr_ty(body) == ()
1010-
if block.span.from_expansion() && cx.tables.expr_ty(&match_body).is_unit() {
1010+
if cx.tcx.hir().span(block.hir_id).from_expansion() && cx.tables.expr_ty(&match_body).is_unit() {
10111011
snippet_body.push(';');
10121012
}
10131013
},

0 commit comments

Comments
 (0)