Skip to content

Commit 66e0316

Browse files
committed
Use absolute spans when trying to steal an AST diagnostic.
1 parent 44972b2 commit 66e0316

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,17 +653,19 @@ impl Handler {
653653
/// Retrieve a stashed diagnostic with `steal_diagnostic`.
654654
pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) {
655655
let mut inner = self.inner.borrow_mut();
656-
inner.stash((span, key), diag);
656+
inner.stash((span.with_parent(None), key), diag);
657657
}
658658

659659
/// Steal a previously stashed diagnostic with the given `Span` and [`StashKey`] as the key.
660660
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<DiagnosticBuilder<'_, ()>> {
661661
let mut inner = self.inner.borrow_mut();
662-
inner.steal((span, key)).map(|diag| DiagnosticBuilder::new_diagnostic(self, diag))
662+
inner
663+
.steal((span.with_parent(None), key))
664+
.map(|diag| DiagnosticBuilder::new_diagnostic(self, diag))
663665
}
664666

665667
pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool {
666-
self.inner.borrow().stashed_diagnostics.get(&(span, key)).is_some()
668+
self.inner.borrow().stashed_diagnostics.get(&(span.with_parent(None), key)).is_some()
667669
}
668670

669671
/// Emit all stashed diagnostics.

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
395395
E0614,
396396
"type `{oprnd_t}` cannot be dereferenced",
397397
);
398-
let sp = tcx.sess.source_map().start_point(expr.span);
398+
let sp = tcx.sess.source_map().start_point(expr.span).with_parent(None);
399399
if let Some(sp) =
400400
tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp)
401401
{

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
973973
err: &mut Diagnostic,
974974
expr: &hir::Expr<'_>,
975975
) -> bool {
976-
let sp = self.tcx.sess.source_map().start_point(expr.span);
976+
let sp = self.tcx.sess.source_map().start_point(expr.span).with_parent(None);
977977
if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) {
978978
// `{ 42 } &&x` (#61475) or `{ 42 } && if x { 1 } else { 0 }`
979979
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
339339
&mut err, item_name, rcvr_ty, cal, span,
340340
);
341341
}
342-
if let Some(span) = tcx.resolutions(()).confused_type_with_std_module.get(&span) {
342+
if let Some(span) =
343+
tcx.resolutions(()).confused_type_with_std_module.get(&span.with_parent(None))
344+
{
343345
err.span_suggestion(
344346
span.shrink_to_lo(),
345347
"you are looking for the module in `std`, not the primitive type",

compiler/rustc_hir_typeck/src/op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
660660
}
661661
}
662662

663-
let sp = self.tcx.sess.source_map().start_point(ex.span);
663+
let sp = self.tcx.sess.source_map().start_point(ex.span).with_parent(None);
664664
if let Some(sp) =
665665
self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp)
666666
{

0 commit comments

Comments
 (0)