Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
625594f
Remove useless Clone bound in IndexVec.
cjgillot May 19, 2020
6758a85
Introduce HirIdVec.
cjgillot May 19, 2020
0b793a3
Collect spans during lowering.
cjgillot May 1, 2020
e69a8df
Introduce a query for HIR spans.
cjgillot May 1, 2020
0d98c91
Don't pass spans in hir::map::blocks.
cjgillot May 2, 2020
3947c9e
Stop passing the Span in HIR visiting.
cjgillot May 2, 2020
973d19b
Pass HirId in save_analysis.
cjgillot Jun 7, 2020
700d697
Remove Span parameter from HIR collector.
cjgillot Jun 3, 2020
05dc82a
Fix fulldeps tests.
cjgillot Dec 13, 2020
7b9999c
Fix clippy.
cjgillot Dec 13, 2020
3dd2859
Remove span from hir::Param.
cjgillot May 1, 2020
5dada24
Remove span from hir::Variant.
cjgillot May 1, 2020
e92e9f7
Remove span from hir::StructField.
cjgillot May 1, 2020
f94bbef
Remove span from hir::Stmt.
cjgillot May 1, 2020
2bc251c
Remove span from hir::Block.
cjgillot May 1, 2020
fcae632
Remove span from hir::MacroDef.
cjgillot May 2, 2020
1641026
Remove span from hir::GenericParam.
cjgillot May 2, 2020
521bc45
Remove span from hir::Arm.
cjgillot May 2, 2020
0373228
Remove span from hir::FieldPat.
cjgillot May 2, 2020
afc6e69
Remove span from hir::Local.
cjgillot May 2, 2020
732ae69
Remove span from hir::Pat.
cjgillot May 2, 2020
96b8564
Remove span from hir::Field.
cjgillot May 2, 2020
e6c0698
Remove GenericArg::span.
cjgillot May 3, 2020
4491f82
Remove Span from hir::TypeBinding.
cjgillot May 8, 2020
fdd2c7d
Remove Span from hir::ConstArg.
cjgillot Jun 1, 2020
ba8fc92
Remove Span from hir::TraitItemRef.
cjgillot Jun 1, 2020
272df28
Remove Span from hir::ImplItemRef.
cjgillot Jun 1, 2020
a0b4ad1
Remove span from hir::ForeignItemRef.
cjgillot Dec 11, 2020
b604b5e
Fix fulldeps tests.
cjgillot May 9, 2020
7ec01a6
Fortify find_entry.
cjgillot Dec 13, 2020
304bdec
Remove Span from hir::CrateItem.
cjgillot Dec 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove span from hir::Block.
  • Loading branch information
cjgillot committed Jan 6, 2021
commit 2bc251cd4c6fefeaf73901107fbd359695e84078
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2017,7 +2017,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
expr: Some(expr),
hir_id,
rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated),
span,
targeted_by_break: false,
}),
None,
Expand All @@ -2037,7 +2036,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
b: &'hir hir::Block<'hir>,
attrs: AttrVec,
) -> hir::Expr<'hir> {
self.expr(b.span, hir::ExprKind::Block(b, None), attrs)
let span = self.spans[b.hir_id];
self.expr(span, hir::ExprKind::Block(b, None), attrs)
}

pub(super) fn expr(
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let rules = self.lower_block_check_mode(&b.rules);
let hir_id = self.lower_node_id(b.id, b.span);

hir::Block { hir_id, stmts, expr, rules, span: b.span, targeted_by_break }
hir::Block { hir_id, stmts, expr, rules, targeted_by_break }
}

/// Lowers a block directly to an expression, presuming that it
Expand Down Expand Up @@ -2519,7 +2519,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
expr,
hir_id: self.next_id(span),
rules: hir::BlockCheckMode::DefaultBlock,
span,
targeted_by_break: false,
};
self.arena.alloc(blk)
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,6 @@ pub struct Block<'hir> {
pub hir_id: HirId,
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
pub rules: BlockCheckMode,
pub span: Span,
/// If true, then there may exist `break 'a` values that aim to
/// break out of this block early.
/// Used by `'label: {}` blocks and by `try {}` blocks.
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,8 @@ impl<'a> State<'a> {
hir::BlockCheckMode::PopUnsafeBlock(..) => self.word_space("pop_unsafe"),
hir::BlockCheckMode::DefaultBlock => (),
}
self.maybe_print_comment(blk.span.lo());
let span = self.span(blk.hir_id);
self.maybe_print_comment(span.lo());
self.ann.pre(self, AnnNode::Block(blk));
self.bopen();

Expand All @@ -1093,9 +1094,9 @@ impl<'a> State<'a> {
if let Some(ref expr) = blk.expr {
self.space_if_not_bol();
self.print_expr(&expr);
self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi()));
self.maybe_print_trailing_comment(expr.span, Some(span.hi()));
}
self.bclose_maybe_open(blk.span, close_box);
self.bclose_maybe_open(span, close_box);
self.ann.post(self, AnnNode::Block(blk))
}

Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_mir_build/src/thir/cx/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block<'tcx> {
let stmts = mirror_stmts(cx, self.hir_id.local_id, &*self.stmts);
let opt_destruction_scope =
cx.region_scope_tree.opt_destruction_scope(self.hir_id.local_id);
let span = cx.tcx.hir().span(self.hir_id);
Block {
targeted_by_break: self.targeted_by_break,
region_scope: region::Scope { id: self.hir_id.local_id, data: region::ScopeData::Node },
opt_destruction_scope,
span: self.span,
span,
stmts,
expr: self.expr.to_ref(),
safety_mode: match self.rules {
Expand Down Expand Up @@ -106,12 +107,8 @@ crate fn to_expr_ref<'a, 'tcx>(
block: &'tcx hir::Block<'tcx>,
) -> ExprRef<'tcx> {
let block_ty = cx.typeck_results().node_type(block.hir_id);
let span = cx.tcx.hir().span(block.hir_id);
let temp_lifetime = cx.region_scope_tree.temporary_scope(block.hir_id.local_id);
let expr = Expr {
ty: block_ty,
temp_lifetime,
span: block.span,
kind: ExprKind::Block { body: block },
};
let expr = Expr { ty: block_ty, temp_lifetime, span, kind: ExprKind::Block { body: block } };
expr.to_ref()
}
3 changes: 2 additions & 1 deletion compiler/rustc_passes/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,15 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
match destination.target_id {
Ok(loop_id) => {
if let Node::Block(block) = self.hir_map.find(loop_id).unwrap() {
let block_span = self.hir_map.span(block.hir_id);
struct_span_err!(
self.sess,
e.span,
E0696,
"`continue` pointing to a labeled block"
)
.span_label(e.span, "labeled blocks cannot be `continue`'d")
.span_label(block.span, "labeled block the `continue` points to")
.span_label(block_span, "labeled block the `continue` points to")
.emit();
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(span, expected_ty.and_then(|ty| self.could_remove_semicolon(block, ty)))
} else {
// empty block; point at its entirety
(block.span, None)
let block_span = self.tcx.hir().span(block.hir_id);
(block_span, None)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let coerce = match source {
// you can only use break with a value from a normal `loop { }`
hir::LoopSource::Loop => {
let coerce_to = expected.coercion_target_type(self, body.span);
let span = self.tcx.hir().span(body.hir_id);
let coerce_to = expected.coercion_target_type(self, span);
Some(CoerceMany::new(coerce_to))
}

Expand Down Expand Up @@ -855,8 +856,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// (which would have type !) are only possible iff we
// permit break with a value [1].
if ctxt.coerce.is_none() && !ctxt.may_break {
let span = self.tcx.hir().span(body.hir_id);
// [1]
self.tcx.sess.delay_span_bug(body.span, "no coercion, but loop may not break");
self.tcx.sess.delay_span_bug(span, "no coercion, but loop may not break");
}
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.mk_unit())
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return None;
}
let last_stmt_span = self.tcx.hir().span(last_stmt.hir_id);
let original_span = original_sp(last_stmt_span, blk.span);
let blk_span = self.tcx.hir().span(blk.hir_id);
let original_span = original_sp(last_stmt_span, blk_span);
Some((original_span.with_lo(original_span.hi() - BytePos(1)), needs_box))
}

Expand Down
17 changes: 11 additions & 6 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// if the block produces a `!` value, that can always be
// (effectively) coerced to unit.
if !ty.is_never() {
self.demand_suptype(blk.span, unit, ty);
let blk_span = self.tcx.hir().span(blk.hir_id);
self.demand_suptype(blk_span, unit, ty);
}
}

Expand Down Expand Up @@ -611,7 +612,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// break 'a 22; }` would not force the type of the block
// to be `()`).
let tail_expr = blk.expr.as_ref();
let coerce_to_ty = expected.coercion_target_type(self, blk.span);
let blk_span = self.tcx.hir().span(blk.hir_id);
let coerce_to_ty = expected.coercion_target_type(self, blk_span);
let coerce = if blk.targeted_by_break {
CoerceMany::new(coerce_to_ty)
} else {
Expand Down Expand Up @@ -659,15 +661,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// `consider_hint_about_removing_semicolon` will point at the last expression
// if it were a relevant part of the error. This improves usability in editors
// that highlight errors inline.
let mut sp = blk.span;
let mut sp = self.tcx.hir().span(blk.hir_id);
let mut fn_span = None;
if let Some((decl, ident)) = self.get_parent_fn_decl(blk.hir_id) {
let ret_sp = decl.output.span();
if let Some(block_sp) = self.parent_item_span(blk.hir_id) {
// HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the
// output would otherwise be incorrect and even misleading. Make sure
// the span we're aiming at correspond to a `fn` body.
if block_sp == blk.span {
let blk_span = self.tcx.hir().span(blk.hir_id);
if block_sp == blk_span {
sp = ret_sp;
fn_span = Some(ident.span);
}
Expand Down Expand Up @@ -783,7 +786,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(_, body_id), .. }) => {
let body = self.tcx.hir().body(body_id);
if let ExprKind::Block(block, _) = &body.value.kind {
return Some(block.span);
let block_span = self.tcx.hir().span(block.hir_id);
return Some(block_span);
}
}
_ => {}
Expand Down Expand Up @@ -820,7 +824,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(match &arm.body.kind {
// Point at the tail expression when possible.
hir::ExprKind::Block(block, _) => {
block.expr.as_ref().map(|e| e.span).unwrap_or(block.span)
let block_span = self.tcx.hir().span(block.hir_id);
block.expr.as_ref().map(|e| e.span).unwrap_or(block_span)
}
_ => arm.body.span,
})
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
}

fn visit_block(&mut self, b: &'tcx hir::Block<'tcx>) {
self.visit_node_id(b.span, b.hir_id);
let span = self.tcx().hir().span(b.hir_id);
self.visit_node_id(span, b.hir_id);
intravisit::walk_block(self, b);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions {
"let res = {}; if res",
snippet_block_with_applicability(
cx,
block.span,
cx.tcx.hir().span(block.hir_id),
"..",
Some(expr.span),
&mut applicability
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ fn lint_same_then_else(cx: &LateContext<'_>, blocks: &[&Block<'_>]) {
span_lint_and_note(
cx,
IF_SAME_THEN_ELSE,
j.span,
cx.tcx.hir().span(j.hir_id),
"this `if` has identical blocks",
Some(i.span),
Some(cx.tcx.hir().span(i.hir_id)),
"same as this",
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,8 @@ fn check_for_single_element_loop<'tcx>(

then {
let for_span = get_span_of_entire_for_loop(expr);
let mut block_str = snippet(cx, block.span, "..").into_owned();
let block_span = cx.tcx.hir().span(block.hir_id);
let mut block_str = snippet(cx, block_span, "..").into_owned();
block_str.remove(0);
block_str.pop();

Expand Down
5 changes: 3 additions & 2 deletions src/tools/clippy/clippy_lints/src/manual_async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
Applicability::MachineApplicable
);

let body_snip = snippet_block(cx, closure_body.value.span, "..", Some(block.span));
let block_span = cx.tcx.hir().span(block.hir_id);
let body_snip = snippet_block(cx, closure_body.value.span, "..", Some(block_span));
diag.span_suggestion(
block.span,
block_span,
"move the body of the async block to the enclosing function",
body_snip.to_string(),
Applicability::MachineApplicable
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,8 @@ fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[A
match match_body.kind {
ExprKind::Block(block, _) => {
// macro + expr_ty(body) == ()
if block.span.from_expansion() && cx.typeck_results().expr_ty(&match_body).is_unit() {
let block_span = cx.tcx.hir().span(block.hir_id);
if block_span.from_expansion() && cx.typeck_results().expr_ty(&match_body).is_unit() {
snippet_body.push(';');
}
},
Expand Down