Skip to content

Remove Spans from HIR -- 3/N -- hir::Item #73095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3603d31
Remove useless Clone bound in IndexVec.
cjgillot May 19, 2020
76a36df
Introduce HirIdVec.
cjgillot May 19, 2020
c6acd0f
Collect spans during HIR indexing.
cjgillot May 1, 2020
71b5666
Introduce a query for HIR spans.
cjgillot May 8, 2020
5b5bc8d
Collect spans during lowering.
cjgillot May 1, 2020
6a1537c
Collect spans directly into an IndexVec.
cjgillot May 18, 2020
3640fb3
Directly use span map for indexing.
cjgillot May 1, 2020
1b9ccbf
Don't pass spans in hir::map::blocks.
cjgillot May 2, 2020
9f00730
Add comment.
cjgillot Jun 6, 2020
ff32863
Stop passing the Span in HIR visiting.
cjgillot May 2, 2020
61402a5
Pass HirId in save_analysis.
cjgillot Jun 7, 2020
a1b12d8
Remove span from hir::Param.
cjgillot May 1, 2020
dad5ec0
Remove span from hir::Variant.
cjgillot May 1, 2020
0bf0ea2
Remove span from hir::StructField.
cjgillot May 1, 2020
76f16ed
Remove span from hir::Stmt.
cjgillot May 1, 2020
8197821
Remove span from hir::Block.
cjgillot May 1, 2020
deec340
Remove span from hir::MacroDef.
cjgillot May 2, 2020
7584102
Remove span from hir::GenericParam.
cjgillot May 2, 2020
71c2c92
Remove span from hir::Arm.
cjgillot May 2, 2020
f94dac7
Remove span from hir::FieldPat.
cjgillot May 2, 2020
1f05c3d
Remove span from hir::Local.
cjgillot May 2, 2020
61504ae
Remove span from hir::Pat.
cjgillot May 2, 2020
44a58d4
Remove span from hir::Field.
cjgillot May 2, 2020
415ad17
Remove GenericArg::span.
cjgillot May 3, 2020
ed0b627
Remove Span from hir::TypeBinding.
cjgillot May 8, 2020
56ee3f9
Remove Span from hir::ConstArg.
cjgillot Jun 1, 2020
00ce893
Remove Span from hir::TraitItemRef.
cjgillot Jun 1, 2020
0f31095
Remove Span from hir::ImplItemRef.
cjgillot Jun 1, 2020
312c2fb
Fix fulldeps tests.
cjgillot May 9, 2020
d3a1ecd
Pass HirId in librustc_typeck::check.
cjgillot May 2, 2020
63db483
Pass HirId in librustc_lint.
cjgillot May 2, 2020
066195c
Pass HirId in librustc_passes::stability.
cjgillot May 2, 2020
edbbd56
Remove span from hir::Item.
cjgillot May 2, 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
51 changes: 22 additions & 29 deletions src/librustc_ast_lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::Res;
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned, DUMMY_SP};
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_target::asm;
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -203,6 +203,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Include parens in span, but only if it is a super-span.
if e.span.contains(ex.span) {
ex.span = e.span;
self.spans[ex.hir_id] = e.span;
}
// Merge attributes into the inner expression.
let mut attrs = e.attrs.clone();
Expand All @@ -220,7 +221,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
};

hir::Expr {
hir_id: self.lower_node_id(e.id),
hir_id: self.lower_node_id(e.id, e.span),
kind,
span: e.span,
attrs: e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into(),
Expand Down Expand Up @@ -473,15 +474,14 @@ impl<'hir> LoweringContext<'_, 'hir> {

fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
hir::Arm {
hir_id: self.next_id(),
hir_id: self.next_id(arm.span),
attrs: self.lower_attrs(&arm.attrs),
pat: self.lower_pat(&arm.pat),
guard: match arm.guard {
Some(ref x) => Some(hir::Guard::If(self.lower_expr(x))),
_ => None,
},
body: self.lower_expr(&arm.body),
span: arm.span,
}
}

Expand Down Expand Up @@ -510,7 +510,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

// Resume argument type. We let the compiler infer this to simplify the lowering. It is
// fully constrained by `future::from_generator`.
let input_ty = hir::Ty { hir_id: self.next_id(), kind: hir::TyKind::Infer, span };
let input_ty = hir::Ty { hir_id: self.next_id(span), kind: hir::TyKind::Infer, span };

// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
let decl = self.arena.alloc(hir::FnDecl {
Expand All @@ -526,7 +526,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
Ident::with_dummy_span(sym::_task_context),
hir::BindingAnnotation::Mutable,
);
let param = hir::Param { attrs: &[], hir_id: self.next_id(), pat, span };
let param = hir::Param { attrs: &[], hir_id: self.next_id(span), pat };
let params = arena_vec![self; param];

let body_id = self.lower_body(move |this| {
Expand All @@ -548,7 +548,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
Some(hir::Movability::Static),
);
let generator = hir::Expr {
hir_id: self.lower_node_id(closure_node_id),
hir_id: self.lower_node_id(closure_node_id, span),
kind: generator_kind,
span,
attrs: ThinVec::new(),
Expand Down Expand Up @@ -629,7 +629,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Use of `await` outside of an async context, we cannot use `task_context` here.
self.expr_err(span)
};
let pin_ty_id = self.next_id();
let pin_ty_id = self.next_id(span);
let new_unchecked_expr_kind = self.expr_call_std_assoc_fn(
pin_ty_id,
span,
Expand All @@ -653,7 +653,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

// `::std::task::Poll::Ready(result) => break result`
let loop_node_id = self.resolver.next_node_id();
let loop_hir_id = self.lower_node_id(loop_node_id);
let loop_hir_id = self.lower_node_id(loop_node_id, span);
let ready_arm = {
let x_ident = Ident::with_dummy_span(sym::result);
let (x_pat, x_pat_hid) = self.pat_ident(span, x_ident);
Expand Down Expand Up @@ -841,7 +841,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

/// Desugar `<start>..=<end>` into `std::ops::RangeInclusive::new(<start>, <end>)`.
fn lower_expr_range_closed(&mut self, span: Span, e1: &Expr, e2: &Expr) -> hir::ExprKind<'hir> {
let id = self.next_id();
let id = self.next_id(span);
let e1 = self.lower_expr_mut(e1);
let e2 = self.lower_expr_mut(e2);
self.expr_call_std_assoc_fn(
Expand Down Expand Up @@ -898,7 +898,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let target_id = match destination {
Some((id, _)) => {
if let Some(loop_id) = self.resolver.get_label_res(id) {
Ok(self.lower_node_id(loop_id))
Ok(self.lower_node_id(loop_id, DUMMY_SP))
} else {
Err(hir::LoopIdError::UnresolvedLabel)
}
Expand All @@ -907,7 +907,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
.loop_scopes
.last()
.cloned()
.map(|id| Ok(self.lower_node_id(id)))
.map(|id| Ok(self.lower_node_id(id, DUMMY_SP)))
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope)),
};
hir::Destination { label: destination.map(|(_, label)| label), target_id }
Expand Down Expand Up @@ -1304,10 +1304,9 @@ impl<'hir> LoweringContext<'_, 'hir> {

fn lower_field(&mut self, f: &Field) -> hir::Field<'hir> {
hir::Field {
hir_id: self.next_id(),
hir_id: self.next_id(f.span),
ident: f.ident,
expr: self.lower_expr(&f.expr),
span: f.span,
is_shorthand: f.is_shorthand,
}
}
Expand Down Expand Up @@ -1364,6 +1363,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let mut head = self.lower_expr_mut(head);
let desugared_span = self.mark_span_with_reason(DesugaringKind::ForLoop, head.span, None);
head.span = desugared_span;
self.spans[head.hir_id] = desugared_span;

let iter = Ident::with_dummy_span(sym::iter);

Expand Down Expand Up @@ -1448,7 +1448,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `[opt_ident]: loop { ... }`
let kind = hir::ExprKind::Loop(loop_block, opt_label, hir::LoopSource::ForLoop);
let loop_expr = self.arena.alloc(hir::Expr {
hir_id: self.lower_node_id(e.id),
hir_id: self.lower_node_id(e.id, e.span),
kind,
span: e.span,
attrs: ThinVec::new(),
Expand Down Expand Up @@ -1554,7 +1554,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let thin_attrs = ThinVec::from(attrs);
let catch_scope = self.catch_scopes.last().copied();
let ret_expr = if let Some(catch_node) = catch_scope {
let target_id = Ok(self.lower_node_id(catch_node));
let target_id = Ok(self.lower_node_id(catch_node, DUMMY_SP));
self.arena.alloc(self.expr(
try_span,
hir::ExprKind::Break(
Expand Down Expand Up @@ -1758,8 +1758,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn expr_unsafe(&mut self, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
let hir_id = self.next_id();
let span = expr.span;
let hir_id = self.next_id(span);
self.expr(
span,
hir::ExprKind::Block(
Expand All @@ -1768,7 +1768,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 @@ -1788,7 +1787,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 All @@ -1797,21 +1797,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
kind: hir::ExprKind<'hir>,
attrs: AttrVec,
) -> hir::Expr<'hir> {
hir::Expr { hir_id: self.next_id(), kind, span, attrs }
hir::Expr { hir_id: self.next_id(span), kind, span, attrs }
}

fn field(&mut self, ident: Ident, expr: &'hir hir::Expr<'hir>, span: Span) -> hir::Field<'hir> {
hir::Field { hir_id: self.next_id(), ident, span, expr, is_shorthand: false }
hir::Field { hir_id: self.next_id(span), ident, expr, is_shorthand: false }
}

fn arm(&mut self, pat: &'hir hir::Pat<'hir>, expr: &'hir hir::Expr<'hir>) -> hir::Arm<'hir> {
hir::Arm {
hir_id: self.next_id(),
attrs: &[],
pat,
guard: None,
span: expr.span,
body: expr,
}
hir::Arm { hir_id: self.next_id(expr.span), attrs: &[], pat, guard: None, body: expr }
}
}
Loading