1
Fork 0

Use absolute spans when trying to steal an AST diagnostic.

This commit is contained in:
Camille GILLOT 2021-04-30 23:57:02 +02:00
parent 44972b2ce7
commit 66e0316414
5 changed files with 11 additions and 7 deletions

View file

@ -653,17 +653,19 @@ impl Handler {
/// Retrieve a stashed diagnostic with `steal_diagnostic`. /// Retrieve a stashed diagnostic with `steal_diagnostic`.
pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) { pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) {
let mut inner = self.inner.borrow_mut(); let mut inner = self.inner.borrow_mut();
inner.stash((span, key), diag); inner.stash((span.with_parent(None), key), diag);
} }
/// Steal a previously stashed diagnostic with the given `Span` and [`StashKey`] as the key. /// Steal a previously stashed diagnostic with the given `Span` and [`StashKey`] as the key.
pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<DiagnosticBuilder<'_, ()>> { pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option<DiagnosticBuilder<'_, ()>> {
let mut inner = self.inner.borrow_mut(); let mut inner = self.inner.borrow_mut();
inner.steal((span, key)).map(|diag| DiagnosticBuilder::new_diagnostic(self, diag)) inner
.steal((span.with_parent(None), key))
.map(|diag| DiagnosticBuilder::new_diagnostic(self, diag))
} }
pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool { pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool {
self.inner.borrow().stashed_diagnostics.get(&(span, key)).is_some() self.inner.borrow().stashed_diagnostics.get(&(span.with_parent(None), key)).is_some()
} }
/// Emit all stashed diagnostics. /// Emit all stashed diagnostics.

View file

@ -395,7 +395,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
E0614, E0614,
"type `{oprnd_t}` cannot be dereferenced", "type `{oprnd_t}` cannot be dereferenced",
); );
let sp = tcx.sess.source_map().start_point(expr.span); let sp = tcx.sess.source_map().start_point(expr.span).with_parent(None);
if let Some(sp) = if let Some(sp) =
tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp)
{ {

View file

@ -973,7 +973,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err: &mut Diagnostic, err: &mut Diagnostic,
expr: &hir::Expr<'_>, expr: &hir::Expr<'_>,
) -> bool { ) -> bool {
let sp = self.tcx.sess.source_map().start_point(expr.span); let sp = self.tcx.sess.source_map().start_point(expr.span).with_parent(None);
if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) { if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) {
// `{ 42 } &&x` (#61475) or `{ 42 } && if x { 1 } else { 0 }` // `{ 42 } &&x` (#61475) or `{ 42 } && if x { 1 } else { 0 }`
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp)); err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));

View file

@ -339,7 +339,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&mut err, item_name, rcvr_ty, cal, span, &mut err, item_name, rcvr_ty, cal, span,
); );
} }
if let Some(span) = tcx.resolutions(()).confused_type_with_std_module.get(&span) { if let Some(span) =
tcx.resolutions(()).confused_type_with_std_module.get(&span.with_parent(None))
{
err.span_suggestion( err.span_suggestion(
span.shrink_to_lo(), span.shrink_to_lo(),
"you are looking for the module in `std`, not the primitive type", "you are looking for the module in `std`, not the primitive type",

View file

@ -660,7 +660,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} }
} }
let sp = self.tcx.sess.source_map().start_point(ex.span); let sp = self.tcx.sess.source_map().start_point(ex.span).with_parent(None);
if let Some(sp) = if let Some(sp) =
self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp)
{ {