Skip to content

Commit a3131ce

Browse files
committed
Mark span parent in def_collector.
1 parent c26af94 commit a3131ce

File tree

5 files changed

+30
-12
lines changed

5 files changed

+30
-12
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::span_bug;
1313
use rustc_middle::ty::TyCtxt;
1414
use rustc_session::errors::report_lit_error;
1515
use rustc_span::source_map::{Spanned, respan};
16-
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
16+
use rustc_span::{DesugaringKind, Ident, Span, Symbol, sym};
1717
use thin_vec::{ThinVec, thin_vec};
1818
use visit::{Visitor, walk_expr};
1919

@@ -207,7 +207,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
207207
MatchKind::Postfix => hir::MatchSource::Postfix,
208208
},
209209
),
210-
ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr),
210+
ExprKind::Await(expr, await_kw_span) => {
211+
self.lower_expr_await(*await_kw_span, e.span, expr)
212+
}
211213
ExprKind::Use(expr, use_kw_span) => self.lower_expr_use(*use_kw_span, expr),
212214
ExprKind::Closure(box Closure {
213215
binder,
@@ -513,7 +515,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
513515
let last_segment = path.segments.last_mut().unwrap();
514516
assert!(last_segment.args.is_none());
515517
last_segment.args = Some(AstP(GenericArgs::AngleBracketed(AngleBracketedArgs {
516-
span: DUMMY_SP,
518+
span: last_segment.span().shrink_to_hi(),
517519
args: generic_args,
518520
})));
519521

@@ -828,20 +830,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
828830
/// }
829831
/// }
830832
/// ```
831-
fn lower_expr_await(&mut self, await_kw_span: Span, expr: &Expr) -> hir::ExprKind<'hir> {
833+
fn lower_expr_await(
834+
&mut self,
835+
await_kw_span: Span,
836+
full_span: Span,
837+
expr: &Expr,
838+
) -> hir::ExprKind<'hir> {
832839
let expr = self.arena.alloc(self.lower_expr_mut(expr));
833-
self.make_lowered_await(await_kw_span, expr, FutureKind::Future)
840+
self.make_lowered_await(await_kw_span, full_span, expr, FutureKind::Future)
834841
}
835842

836843
/// Takes an expr that has already been lowered and generates a desugared await loop around it
837844
fn make_lowered_await(
838845
&mut self,
839846
await_kw_span: Span,
847+
full_span: Span,
840848
expr: &'hir hir::Expr<'hir>,
841849
await_kind: FutureKind,
842850
) -> hir::ExprKind<'hir> {
843-
let full_span = expr.span.to(await_kw_span);
844-
845851
let is_async_gen = match self.coroutine_kind {
846852
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => false,
847853
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
@@ -1820,7 +1826,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
18201826
));
18211827
// `unsafe { ... }`
18221828
let iter = self.arena.alloc(self.expr_unsafe(iter));
1823-
let kind = self.make_lowered_await(head_span, iter, FutureKind::AsyncIterator);
1829+
let kind = self.make_lowered_await(
1830+
head_span,
1831+
head_span,
1832+
iter,
1833+
FutureKind::AsyncIterator,
1834+
);
18241835
self.arena.alloc(hir::Expr { hir_id: self.next_id(), kind, span: head_span })
18251836
}
18261837
};
@@ -2120,6 +2131,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
21202131
}
21212132

21222133
pub(super) fn expr_str(&mut self, sp: Span, value: Symbol) -> hir::Expr<'hir> {
2134+
let sp = self.lower_span(sp);
21232135
let lit = hir::Lit { span: sp, node: ast::LitKind::Str(value, ast::StrStyle::Cooked) };
21242136
self.expr(sp, hir::ExprKind::Lit(lit))
21252137
}

compiler/rustc_ast_lowering/src/item.rs

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

173+
let vis_span = self.lower_span(vis_span);
173174
self.lower_use_tree(use_tree, &prefix, id, vis_span, attrs)
174175
}
175176
ItemKind::Static(box ast::StaticItem {
@@ -621,6 +622,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
621622
} else {
622623
// For non-empty lists we can just drop all the data, the prefix is already
623624
// present in HIR as a part of nested imports.
625+
let span = self.lower_span(span);
624626
self.arena.alloc(hir::UsePath { res: PerNS::default(), segments: &[], span })
625627
};
626628
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
@@ -770,9 +770,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
770770
expected.only_has_type(self),
771771
);
772772
}
773-
if let Some(span) =
774-
tcx.resolutions(()).confused_type_with_std_module.get(&span.with_parent(None))
775-
{
773+
if let Some(span) = tcx.resolutions(()).confused_type_with_std_module.get(&span) {
776774
err.span_suggestion(
777775
span.shrink_to_lo(),
778776
"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
@@ -100,6 +100,12 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
100100
}
101101

102102
impl<'a, 'ra, 'tcx> mut_visit::MutVisitor for DefCollector<'a, 'ra, 'tcx> {
103+
fn visit_span(&mut self, span: &mut Span) {
104+
if self.resolver.tcx.sess.opts.incremental.is_some() {
105+
*span = span.with_parent(Some(self.invocation_parent.parent_def));
106+
}
107+
}
108+
103109
fn visit_item(&mut self, i: &mut Item) {
104110
// Pick the def data. This need not be unique, but the more
105111
// information we encapsulate into, the better

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)