1
Fork 0

ast_lowering: Introduce lower_span for catching all spans entering HIR

This commit is contained in:
Vadim Petrochenkov 2021-08-21 00:29:08 +03:00
parent 757a65bfdf
commit 59013cdebe
6 changed files with 330 additions and 169 deletions

View file

@ -128,7 +128,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) } hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) }
} }
}; };
(op, *op_sp) (op, self.lower_span(*op_sp))
}) })
.collect(); .collect();
@ -384,7 +384,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
late: true, late: true,
expr: None, expr: None,
}, },
abi_span, self.lower_span(abi_span),
)); ));
} }
} }
@ -392,8 +392,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let operands = self.arena.alloc_from_iter(operands); let operands = self.arena.alloc_from_iter(operands);
let template = self.arena.alloc_from_iter(asm.template.iter().cloned()); let template = self.arena.alloc_from_iter(asm.template.iter().cloned());
let template_strs = self.arena.alloc_from_iter(asm.template_strs.iter().cloned()); let template_strs = self.arena.alloc_from_iter(
let line_spans = self.arena.alloc_slice(&asm.line_spans[..]); asm.template_strs
.iter()
.map(|(sym, snippet, span)| (*sym, *snippet, self.lower_span(*span))),
);
let line_spans =
self.arena.alloc_from_iter(asm.line_spans.iter().map(|span| self.lower_span(*span)));
let hir_asm = let hir_asm =
hir::InlineAsm { template, template_strs, operands, options: asm.options, line_spans }; hir::InlineAsm { template, template_strs, operands, options: asm.options, line_spans };
self.arena.alloc(hir_asm) self.arena.alloc(hir_asm)

View file

@ -58,7 +58,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
None, None,
)); ));
let args = self.lower_exprs(args); let args = self.lower_exprs(args);
hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args, span) hir::ExprKind::MethodCall(
hir_seg,
self.lower_span(seg.ident.span),
args,
self.lower_span(span),
)
} }
ExprKind::Binary(binop, ref lhs, ref rhs) => { ExprKind::Binary(binop, ref lhs, ref rhs) => {
let binop = self.lower_binop(binop); let binop = self.lower_binop(binop);
@ -71,7 +76,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
let ohs = self.lower_expr(ohs); let ohs = self.lower_expr(ohs);
hir::ExprKind::Unary(op, ohs) hir::ExprKind::Unary(op, ohs)
} }
ExprKind::Lit(ref l) => hir::ExprKind::Lit(respan(l.span, l.kind.clone())), ExprKind::Lit(ref l) => {
hir::ExprKind::Lit(respan(self.lower_span(l.span), l.kind.clone()))
}
ExprKind::Cast(ref expr, ref ty) => { ExprKind::Cast(ref expr, ref ty) => {
let expr = self.lower_expr(expr); let expr = self.lower_expr(expr);
let ty = self.lower_ty(ty, ImplTraitContext::disallowed()); let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
@ -86,9 +93,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
let ohs = self.lower_expr(ohs); let ohs = self.lower_expr(ohs);
hir::ExprKind::AddrOf(k, m, ohs) hir::ExprKind::AddrOf(k, m, ohs)
} }
ExprKind::Let(ref pat, ref scrutinee, span) => { ExprKind::Let(ref pat, ref scrutinee, span) => hir::ExprKind::Let(
hir::ExprKind::Let(self.lower_pat(pat), self.lower_expr(scrutinee), span) self.lower_pat(pat),
} self.lower_expr(scrutinee),
self.lower_span(span),
),
ExprKind::If(ref cond, ref then, ref else_opt) => { ExprKind::If(ref cond, ref then, ref else_opt) => {
self.lower_expr_if(cond, then, else_opt.as_deref()) self.lower_expr_if(cond, then, else_opt.as_deref())
} }
@ -99,7 +108,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ExprKind::Loop(ref body, opt_label) => self.with_loop_scope(e.id, |this| { ExprKind::Loop(ref body, opt_label) => self.with_loop_scope(e.id, |this| {
hir::ExprKind::Loop( hir::ExprKind::Loop(
this.lower_block(body, false), this.lower_block(body, false),
opt_label, this.lower_label(opt_label),
hir::LoopSource::Loop, hir::LoopSource::Loop,
DUMMY_SP, DUMMY_SP,
) )
@ -147,6 +156,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
} }
ExprKind::Block(ref blk, opt_label) => { ExprKind::Block(ref blk, opt_label) => {
let opt_label = self.lower_label(opt_label);
hir::ExprKind::Block(self.lower_block(blk, opt_label.is_some()), opt_label) hir::ExprKind::Block(self.lower_block(blk, opt_label.is_some()), opt_label)
} }
ExprKind::Assign(ref el, ref er, span) => { ExprKind::Assign(ref el, ref er, span) => {
@ -157,7 +167,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_expr(el), self.lower_expr(el),
self.lower_expr(er), self.lower_expr(er),
), ),
ExprKind::Field(ref el, ident) => hir::ExprKind::Field(self.lower_expr(el), ident), ExprKind::Field(ref el, ident) => {
hir::ExprKind::Field(self.lower_expr(el), self.lower_ident(ident))
}
ExprKind::Index(ref el, ref er) => { ExprKind::Index(ref el, ref er) => {
hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er)) hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er))
} }
@ -234,7 +246,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let mut ex = self.lower_expr_mut(ex); let mut ex = self.lower_expr_mut(ex);
// Include parens in span, but only if it is a super-span. // Include parens in span, but only if it is a super-span.
if e.span.contains(ex.span) { if e.span.contains(ex.span) {
ex.span = e.span; ex.span = self.lower_span(e.span);
} }
// Merge attributes into the inner expression. // Merge attributes into the inner expression.
if !e.attrs.is_empty() { if !e.attrs.is_empty() {
@ -262,7 +274,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let hir_id = self.lower_node_id(e.id); let hir_id = self.lower_node_id(e.id);
self.lower_attrs(hir_id, &e.attrs); self.lower_attrs(hir_id, &e.attrs);
hir::Expr { hir_id, kind, span: e.span } hir::Expr { hir_id, kind, span: self.lower_span(e.span) }
}) })
} }
@ -296,7 +308,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
BinOpKind::Ge => hir::BinOpKind::Ge, BinOpKind::Ge => hir::BinOpKind::Ge,
BinOpKind::Gt => hir::BinOpKind::Gt, BinOpKind::Gt => hir::BinOpKind::Gt,
}, },
span: b.span, span: self.lower_span(b.span),
} }
} }
@ -478,7 +490,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
}); });
let hir_id = self.next_id(); let hir_id = self.next_id();
self.lower_attrs(hir_id, &arm.attrs); self.lower_attrs(hir_id, &arm.attrs);
hir::Arm { hir_id, pat, guard, body: self.lower_expr(&arm.body), span: arm.span } hir::Arm {
hir_id,
pat,
guard,
body: self.lower_expr(&arm.body),
span: self.lower_span(arm.span),
}
} }
/// Lower an `async` construct to a generator that is then wrapped so it implements `Future`. /// Lower an `async` construct to a generator that is then wrapped so it implements `Future`.
@ -501,12 +519,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> hir::ExprKind<'hir> { ) -> hir::ExprKind<'hir> {
let output = match ret_ty { let output = match ret_ty {
Some(ty) => hir::FnRetTy::Return(self.lower_ty(&ty, ImplTraitContext::disallowed())), Some(ty) => hir::FnRetTy::Return(self.lower_ty(&ty, ImplTraitContext::disallowed())),
None => hir::FnRetTy::DefaultReturn(span), None => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
}; };
// Resume argument type. We let the compiler infer this to simplify the lowering. It is // Resume argument type. We let the compiler infer this to simplify the lowering. It is
// fully constrained by `future::from_generator`. // 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(),
kind: hir::TyKind::Infer,
span: self.lower_span(span),
};
// The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`. // The closure/generator `FnDecl` takes a single (resume) argument of type `input_ty`.
let decl = self.arena.alloc(hir::FnDecl { let decl = self.arena.alloc(hir::FnDecl {
@ -522,7 +544,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
Ident::with_dummy_span(sym::_task_context), Ident::with_dummy_span(sym::_task_context),
hir::BindingAnnotation::Mutable, hir::BindingAnnotation::Mutable,
); );
let param = hir::Param { hir_id: self.next_id(), pat, ty_span: span, span }; let param = hir::Param {
hir_id: self.next_id(),
pat,
ty_span: self.lower_span(span),
span: self.lower_span(span),
};
let params = arena_vec![self; param]; let params = arena_vec![self; param];
let body_id = self.lower_body(move |this| { let body_id = self.lower_body(move |this| {
@ -540,11 +567,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
capture_clause, capture_clause,
decl, decl,
body_id, body_id,
span, self.lower_span(span),
Some(hir::Movability::Static), Some(hir::Movability::Static),
); );
let generator = let generator = hir::Expr {
hir::Expr { hir_id: self.lower_node_id(closure_node_id), kind: generator_kind, span }; hir_id: self.lower_node_id(closure_node_id),
kind: generator_kind,
span: self.lower_span(span),
};
// `future::from_generator`: // `future::from_generator`:
let unstable_span = let unstable_span =
@ -681,8 +711,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
if let Some(task_context_hid) = self.task_context { if let Some(task_context_hid) = self.task_context {
let lhs = self.expr_ident(span, task_context_ident, task_context_hid); let lhs = self.expr_ident(span, task_context_ident, task_context_hid);
let assign = let assign = self.expr(
self.expr(span, hir::ExprKind::Assign(lhs, yield_expr, span), AttrVec::new()); span,
hir::ExprKind::Assign(lhs, yield_expr, self.lower_span(span)),
AttrVec::new(),
);
self.stmt_expr(span, assign) self.stmt_expr(span, assign)
} else { } else {
// Use of `await` outside of an async context. Return `yield_expr` so that we can // Use of `await` outside of an async context. Return `yield_expr` so that we can
@ -696,8 +729,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
// loop { .. } // loop { .. }
let loop_expr = self.arena.alloc(hir::Expr { let loop_expr = self.arena.alloc(hir::Expr {
hir_id: loop_hir_id, hir_id: loop_hir_id,
kind: hir::ExprKind::Loop(loop_block, None, hir::LoopSource::Loop, span), kind: hir::ExprKind::Loop(
span, loop_block,
None,
hir::LoopSource::Loop,
self.lower_span(span),
),
span: self.lower_span(span),
}); });
// mut pinned => loop { ... } // mut pinned => loop { ... }
@ -735,7 +773,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Lower outside new scope to preserve `is_in_loop_condition`. // Lower outside new scope to preserve `is_in_loop_condition`.
let fn_decl = self.lower_fn_decl(decl, None, false, None); let fn_decl = self.lower_fn_decl(decl, None, false, None);
hir::ExprKind::Closure(capture_clause, fn_decl, body_id, fn_decl_span, generator_option) hir::ExprKind::Closure(
capture_clause,
fn_decl,
body_id,
self.lower_span(fn_decl_span),
generator_option,
)
} }
fn generator_movability_for_fn( fn generator_movability_for_fn(
@ -821,7 +865,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
// closure argument types. // closure argument types.
let fn_decl = self.lower_fn_decl(&outer_decl, None, false, None); let fn_decl = self.lower_fn_decl(&outer_decl, None, false, None);
hir::ExprKind::Closure(capture_clause, fn_decl, body_id, fn_decl_span, None) hir::ExprKind::Closure(
capture_clause,
fn_decl,
body_id,
self.lower_span(fn_decl_span),
None,
)
} }
/// Destructure the LHS of complex assignments. /// Destructure the LHS of complex assignments.
@ -853,7 +903,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
} }
if is_ordinary(self, lhs) { if is_ordinary(self, lhs) {
return hir::ExprKind::Assign(self.lower_expr(lhs), self.lower_expr(rhs), eq_sign_span); return hir::ExprKind::Assign(
self.lower_expr(lhs),
self.lower_expr(rhs),
self.lower_span(eq_sign_span),
);
} }
if !self.sess.features_untracked().destructuring_assignment { if !self.sess.features_untracked().destructuring_assignment {
feature_err( feature_err(
@ -878,7 +932,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
whole_span, whole_span,
Some(rhs), Some(rhs),
pat, pat,
hir::LocalSource::AssignDesugar(eq_sign_span), hir::LocalSource::AssignDesugar(self.lower_span(eq_sign_span)),
); );
// `a = lhs1; b = lhs2;`. // `a = lhs1; b = lhs2;`.
@ -978,10 +1032,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
let pat = self.destructure_assign(&f.expr, eq_sign_span, assignments); let pat = self.destructure_assign(&f.expr, eq_sign_span, assignments);
hir::PatField { hir::PatField {
hir_id: self.next_id(), hir_id: self.next_id(),
ident: f.ident, ident: self.lower_ident(f.ident),
pat, pat,
is_shorthand: f.is_shorthand, is_shorthand: f.is_shorthand,
span: f.span, span: self.lower_span(f.span),
} }
})); }));
let qpath = self.lower_qpath( let qpath = self.lower_qpath(
@ -1033,10 +1087,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
_ => {} _ => {}
} }
// Treat all other cases as normal lvalue. // Treat all other cases as normal lvalue.
let ident = Ident::new(sym::lhs, lhs.span); let ident = Ident::new(sym::lhs, self.lower_span(lhs.span));
let (pat, binding) = self.pat_ident_mut(lhs.span, ident); let (pat, binding) = self.pat_ident_mut(lhs.span, ident);
let ident = self.expr_ident(lhs.span, ident, binding); let ident = self.expr_ident(lhs.span, ident, binding);
let assign = hir::ExprKind::Assign(self.lower_expr(lhs), ident, eq_sign_span); let assign =
hir::ExprKind::Assign(self.lower_expr(lhs), ident, self.lower_span(eq_sign_span));
let expr = self.expr(lhs.span, assign, ThinVec::new()); let expr = self.expr(lhs.span, assign, ThinVec::new());
assignments.push(self.stmt_expr(lhs.span, expr)); assignments.push(self.stmt_expr(lhs.span, expr));
pat pat
@ -1076,7 +1131,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_expr_range_closed(&mut self, span: Span, e1: &Expr, e2: &Expr) -> hir::ExprKind<'hir> { fn lower_expr_range_closed(&mut self, span: Span, e1: &Expr, e2: &Expr) -> hir::ExprKind<'hir> {
let e1 = self.lower_expr_mut(e1); let e1 = self.lower_expr_mut(e1);
let e2 = self.lower_expr_mut(e2); let e2 = self.lower_expr_mut(e2);
let fn_path = hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, span); let fn_path = hir::QPath::LangItem(hir::LangItem::RangeInclusiveNew, self.lower_span(span));
let fn_expr = let fn_expr =
self.arena.alloc(self.expr(span, hir::ExprKind::Path(fn_path), ThinVec::new())); self.arena.alloc(self.expr(span, hir::ExprKind::Path(fn_path), ThinVec::new()));
hir::ExprKind::Call(fn_expr, arena_vec![self; e1, e2]) hir::ExprKind::Call(fn_expr, arena_vec![self; e1, e2])
@ -1104,12 +1159,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
let fields = self.arena.alloc_from_iter( let fields = self.arena.alloc_from_iter(
e1.iter().map(|e| ("start", e)).chain(e2.iter().map(|e| ("end", e))).map(|(s, e)| { e1.iter().map(|e| ("start", e)).chain(e2.iter().map(|e| ("end", e))).map(|(s, e)| {
let expr = self.lower_expr(&e); let expr = self.lower_expr(&e);
let ident = Ident::new(Symbol::intern(s), e.span); let ident = Ident::new(Symbol::intern(s), self.lower_span(e.span));
self.expr_field(ident, expr, e.span) self.expr_field(ident, expr, e.span)
}), }),
); );
hir::ExprKind::Struct(self.arena.alloc(hir::QPath::LangItem(lang_item, span)), fields, None) hir::ExprKind::Struct(
self.arena.alloc(hir::QPath::LangItem(lang_item, self.lower_span(span))),
fields,
None,
)
}
fn lower_label(&self, opt_label: Option<Label>) -> Option<Label> {
let label = opt_label?;
Some(Label { ident: self.lower_ident(label.ident) })
} }
fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination { fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination {
@ -1128,7 +1192,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
.map(|id| Ok(self.lower_node_id(id))) .map(|id| Ok(self.lower_node_id(id)))
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope)), .unwrap_or(Err(hir::LoopIdError::OutsideLoopScope)),
}; };
hir::Destination { label: destination.map(|(_, label)| label), target_id } let label = self.lower_label(destination.map(|(_, label)| label));
hir::Destination { label, target_id }
} }
fn lower_jump_destination(&mut self, id: NodeId, opt_label: Option<Label>) -> hir::Destination { fn lower_jump_destination(&mut self, id: NodeId, opt_label: Option<Label>) -> hir::Destination {
@ -1201,7 +1266,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
constraint: out.constraint, constraint: out.constraint,
is_rw: out.is_rw, is_rw: out.is_rw,
is_indirect: out.is_indirect, is_indirect: out.is_indirect,
span: out.expr.span, span: self.lower_span(out.expr.span),
}) })
.collect(), .collect(),
asm: asm.asm, asm: asm.asm,
@ -1226,9 +1291,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_expr_field(&mut self, f: &ExprField) -> hir::ExprField<'hir> { fn lower_expr_field(&mut self, f: &ExprField) -> hir::ExprField<'hir> {
hir::ExprField { hir::ExprField {
hir_id: self.next_id(), hir_id: self.next_id(),
ident: f.ident, ident: self.lower_ident(f.ident),
expr: self.lower_expr(&f.expr), expr: self.lower_expr(&f.expr),
span: f.span, span: self.lower_span(f.span),
is_shorthand: f.is_shorthand, is_shorthand: f.is_shorthand,
} }
} }
@ -1289,7 +1354,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
orig_head_span, orig_head_span,
None, None,
); );
head.span = desugared_span; head.span = self.lower_span(desugared_span);
let iter = Ident::with_dummy_span(sym::iter); let iter = Ident::with_dummy_span(sym::iter);
@ -1308,7 +1373,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let next_expr = self.expr_ident(pat.span, next_ident, next_pat_hid); let next_expr = self.expr_ident(pat.span, next_ident, next_pat_hid);
let assign = self.arena.alloc(self.expr( let assign = self.arena.alloc(self.expr(
pat.span, pat.span,
hir::ExprKind::Assign(next_expr, val_expr, pat.span), hir::ExprKind::Assign(next_expr, val_expr, self.lower_span(pat.span)),
ThinVec::new(), ThinVec::new(),
)); ));
let some_pat = self.pat_some(pat.span, val_pat); let some_pat = self.pat_some(pat.span, val_pat);
@ -1376,12 +1441,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `[opt_ident]: loop { ... }` // `[opt_ident]: loop { ... }`
let kind = hir::ExprKind::Loop( let kind = hir::ExprKind::Loop(
loop_block, loop_block,
opt_label, self.lower_label(opt_label),
hir::LoopSource::ForLoop, hir::LoopSource::ForLoop,
e.span.with_hi(orig_head_span.hi()), self.lower_span(e.span.with_hi(orig_head_span.hi())),
); );
let loop_expr = let loop_expr = self.arena.alloc(hir::Expr {
self.arena.alloc(hir::Expr { hir_id: self.lower_node_id(e.id), kind, span: e.span }); hir_id: self.lower_node_id(e.id),
kind,
span: self.lower_span(e.span),
});
// `mut iter => { ... }` // `mut iter => { ... }`
let iter_arm = self.arm(iter_pat, loop_expr); let iter_arm = self.arm(iter_pat, loop_expr);
@ -1460,8 +1528,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
let attr = { let attr = {
// `allow(unreachable_code)` // `allow(unreachable_code)`
let allow = { let allow = {
let allow_ident = Ident::new(sym::allow, span); let allow_ident = Ident::new(sym::allow, self.lower_span(span));
let uc_ident = Ident::new(sym::unreachable_code, span); let uc_ident = Ident::new(sym::unreachable_code, self.lower_span(span));
let uc_nested = attr::mk_nested_word_item(uc_ident); let uc_nested = attr::mk_nested_word_item(uc_ident);
attr::mk_list_item(allow_ident, vec![uc_nested]) attr::mk_list_item(allow_ident, vec![uc_nested])
}; };
@ -1630,7 +1698,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
lang_item: hir::LangItem, lang_item: hir::LangItem,
attrs: AttrVec, attrs: AttrVec,
) -> hir::Expr<'hir> { ) -> hir::Expr<'hir> {
self.expr(span, hir::ExprKind::Path(hir::QPath::LangItem(lang_item, span)), attrs) self.expr(
span,
hir::ExprKind::Path(hir::QPath::LangItem(lang_item, self.lower_span(span))),
attrs,
)
} }
pub(super) fn expr_ident( pub(super) fn expr_ident(
@ -1661,7 +1733,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let expr_path = hir::ExprKind::Path(hir::QPath::Resolved( let expr_path = hir::ExprKind::Path(hir::QPath::Resolved(
None, None,
self.arena.alloc(hir::Path { self.arena.alloc(hir::Path {
span, span: self.lower_span(span),
res: Res::Local(binding), res: Res::Local(binding),
segments: arena_vec![self; hir::PathSegment::from_ident(ident)], segments: arena_vec![self; hir::PathSegment::from_ident(ident)],
}), }),
@ -1681,7 +1753,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
expr: Some(expr), expr: Some(expr),
hir_id, hir_id,
rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated), rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated),
span, span: self.lower_span(span),
targeted_by_break: false, targeted_by_break: false,
}), }),
None, None,
@ -1712,7 +1784,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
) -> hir::Expr<'hir> { ) -> hir::Expr<'hir> {
let hir_id = self.next_id(); let hir_id = self.next_id();
self.lower_attrs(hir_id, &attrs); self.lower_attrs(hir_id, &attrs);
hir::Expr { hir_id, kind, span } hir::Expr { hir_id, kind, span: self.lower_span(span) }
} }
fn expr_field( fn expr_field(
@ -1721,10 +1793,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
expr: &'hir hir::Expr<'hir>, expr: &'hir hir::Expr<'hir>,
span: Span, span: Span,
) -> hir::ExprField<'hir> { ) -> hir::ExprField<'hir> {
hir::ExprField { hir_id: self.next_id(), ident, span, expr, is_shorthand: false } hir::ExprField {
hir_id: self.next_id(),
ident,
span: self.lower_span(span),
expr,
is_shorthand: false,
}
} }
fn arm(&mut self, pat: &'hir hir::Pat<'hir>, expr: &'hir hir::Expr<'hir>) -> hir::Arm<'hir> { fn arm(&mut self, pat: &'hir hir::Pat<'hir>, expr: &'hir hir::Expr<'hir>) -> hir::Arm<'hir> {
hir::Arm { hir_id: self.next_id(), pat, guard: None, span: expr.span, body: expr } hir::Arm {
hir_id: self.next_id(),
pat,
guard: None,
span: self.lower_span(expr.span),
body: expr,
}
} }
} }

View file

@ -158,7 +158,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
pub(super) fn lower_mod(&mut self, items: &[P<Item>], inner: Span) -> hir::Mod<'hir> { pub(super) fn lower_mod(&mut self, items: &[P<Item>], inner: Span) -> hir::Mod<'hir> {
hir::Mod { hir::Mod {
inner, inner: self.lower_span(inner),
item_ids: self.arena.alloc_from_iter(items.iter().flat_map(|x| self.lower_item_id(x))), item_ids: self.arena.alloc_from_iter(items.iter().flat_map(|x| self.lower_item_id(x))),
} }
} }
@ -214,7 +214,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let hir_id = self.lower_node_id(i.id); let hir_id = self.lower_node_id(i.id);
let attrs = self.lower_attrs(hir_id, &i.attrs); let attrs = self.lower_attrs(hir_id, &i.attrs);
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, &mut vis, &i.kind); let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, &mut vis, &i.kind);
Some(hir::Item { def_id: hir_id.expect_owner(), ident, kind, vis, span: i.span }) Some(hir::Item {
def_id: hir_id.expect_owner(),
ident: self.lower_ident(ident),
kind,
vis,
span: self.lower_span(i.span),
})
} }
fn lower_item_kind( fn lower_item_kind(
@ -278,7 +284,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let sig = hir::FnSig { let sig = hir::FnSig {
decl, decl,
header: this.lower_fn_header(header, fn_sig_span, id), header: this.lower_fn_header(header, fn_sig_span, id),
span: fn_sig_span, span: this.lower_span(fn_sig_span),
}; };
hir::ItemKind::Fn(sig, generics, body_id) hir::ItemKind::Fn(sig, generics, body_id)
}) })
@ -407,6 +413,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
// to not cause an assertion failure inside the `lower_defaultness` function. // to not cause an assertion failure inside the `lower_defaultness` function.
let has_val = true; let has_val = true;
let (defaultness, defaultness_span) = self.lower_defaultness(defaultness, has_val); let (defaultness, defaultness_span) = self.lower_defaultness(defaultness, has_val);
let polarity = match polarity {
ImplPolarity::Positive => ImplPolarity::Positive,
ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(s)),
};
hir::ItemKind::Impl(hir::Impl { hir::ItemKind::Impl(hir::Impl {
unsafety: self.lower_unsafety(unsafety), unsafety: self.lower_unsafety(unsafety),
polarity, polarity,
@ -525,10 +535,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
this.insert_item(hir::Item { this.insert_item(hir::Item {
def_id: new_id.expect_owner(), def_id: new_id.expect_owner(),
ident, ident: this.lower_ident(ident),
kind, kind,
vis, vis,
span, span: this.lower_span(span),
}); });
}); });
} }
@ -599,10 +609,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
this.insert_item(hir::Item { this.insert_item(hir::Item {
def_id: new_hir_id.expect_owner(), def_id: new_hir_id.expect_owner(),
ident, ident: this.lower_ident(ident),
kind, kind,
vis, vis,
span: use_tree.span, span: this.lower_span(use_tree.span),
}); });
}); });
} }
@ -621,7 +631,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::VisibilityKind::Public hir::VisibilityKind::Public
| hir::VisibilityKind::Crate(_) | hir::VisibilityKind::Crate(_)
| hir::VisibilityKind::Inherited => { | hir::VisibilityKind::Inherited => {
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited); *vis = respan(
self.lower_span(prefix.span.shrink_to_lo()),
hir::VisibilityKind::Inherited,
);
} }
hir::VisibilityKind::Restricted { .. } => { hir::VisibilityKind::Restricted { .. } => {
// Do nothing here, as described in the comment on the match. // Do nothing here, as described in the comment on the match.
@ -664,7 +677,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
} }
}; };
respan(vis.span, vis_kind) respan(self.lower_span(vis.span), vis_kind)
} }
fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> { fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> {
@ -673,7 +686,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_attrs(hir_id, &i.attrs); self.lower_attrs(hir_id, &i.attrs);
hir::ForeignItem { hir::ForeignItem {
def_id, def_id,
ident: i.ident, ident: self.lower_ident(i.ident),
kind: match i.kind { kind: match i.kind {
ForeignItemKind::Fn(box FnKind(_, ref sig, ref generics, _)) => { ForeignItemKind::Fn(box FnKind(_, ref sig, ref generics, _)) => {
let fdec = &sig.decl; let fdec = &sig.decl;
@ -700,15 +713,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"), ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),
}, },
vis: self.lower_visibility(&i.vis, None), vis: self.lower_visibility(&i.vis, None),
span: i.span, span: self.lower_span(i.span),
} }
} }
fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef<'hir> { fn lower_foreign_item_ref(&mut self, i: &ForeignItem) -> hir::ForeignItemRef<'hir> {
hir::ForeignItemRef { hir::ForeignItemRef {
id: hir::ForeignItemId { def_id: self.lower_node_id(i.id).expect_owner() }, id: hir::ForeignItemId { def_id: self.lower_node_id(i.id).expect_owner() },
ident: i.ident, ident: self.lower_ident(i.ident),
span: i.span, span: self.lower_span(i.span),
vis: self.lower_visibility(&i.vis, Some(i.id)), vis: self.lower_visibility(&i.vis, Some(i.id)),
} }
} }
@ -720,8 +733,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
id, id,
data: self.lower_variant_data(id, &v.data), data: self.lower_variant_data(id, &v.data),
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)), disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
ident: v.ident, ident: self.lower_ident(v.ident),
span: v.span, span: self.lower_span(v.span),
} }
} }
@ -773,12 +786,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
let hir_id = self.lower_node_id(f.id); let hir_id = self.lower_node_id(f.id);
self.lower_attrs(hir_id, &f.attrs); self.lower_attrs(hir_id, &f.attrs);
hir::FieldDef { hir::FieldDef {
span: f.span, span: self.lower_span(f.span),
hir_id, hir_id,
ident: match f.ident { ident: match f.ident {
Some(ident) => ident, Some(ident) => self.lower_ident(ident),
// FIXME(jseyfried): positional field hygiene. // FIXME(jseyfried): positional field hygiene.
None => Ident::new(sym::integer(index), f.span), None => Ident::new(sym::integer(index), self.lower_span(f.span)),
}, },
vis: self.lower_visibility(&f.vis, None), vis: self.lower_visibility(&f.vis, None),
ty, ty,
@ -829,7 +842,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
}; };
self.lower_attrs(hir_id, &i.attrs); self.lower_attrs(hir_id, &i.attrs);
hir::TraitItem { def_id: trait_item_def_id, ident: i.ident, generics, kind, span: i.span } hir::TraitItem {
def_id: trait_item_def_id,
ident: self.lower_ident(i.ident),
generics,
kind,
span: self.lower_span(i.span),
}
} }
fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef { fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef {
@ -845,7 +864,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
}; };
let id = hir::TraitItemId { def_id: self.lower_node_id(i.id).expect_owner() }; let id = hir::TraitItemId { def_id: self.lower_node_id(i.id).expect_owner() };
let defaultness = hir::Defaultness::Default { has_value: has_default }; let defaultness = hir::Defaultness::Default { has_value: has_default };
hir::TraitItemRef { id, ident: i.ident, span: i.span, defaultness, kind } hir::TraitItemRef {
id,
ident: self.lower_ident(i.ident),
span: self.lower_span(i.span),
defaultness,
kind,
}
} }
/// Construct `ExprKind::Err` for the given `span`. /// Construct `ExprKind::Err` for the given `span`.
@ -910,12 +935,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_attrs(hir_id, &i.attrs); self.lower_attrs(hir_id, &i.attrs);
hir::ImplItem { hir::ImplItem {
def_id: hir_id.expect_owner(), def_id: hir_id.expect_owner(),
ident: i.ident, ident: self.lower_ident(i.ident),
generics, generics,
vis: self.lower_visibility(&i.vis, None), vis: self.lower_visibility(&i.vis, None),
defaultness, defaultness,
kind, kind,
span: i.span, span: self.lower_span(i.span),
} }
} }
@ -925,8 +950,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value); let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
hir::ImplItemRef { hir::ImplItemRef {
id: hir::ImplItemId { def_id: self.lower_node_id(i.id).expect_owner() }, id: hir::ImplItemId { def_id: self.lower_node_id(i.id).expect_owner() },
ident: i.ident, ident: self.lower_ident(i.ident),
span: i.span, span: self.lower_span(i.span),
vis: self.lower_visibility(&i.vis, Some(i.id)), vis: self.lower_visibility(&i.vis, Some(i.id)),
defaultness, defaultness,
kind: match &i.kind { kind: match &i.kind {
@ -969,7 +994,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
VisibilityKind::Inherited => hir::VisibilityKind::Inherited, VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
}; };
respan(v.span, node) respan(self.lower_span(v.span), node)
} }
fn lower_defaultness( fn lower_defaultness(
@ -978,7 +1003,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
has_value: bool, has_value: bool,
) -> (hir::Defaultness, Option<Span>) { ) -> (hir::Defaultness, Option<Span>) {
match d { match d {
Defaultness::Default(sp) => (hir::Defaultness::Default { has_value }, Some(sp)), Defaultness::Default(sp) => {
(hir::Defaultness::Default { has_value }, Some(self.lower_span(sp)))
}
Defaultness::Final => { Defaultness::Final => {
assert!(has_value); assert!(has_value);
(hir::Defaultness::Final, None) (hir::Defaultness::Final, None)
@ -1016,8 +1043,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::Param { hir::Param {
hir_id, hir_id,
pat: self.lower_pat(&param.pat), pat: self.lower_pat(&param.pat),
ty_span: param.ty.span, ty_span: self.lower_span(param.ty.span),
span: param.span, span: self.lower_span(param.span),
} }
} }
@ -1151,8 +1178,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
let new_parameter = hir::Param { let new_parameter = hir::Param {
hir_id: parameter.hir_id, hir_id: parameter.hir_id,
pat: new_parameter_pat, pat: new_parameter_pat,
ty_span: parameter.ty_span, ty_span: this.lower_span(parameter.ty_span),
span: parameter.span, span: this.lower_span(parameter.span),
}; };
if is_simple_parameter { if is_simple_parameter {
@ -1285,7 +1312,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
) )
}, },
); );
(generics, hir::FnSig { header, decl, span: sig.span }) (generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
} }
fn lower_fn_header(&mut self, h: FnHeader, span: Span, id: NodeId) -> hir::FnHeader { fn lower_fn_header(&mut self, h: FnHeader, span: Span, id: NodeId) -> hir::FnHeader {
@ -1385,7 +1412,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
GenericsCtor { GenericsCtor {
params: self.lower_generic_params_mut(&generics.params, &add_bounds, itctx).collect(), params: self.lower_generic_params_mut(&generics.params, &add_bounds, itctx).collect(),
where_clause: self.lower_where_clause(&generics.where_clause), where_clause: self.lower_where_clause(&generics.where_clause),
span: generics.span, span: self.lower_span(generics.span),
} }
} }
@ -1404,7 +1431,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
predicates: this.arena.alloc_from_iter( predicates: this.arena.alloc_from_iter(
wc.predicates.iter().map(|predicate| this.lower_where_predicate(predicate)), wc.predicates.iter().map(|predicate| this.lower_where_predicate(predicate)),
), ),
span: wc.span, span: this.lower_span(wc.span),
} }
}) })
} }
@ -1433,12 +1460,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `suggest_constraining_type_param`. This will need to change if // `suggest_constraining_type_param`. This will need to change if
// we ever allow something *other* than `?Sized`. // we ever allow something *other* than `?Sized`.
GenericBound::Trait(p, TraitBoundModifier::Maybe) => { GenericBound::Trait(p, TraitBoundModifier::Maybe) => {
hir::GenericBound::Unsized(p.span) hir::GenericBound::Unsized(this.lower_span(p.span))
} }
_ => this.lower_param_bound(bound, ImplTraitContext::disallowed()), _ => this.lower_param_bound(bound, ImplTraitContext::disallowed()),
}, },
)), )),
span, span: this.lower_span(span),
}) })
}) })
} }
@ -1447,7 +1474,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ref bounds, ref bounds,
span, span,
}) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate { }) => hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
span, span: self.lower_span(span),
lifetime: self.lower_lifetime(lifetime), lifetime: self.lower_lifetime(lifetime),
bounds: self.lower_param_bounds(bounds, ImplTraitContext::disallowed()), bounds: self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
}), }),
@ -1456,7 +1483,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir_id: self.lower_node_id(id), hir_id: self.lower_node_id(id),
lhs_ty: self.lower_ty(lhs_ty, ImplTraitContext::disallowed()), lhs_ty: self.lower_ty(lhs_ty, ImplTraitContext::disallowed()),
rhs_ty: self.lower_ty(rhs_ty, ImplTraitContext::disallowed()), rhs_ty: self.lower_ty(rhs_ty, ImplTraitContext::disallowed()),
span, span: self.lower_span(span),
}) })
} }
} }

View file

@ -760,6 +760,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
result result
} }
/// Intercept all spans entering HIR.
/// For now we are not doing anything with the intercepted spans.
fn lower_span(&self, span: Span) -> Span {
span
}
fn lower_ident(&self, ident: Ident) -> Ident {
Ident::new(ident.name, self.lower_span(ident.span))
}
/// Creates a new `hir::GenericParam` for every new lifetime and /// Creates a new `hir::GenericParam` for every new lifetime and
/// type parameter encountered while evaluating `f`. Definitions /// type parameter encountered while evaluating `f`. Definitions
/// are created with the parent provided. If no `parent_id` is /// are created with the parent provided. If no `parent_id` is
@ -828,7 +838,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir_id: self.lower_node_id(node_id), hir_id: self.lower_node_id(node_id),
name: hir_name, name: hir_name,
bounds: &[], bounds: &[],
span, span: self.lower_span(span),
pure_wrt_drop: false, pure_wrt_drop: false,
kind: hir::GenericParamKind::Lifetime { kind }, kind: hir::GenericParamKind::Lifetime { kind },
} }
@ -989,7 +999,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
AttrKind::DocComment(comment_kind, data) => AttrKind::DocComment(comment_kind, data), AttrKind::DocComment(comment_kind, data) => AttrKind::DocComment(comment_kind, data),
}; };
Attribute { kind, id: attr.id, style: attr.style, span: attr.span } Attribute { kind, id: attr.id, style: attr.style, span: self.lower_span(attr.span) }
} }
fn alias_attrs(&mut self, id: hir::HirId, target_id: hir::HirId) { fn alias_attrs(&mut self, id: hir::HirId, target_id: hir::HirId) {
@ -1117,7 +1127,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.0 .0
} }
}; };
self.arena.alloc(gen_args_ctor.into_generic_args(&self.arena)) gen_args_ctor.into_generic_args(self)
} else { } else {
self.arena.alloc(hir::GenericArgs::none()) self.arena.alloc(hir::GenericArgs::none())
}; };
@ -1198,7 +1208,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&Ty { &Ty {
id: node_id, id: node_id,
kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()), kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
span: constraint.span, span: this.lower_span(constraint.span),
tokens: None, tokens: None,
}, },
itctx, itctx,
@ -1218,10 +1228,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::TypeBinding { hir::TypeBinding {
hir_id: self.lower_node_id(constraint.id), hir_id: self.lower_node_id(constraint.id),
ident: constraint.ident, ident: self.lower_ident(constraint.ident),
gen_args, gen_args,
kind, kind,
span: constraint.span, span: self.lower_span(constraint.span),
} }
} }
@ -1235,10 +1245,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ast::GenericArg::Type(ty) => { ast::GenericArg::Type(ty) => {
match ty.kind { match ty.kind {
TyKind::Infer if self.sess.features_untracked().generic_arg_infer => { TyKind::Infer if self.sess.features_untracked().generic_arg_infer => {
let hir_id = self.lower_node_id(ty.id);
return GenericArg::Infer(hir::InferArg { return GenericArg::Infer(hir::InferArg {
hir_id, hir_id: self.lower_node_id(ty.id),
span: ty.span, span: self.lower_span(ty.span),
kind: InferKind::Type, kind: InferKind::Type,
}); });
} }
@ -1269,10 +1278,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ty.span, ty.span,
); );
let span = self.lower_span(ty.span);
let path_expr = Expr { let path_expr = Expr {
id: ty.id, id: ty.id,
kind: ExprKind::Path(qself.clone(), path.clone()), kind: ExprKind::Path(qself.clone(), path.clone()),
span: ty.span, span,
attrs: AttrVec::new(), attrs: AttrVec::new(),
tokens: None, tokens: None,
}; };
@ -1281,7 +1291,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir_id: this.lower_node_id(node_id), hir_id: this.lower_node_id(node_id),
body: this.lower_const_body(path_expr.span, Some(&path_expr)), body: this.lower_const_body(path_expr.span, Some(&path_expr)),
}); });
return GenericArg::Const(ConstArg { value: ct, span: ty.span }); return GenericArg::Const(ConstArg { value: ct, span });
} }
} }
} }
@ -1291,7 +1301,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
ast::GenericArg::Const(ct) => GenericArg::Const(ConstArg { ast::GenericArg::Const(ct) => GenericArg::Const(ConstArg {
value: self.lower_anon_const(&ct), value: self.lower_anon_const(&ct),
span: ct.value.span, span: self.lower_span(ct.value.span),
}), }),
} }
} }
@ -1318,7 +1328,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> { fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
hir::Ty { hir_id: self.next_id(), kind, span } hir::Ty { hir_id: self.next_id(), kind, span: self.lower_span(span) }
} }
fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> { fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
@ -1386,7 +1396,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
segments: arena_vec![self; hir::PathSegment::from_ident( segments: arena_vec![self; hir::PathSegment::from_ident(
Ident::with_dummy_span(kw::SelfUpper) Ident::with_dummy_span(kw::SelfUpper)
)], )],
span: t.span, span: self.lower_span(t.span),
}), }),
)) ))
} }
@ -1467,10 +1477,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span); let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
in_band_ty_params.push(hir::GenericParam { in_band_ty_params.push(hir::GenericParam {
hir_id: self.lower_node_id(def_node_id), hir_id: self.lower_node_id(def_node_id),
name: ParamName::Plain(ident), name: ParamName::Plain(self.lower_ident(ident)),
pure_wrt_drop: false, pure_wrt_drop: false,
bounds: hir_bounds, bounds: hir_bounds,
span, span: self.lower_span(span),
kind: hir::GenericParamKind::Type { kind: hir::GenericParamKind::Type {
default: None, default: None,
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait), synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
@ -1480,9 +1490,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::TyKind::Path(hir::QPath::Resolved( hir::TyKind::Path(hir::QPath::Resolved(
None, None,
self.arena.alloc(hir::Path { self.arena.alloc(hir::Path {
span, span: self.lower_span(span),
res: Res::Def(DefKind::TyParam, def_id.to_def_id()), res: Res::Def(DefKind::TyParam, def_id.to_def_id()),
segments: arena_vec![self; hir::PathSegment::from_ident(ident)], segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident))],
}), }),
)) ))
} }
@ -1509,7 +1519,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
}; };
hir::Ty { kind, span: t.span, hir_id: self.lower_node_id(t.id) } hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
} }
fn lower_opaque_impl_trait( fn lower_opaque_impl_trait(
@ -1554,8 +1564,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let opaque_ty_item = hir::OpaqueTy { let opaque_ty_item = hir::OpaqueTy {
generics: hir::Generics { generics: hir::Generics {
params: lifetime_defs, params: lifetime_defs,
where_clause: hir::WhereClause { predicates: &[], span }, where_clause: hir::WhereClause { predicates: &[], span: lctx.lower_span(span) },
span, span: lctx.lower_span(span),
}, },
bounds: hir_bounds, bounds: hir_bounds,
impl_trait_fn: fn_def_id, impl_trait_fn: fn_def_id,
@ -1586,8 +1596,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
def_id: opaque_ty_id, def_id: opaque_ty_id,
ident: Ident::invalid(), ident: Ident::invalid(),
kind: opaque_ty_item_kind, kind: opaque_ty_item_kind,
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited), vis: respan(self.lower_span(span.shrink_to_lo()), hir::VisibilityKind::Inherited),
span: opaque_ty_span, span: self.lower_span(opaque_ty_span),
}; };
// Insert the item into the global item list. This usually happens // Insert the item into the global item list. This usually happens
@ -1714,7 +1724,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.output_lifetimes.push(hir::GenericArg::Lifetime(hir::Lifetime { self.output_lifetimes.push(hir::GenericArg::Lifetime(hir::Lifetime {
hir_id: self.context.next_id(), hir_id: self.context.next_id(),
span: lifetime.span, span: self.context.lower_span(lifetime.span),
name, name,
})); }));
@ -1739,11 +1749,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
_ => panic!("expected `LifetimeName::Param` or `ParamName::Plain`"), _ => panic!("expected `LifetimeName::Param` or `ParamName::Plain`"),
}; };
let name = match name {
hir::ParamName::Plain(ident) => {
hir::ParamName::Plain(self.context.lower_ident(ident))
}
name => name,
};
self.output_lifetime_params.push(hir::GenericParam { self.output_lifetime_params.push(hir::GenericParam {
hir_id, hir_id,
name, name,
span: lifetime.span, span: self.context.lower_span(lifetime.span),
pure_wrt_drop: false, pure_wrt_drop: false,
bounds: &[], bounds: &[],
kind: hir::GenericParamKind::Lifetime { kind }, kind: hir::GenericParamKind::Lifetime { kind },
@ -1790,7 +1806,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ty, ty,
pat: self.lower_pat(&l.pat), pat: self.lower_pat(&l.pat),
init, init,
span: l.span, span: self.lower_span(l.span),
source: hir::LocalSource::Normal, source: hir::LocalSource::Normal,
} }
} }
@ -1804,8 +1820,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
inputs = &inputs[..inputs.len() - 1]; inputs = &inputs[..inputs.len() - 1];
} }
self.arena.alloc_from_iter(inputs.iter().map(|param| match param.pat.kind { self.arena.alloc_from_iter(inputs.iter().map(|param| match param.pat.kind {
PatKind::Ident(_, ident, _) => ident, PatKind::Ident(_, ident, _) => self.lower_ident(ident),
_ => Ident::new(kw::Empty, param.pat.span), _ => Ident::new(kw::Empty, self.lower_span(param.pat.span)),
})) }))
} }
@ -1889,7 +1905,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}; };
hir::FnRetTy::Return(self.lower_ty(ty, context)) hir::FnRetTy::Return(self.lower_ty(ty, context))
} }
FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(span), FnRetTy::Default(span) => hir::FnRetTy::DefaultReturn(self.lower_span(span)),
} }
}; };
@ -2046,8 +2062,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let opaque_ty_item = hir::OpaqueTy { let opaque_ty_item = hir::OpaqueTy {
generics: hir::Generics { generics: hir::Generics {
params: generic_params, params: generic_params,
where_clause: hir::WhereClause { predicates: &[], span }, where_clause: hir::WhereClause { predicates: &[], span: this.lower_span(span) },
span, span: this.lower_span(span),
}, },
bounds: arena_vec![this; future_bound], bounds: arena_vec![this; future_bound],
impl_trait_fn: Some(fn_def_id), impl_trait_fn: Some(fn_def_id),
@ -2082,7 +2098,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Input lifetime like `'a` or `'1`: // Input lifetime like `'a` or `'1`:
GenericArg::Lifetime(hir::Lifetime { GenericArg::Lifetime(hir::Lifetime {
hir_id: self.next_id(), hir_id: self.next_id(),
span, span: self.lower_span(span),
name: hir::LifetimeName::Param(hir_name), name: hir::LifetimeName::Param(hir_name),
}) })
}, },
@ -2091,7 +2107,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Output lifetime like `'_`. // Output lifetime like `'_`.
GenericArg::Lifetime(hir::Lifetime { GenericArg::Lifetime(hir::Lifetime {
hir_id: self.next_id(), hir_id: self.next_id(),
span, span: self.lower_span(span),
name: hir::LifetimeName::Implicit, name: hir::LifetimeName::Implicit,
}))); })));
let generic_args = self.arena.alloc_from_iter(generic_args); let generic_args = self.arena.alloc_from_iter(generic_args);
@ -2139,7 +2155,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::GenericBound::LangItemTrait( hir::GenericBound::LangItemTrait(
// ::std::future::Future<future_params> // ::std::future::Future<future_params>
hir::LangItem::Future, hir::LangItem::Future,
span, self.lower_span(span),
self.next_id(), self.next_id(),
future_args, future_args,
) )
@ -2162,7 +2178,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime { fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
let span = l.ident.span; let span = self.lower_span(l.ident.span);
match l.ident { match l.ident {
ident if ident.name == kw::StaticLifetime => { ident if ident.name == kw::StaticLifetime => {
self.new_named_lifetime(l.id, span, hir::LifetimeName::Static) self.new_named_lifetime(l.id, span, hir::LifetimeName::Static)
@ -2181,7 +2197,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}, },
ident => { ident => {
self.maybe_collect_in_band_lifetime(ident); self.maybe_collect_in_band_lifetime(ident);
let param_name = ParamName::Plain(ident); let param_name = ParamName::Plain(self.lower_ident(ident));
self.new_named_lifetime(l.id, span, hir::LifetimeName::Param(param_name)) self.new_named_lifetime(l.id, span, hir::LifetimeName::Param(param_name))
} }
} }
@ -2193,7 +2209,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: Span, span: Span,
name: hir::LifetimeName, name: hir::LifetimeName,
) -> hir::Lifetime { ) -> hir::Lifetime {
hir::Lifetime { hir_id: self.lower_node_id(id), span, name } hir::Lifetime { hir_id: self.lower_node_id(id), span: self.lower_span(span), name }
} }
fn lower_generic_params_mut<'s>( fn lower_generic_params_mut<'s>(
@ -2276,7 +2292,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.next(), .next(),
}; };
(hir::ParamName::Plain(param.ident), kind) (hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
} }
GenericParamKind::Const { ref ty, kw_span: _, ref default } => { GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
let ty = self let ty = self
@ -2284,16 +2300,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
this.lower_ty(&ty, ImplTraitContext::disallowed()) this.lower_ty(&ty, ImplTraitContext::disallowed())
}); });
let default = default.as_ref().map(|def| self.lower_anon_const(def)); let default = default.as_ref().map(|def| self.lower_anon_const(def));
(hir::ParamName::Plain(param.ident), hir::GenericParamKind::Const { ty, default }) (
hir::ParamName::Plain(self.lower_ident(param.ident)),
hir::GenericParamKind::Const { ty, default },
)
} }
}; };
let name = match name {
hir::ParamName::Plain(ident) => hir::ParamName::Plain(self.lower_ident(ident)),
name => name,
};
let hir_id = self.lower_node_id(param.id); let hir_id = self.lower_node_id(param.id);
self.lower_attrs(hir_id, &param.attrs); self.lower_attrs(hir_id, &param.attrs);
hir::GenericParam { hir::GenericParam {
hir_id, hir_id,
name, name,
span: param.ident.span, span: self.lower_span(param.ident.span),
pure_wrt_drop: self.sess.contains_name(&param.attrs, sym::may_dangle), pure_wrt_drop: self.sess.contains_name(&param.attrs, sym::may_dangle),
bounds: self.arena.alloc_from_iter(bounds), bounds: self.arena.alloc_from_iter(bounds),
kind, kind,
@ -2350,7 +2373,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
res res
}); });
hir::PolyTraitRef { bound_generic_params, trait_ref, span: p.span } hir::PolyTraitRef { bound_generic_params, trait_ref, span: self.lower_span(p.span) }
} }
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_, 'hir>) -> hir::MutTy<'hir> { fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext<'_, 'hir>) -> hir::MutTy<'hir> {
@ -2387,7 +2410,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let rules = self.lower_block_check_mode(&b.rules); let rules = self.lower_block_check_mode(&b.rules);
let hir_id = self.lower_node_id(b.id); let hir_id = self.lower_node_id(b.id);
hir::Block { hir_id, stmts, expr, rules, span: b.span, targeted_by_break } hir::Block { hir_id, stmts, expr, rules, span: self.lower_span(b.span), targeted_by_break }
} }
/// Lowers a block directly to an expression, presuming that it /// Lowers a block directly to an expression, presuming that it
@ -2413,7 +2436,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
return smallvec![hir::Stmt { return smallvec![hir::Stmt {
hir_id, hir_id,
kind: hir::StmtKind::Local(self.arena.alloc(l)), kind: hir::StmtKind::Local(self.arena.alloc(l)),
span: s.span, span: self.lower_span(s.span),
}]; }];
} }
StmtKind::Item(ref it) => { StmtKind::Item(ref it) => {
@ -2428,7 +2451,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.map(|id| self.lower_node_id(id)) .map(|id| self.lower_node_id(id))
.unwrap_or_else(|| self.next_id()); .unwrap_or_else(|| self.next_id());
hir::Stmt { hir_id, kind: hir::StmtKind::Item(item_id), span: s.span } hir::Stmt {
hir_id,
kind: hir::StmtKind::Item(item_id),
span: self.lower_span(s.span),
}
}) })
.collect(); .collect();
} }
@ -2447,7 +2474,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
StmtKind::Empty => return smallvec![], StmtKind::Empty => return smallvec![],
StmtKind::MacCall(..) => panic!("shouldn't exist here"), StmtKind::MacCall(..) => panic!("shouldn't exist here"),
}; };
smallvec![hir::Stmt { hir_id, kind, span: s.span }] smallvec![hir::Stmt { hir_id, kind, span: self.lower_span(s.span) }]
} }
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode { fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {
@ -2482,7 +2509,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Helper methods for building HIR. // Helper methods for building HIR.
fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> { fn stmt(&mut self, span: Span, kind: hir::StmtKind<'hir>) -> hir::Stmt<'hir> {
hir::Stmt { span, kind, hir_id: self.next_id() } hir::Stmt { span: self.lower_span(span), kind, hir_id: self.next_id() }
} }
fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> { fn stmt_expr(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Stmt<'hir> {
@ -2502,7 +2529,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
debug_assert!(!a.is_empty()); debug_assert!(!a.is_empty());
self.attrs.insert(hir_id, a); self.attrs.insert(hir_id, a);
} }
let local = hir::Local { hir_id, init, pat, source, span, ty: None }; let local = hir::Local { hir_id, init, pat, source, span: self.lower_span(span), ty: None };
self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local))) self.stmt(span, hir::StmtKind::Local(self.arena.alloc(local)))
} }
@ -2521,7 +2548,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
expr, expr,
hir_id: self.next_id(), hir_id: self.next_id(),
rules: hir::BlockCheckMode::DefaultBlock, rules: hir::BlockCheckMode::DefaultBlock,
span, span: self.lower_span(span),
targeted_by_break: false, targeted_by_break: false,
}; };
self.arena.alloc(blk) self.arena.alloc(blk)
@ -2553,10 +2580,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) -> &'hir [hir::PatField<'hir>] { ) -> &'hir [hir::PatField<'hir>] {
let field = hir::PatField { let field = hir::PatField {
hir_id: self.next_id(), hir_id: self.next_id(),
ident: Ident::new(sym::integer(0), span), ident: Ident::new(sym::integer(0), self.lower_span(span)),
is_shorthand: false, is_shorthand: false,
pat, pat,
span, span: self.lower_span(span),
}; };
arena_vec![self; field] arena_vec![self; field]
} }
@ -2567,7 +2594,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
lang_item: hir::LangItem, lang_item: hir::LangItem,
fields: &'hir [hir::PatField<'hir>], fields: &'hir [hir::PatField<'hir>],
) -> &'hir hir::Pat<'hir> { ) -> &'hir hir::Pat<'hir> {
let qpath = hir::QPath::LangItem(lang_item, span); let qpath = hir::QPath::LangItem(lang_item, self.lower_span(span));
self.pat(span, hir::PatKind::Struct(qpath, fields, false)) self.pat(span, hir::PatKind::Struct(qpath, fields, false))
} }
@ -2600,8 +2627,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
( (
hir::Pat { hir::Pat {
hir_id, hir_id,
kind: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None), kind: hir::PatKind::Binding(bm, hir_id, self.lower_ident(ident), None),
span, span: self.lower_span(span),
default_binding_modes: true, default_binding_modes: true,
}, },
hir_id, hir_id,
@ -2612,13 +2639,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.arena.alloc(hir::Pat { self.arena.alloc(hir::Pat {
hir_id: self.next_id(), hir_id: self.next_id(),
kind, kind,
span, span: self.lower_span(span),
default_binding_modes: true, default_binding_modes: true,
}) })
} }
fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> { fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> {
hir::Pat { hir_id: self.next_id(), kind, span, default_binding_modes: false } hir::Pat {
hir_id: self.next_id(),
kind,
span: self.lower_span(span),
default_binding_modes: false,
}
} }
fn ty_path( fn ty_path(
@ -2635,7 +2667,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let principal = hir::PolyTraitRef { let principal = hir::PolyTraitRef {
bound_generic_params: &[], bound_generic_params: &[],
trait_ref: hir::TraitRef { path, hir_ref_id: hir_id }, trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
span, span: self.lower_span(span),
}; };
// The original ID is taken by the `PolyTraitRef`, // The original ID is taken by the `PolyTraitRef`,
@ -2653,7 +2685,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
_ => hir::TyKind::Path(qpath), _ => hir::TyKind::Path(qpath),
}; };
hir::Ty { hir_id, kind, span } hir::Ty { hir_id, kind, span: self.lower_span(span) }
} }
/// Invoked to create the lifetime argument for a type `&T` /// Invoked to create the lifetime argument for a type `&T`
@ -2668,7 +2700,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let fresh_name = self.collect_fresh_in_band_lifetime(span); let fresh_name = self.collect_fresh_in_band_lifetime(span);
hir::Lifetime { hir::Lifetime {
hir_id: self.next_id(), hir_id: self.next_id(),
span, span: self.lower_span(span),
name: hir::LifetimeName::Param(fresh_name), name: hir::LifetimeName::Param(fresh_name),
} }
} }
@ -2763,7 +2795,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let r = hir::Lifetime { let r = hir::Lifetime {
hir_id: self.next_id(), hir_id: self.next_id(),
span, span: self.lower_span(span),
name: hir::LifetimeName::ImplicitObjectLifetimeDefault, name: hir::LifetimeName::ImplicitObjectLifetimeDefault,
}; };
debug!("elided_dyn_bound: r={:?}", r); debug!("elided_dyn_bound: r={:?}", r);
@ -2771,7 +2803,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime { fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime {
hir::Lifetime { hir_id: self.next_id(), span, name: hir::LifetimeName::Implicit } hir::Lifetime {
hir_id: self.next_id(),
span: self.lower_span(span),
name: hir::LifetimeName::Implicit,
}
} }
fn maybe_lint_bare_trait(&mut self, span: Span, id: NodeId, is_global: bool) { fn maybe_lint_bare_trait(&mut self, span: Span, id: NodeId, is_global: bool) {
@ -2849,12 +2885,13 @@ impl<'hir> GenericArgsCtor<'hir> {
self.args.is_empty() && self.bindings.is_empty() && !self.parenthesized self.args.is_empty() && self.bindings.is_empty() && !self.parenthesized
} }
fn into_generic_args(self, arena: &'hir Arena<'hir>) -> hir::GenericArgs<'hir> { fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
hir::GenericArgs { let ga = hir::GenericArgs {
args: arena.alloc_from_iter(self.args), args: this.arena.alloc_from_iter(self.args),
bindings: self.bindings, bindings: self.bindings,
parenthesized: self.parenthesized, parenthesized: self.parenthesized,
span_ext: self.span, span_ext: this.lower_span(self.span),
} };
this.arena.alloc(ga)
} }
} }

View file

@ -62,10 +62,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::PatField { let fs = self.arena.alloc_from_iter(fields.iter().map(|f| hir::PatField {
hir_id: self.next_id(), hir_id: self.next_id(),
ident: f.ident, ident: self.lower_ident(f.ident),
pat: self.lower_pat(&f.pat), pat: self.lower_pat(&f.pat),
is_shorthand: f.is_shorthand, is_shorthand: f.is_shorthand,
span: f.span, span: self.lower_span(f.span),
})); }));
break hir::PatKind::Struct(qpath, fs, etc); break hir::PatKind::Struct(qpath, fs, etc);
} }
@ -247,16 +247,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::PatKind::Binding( hir::PatKind::Binding(
self.lower_binding_mode(binding_mode), self.lower_binding_mode(binding_mode),
self.lower_node_id(canonical_id), self.lower_node_id(canonical_id),
ident, self.lower_ident(ident),
lower_sub(self), lower_sub(self),
) )
} }
Some(res) => hir::PatKind::Path(hir::QPath::Resolved( Some(res) => hir::PatKind::Path(hir::QPath::Resolved(
None, None,
self.arena.alloc(hir::Path { self.arena.alloc(hir::Path {
span: ident.span, span: self.lower_span(ident.span),
res: self.lower_res(res), res: self.lower_res(res),
segments: arena_vec![self; hir::PathSegment::from_ident(ident)], segments: arena_vec![self; hir::PathSegment::from_ident(self.lower_ident(ident))],
}), }),
)), )),
} }
@ -280,7 +280,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::Pat { hir::Pat {
hir_id: self.lower_node_id(p.id), hir_id: self.lower_node_id(p.id),
kind, kind,
span: p.span, span: self.lower_span(p.span),
default_binding_modes: true, default_binding_modes: true,
} }
} }

View file

@ -110,9 +110,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) )
}, },
)), )),
span: p.segments[..proj_start] span: self.lower_span(
.last() p.segments[..proj_start]
.map_or(path_span_lo, |segment| path_span_lo.to(segment.span())), .last()
.map_or(path_span_lo, |segment| path_span_lo.to(segment.span())),
),
}); });
// Simple case, either no projections, or only fully-qualified. // Simple case, either no projections, or only fully-qualified.
@ -198,7 +200,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
explicit_owner, explicit_owner,
) )
})), })),
span: p.span, span: self.lower_span(p.span),
}) })
} }
@ -370,14 +372,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
); );
hir::PathSegment { hir::PathSegment {
ident: segment.ident, ident: self.lower_ident(segment.ident),
hir_id: Some(id), hir_id: Some(id),
res: Some(self.lower_res(res)), res: Some(self.lower_res(res)),
infer_args, infer_args,
args: if generic_args.is_empty() && generic_args.span.is_empty() { args: if generic_args.is_empty() && generic_args.span.is_empty() {
None None
} else { } else {
Some(self.arena.alloc(generic_args.into_generic_args(self.arena))) Some(generic_args.into_generic_args(self))
}, },
} }
} }
@ -459,6 +461,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
parenthesized: false, parenthesized: false,
span_ext: DUMMY_SP, span_ext: DUMMY_SP,
}); });
hir::TypeBinding { hir_id: self.next_id(), gen_args, span, ident, kind } hir::TypeBinding {
hir_id: self.next_id(),
gen_args,
span: self.lower_span(span),
ident,
kind,
}
} }
} }