Skip to content

Commit 709d052

Browse files
committed
Mark span parent in def_collector.
1 parent c6c5243 commit 709d052

File tree

5 files changed

+35
-15
lines changed

5 files changed

+35
-15
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::span_bug;
1010
use rustc_session::errors::report_lit_error;
1111
use rustc_span::source_map::{Spanned, respan};
1212
use rustc_span::symbol::{Ident, Symbol, kw, sym};
13-
use rustc_span::{DUMMY_SP, DesugaringKind, Span};
13+
use rustc_span::{DesugaringKind, Span};
1414
use thin_vec::{ThinVec, thin_vec};
1515

1616
use super::errors::{
@@ -196,7 +196,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
196196
MatchKind::Postfix => hir::MatchSource::Postfix,
197197
},
198198
),
199-
ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr),
199+
ExprKind::Await(expr, await_kw_span) => {
200+
self.lower_expr_await(*await_kw_span, e.span, expr)
201+
}
200202
ExprKind::Closure(box Closure {
201203
binder,
202204
capture_clause,
@@ -262,9 +264,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
262264
ExprKind::Field(el, ident) => {
263265
hir::ExprKind::Field(self.lower_expr(el), self.lower_ident(*ident))
264266
}
265-
ExprKind::Index(el, er, brackets_span) => {
266-
hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er), *brackets_span)
267-
}
267+
ExprKind::Index(el, er, brackets_span) => hir::ExprKind::Index(
268+
self.lower_expr(el),
269+
self.lower_expr(er),
270+
self.lower_span(*brackets_span),
271+
),
268272
ExprKind::Range(Some(e1), Some(e2), RangeLimits::Closed) => {
269273
self.lower_expr_range_closed(e.span, e1, e2)
270274
}
@@ -405,7 +409,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
405409
let last_segment = path.segments.last_mut().unwrap();
406410
assert!(last_segment.args.is_none());
407411
last_segment.args = Some(AstP(GenericArgs::AngleBracketed(AngleBracketedArgs {
408-
span: DUMMY_SP,
412+
span: last_segment.span().shrink_to_hi(),
409413
args: generic_args,
410414
})));
411415

@@ -753,20 +757,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
753757
/// }
754758
/// }
755759
/// ```
756-
fn lower_expr_await(&mut self, await_kw_span: Span, expr: &Expr) -> hir::ExprKind<'hir> {
760+
fn lower_expr_await(
761+
&mut self,
762+
await_kw_span: Span,
763+
full_span: Span,
764+
expr: &Expr,
765+
) -> hir::ExprKind<'hir> {
757766
let expr = self.arena.alloc(self.lower_expr_mut(expr));
758-
self.make_lowered_await(await_kw_span, expr, FutureKind::Future)
767+
self.make_lowered_await(await_kw_span, full_span, expr, FutureKind::Future)
759768
}
760769

761770
/// Takes an expr that has already been lowered and generates a desugared await loop around it
762771
fn make_lowered_await(
763772
&mut self,
764773
await_kw_span: Span,
774+
full_span: Span,
765775
expr: &'hir hir::Expr<'hir>,
766776
await_kind: FutureKind,
767777
) -> hir::ExprKind<'hir> {
768-
let full_span = expr.span.to(await_kw_span);
769-
770778
let is_async_gen = match self.coroutine_kind {
771779
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => false,
772780
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
@@ -1706,7 +1714,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
17061714
));
17071715
// `unsafe { ... }`
17081716
let iter = self.arena.alloc(self.expr_unsafe(iter));
1709-
let kind = self.make_lowered_await(head_span, iter, FutureKind::AsyncIterator);
1717+
let kind = self.make_lowered_await(
1718+
head_span,
1719+
head_span,
1720+
iter,
1721+
FutureKind::AsyncIterator,
1722+
);
17101723
self.arena.alloc(hir::Expr { hir_id: self.next_id(), kind, span: head_span })
17111724
}
17121725
};
@@ -2012,6 +2025,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
20122025
}
20132026

20142027
pub(super) fn expr_str(&mut self, sp: Span, value: Symbol) -> hir::Expr<'hir> {
2028+
let sp = self.lower_span(sp);
20152029
let lit = self
20162030
.arena
20172031
.alloc(hir::Lit { span: sp, node: ast::LitKind::Str(value, ast::StrStyle::Cooked) });

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
183183
// Start with an empty prefix.
184184
let prefix = Path { segments: ThinVec::new(), span: use_tree.span, tokens: None };
185185

186+
let vis_span = self.lower_span(vis_span);
186187
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
187188
}
188189
ItemKind::Static(box ast::StaticItem { ty: t, safety: _, mutability: m, expr: e }) => {
@@ -570,6 +571,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
570571
} else {
571572
// For non-empty lists we can just drop all the data, the prefix is already
572573
// present in HIR as a part of nested imports.
574+
let span = self.lower_span(span);
573575
self.arena.alloc(hir::UsePath { res: smallvec![], segments: &[], span })
574576
};
575577
hir::ItemKind::Use(path, hir::UseKind::ListStem)

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
776776
expected.only_has_type(self),
777777
);
778778
}
779-
if let Some(span) =
780-
tcx.resolutions(()).confused_type_with_std_module.get(&span.with_parent(None))
781-
{
779+
if let Some(span) = tcx.resolutions(()).confused_type_with_std_module.get(&span) {
782780
err.span_suggestion(
783781
span.shrink_to_lo(),
784782
"you are looking for the module in `std`, not the primitive type",

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
183183
}
184184

185185
impl<'a, 'ra, 'tcx> mut_visit::MutVisitor for DefCollector<'a, 'ra, 'tcx> {
186+
fn visit_span(&mut self, span: &mut Span) {
187+
if self.resolver.tcx.sess.opts.incremental.is_some() {
188+
*span = span.with_parent(Some(self.parent_def));
189+
}
190+
}
191+
186192
#[tracing::instrument(level = "trace", skip(self))]
187193
fn flat_map_item(&mut self, mut i: P<Item>) -> SmallVec<[P<Item>; 1]> {
188194
// Pick the def data. This need not be unique, but the more

tests/incremental/hashes/function_interfaces.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub fn change_return_impl_trait() -> impl Clone {
320320
#[cfg(not(any(cfail1,cfail4)))]
321321
#[rustc_clean(cfg = "cfail2", except = "opt_hir_owner_nodes")]
322322
#[rustc_clean(cfg = "cfail3")]
323-
#[rustc_clean(cfg = "cfail5", except = "opt_hir_owner_nodes, typeck")]
323+
#[rustc_clean(cfg = "cfail5", except = "opt_hir_owner_nodes")]
324324
#[rustc_clean(cfg = "cfail6")]
325325
pub fn change_return_impl_trait() -> impl Copy {
326326
0u32

0 commit comments

Comments
 (0)