Skip to content

Commit 461d798

Browse files
committed
stashing: tweak ExpnData based on eddyb's feedback.
1 parent 1ee095f commit 461d798

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

src/librustc/lint.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
342342
let expn_data = span.ctxt().outer_expn_data();
343343
match expn_data.kind {
344344
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
345-
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
345+
// well, it's "external"
346+
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) | ExpnKind::ParserRecovery => true,
346347
ExpnKind::Macro(MacroKind::Bang, _) => {
347348
if expn_data.def_site.is_dummy() {
348349
// Dummy span for the `def_site` means it's an external macro.

src/librustc_errors/diagnostic_builder.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{Applicability, Handler, Level, StashKey};
22
use crate::{Diagnostic, DiagnosticId, DiagnosticStyledString};
33

44
use log::debug;
5-
use rustc_span::{MultiSpan, Span};
5+
use rustc_span::{ExpnData, ExpnKind, MultiSpan, Span};
66
use std::fmt::{self, Debug};
77
use std::ops::{Deref, DerefMut};
88
use std::thread::panicking;
@@ -133,7 +133,8 @@ impl<'a> DiagnosticBuilder<'a> {
133133
// suite! { len; is_empty; }
134134
// ```
135135
// ...would result in overwriting due to using the same `def_site` span for `A`.
136-
let span = span.fresh_expansion(span.ctxt().outer_expn_data());
136+
let data = ExpnData::default(ExpnKind::ParserRecovery, span, span.edition());
137+
let span = span.fresh_expansion(data);
137138
handler.stash_diagnostic(span, key, diag);
138139
span
139140
})

src/librustc_errors/emitter.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ pub trait Emitter {
293293

294294
// Skip past non-macro entries, just in case there
295295
// are some which do actually involve macros.
296-
ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
296+
ExpnKind::Desugaring(..)
297+
| ExpnKind::AstPass(..)
298+
| ExpnKind::ParserRecovery => None,
297299

298300
ExpnKind::Macro(macro_kind, _) => Some(macro_kind),
299301
}

src/librustc_save_analysis/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,10 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
789789

790790
// These are not macros.
791791
// FIXME(eddyb) maybe there is a way to handle them usefully?
792-
ExpnKind::Root | ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => return None,
792+
ExpnKind::Root
793+
| ExpnKind::AstPass(_)
794+
| ExpnKind::Desugaring(_)
795+
| ExpnKind::ParserRecovery => return None,
793796
};
794797

795798
// If the callee is an imported macro from an external crate, need to get

src/librustc_span/hygiene.rs

+3
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ pub enum ExpnKind {
729729
AstPass(AstPass),
730730
/// Desugaring done by the compiler during HIR lowering.
731731
Desugaring(DesugaringKind),
732+
/// AST fragements produced by parser recovery.
733+
ParserRecovery,
732734
}
733735

734736
impl ExpnKind {
@@ -742,6 +744,7 @@ impl ExpnKind {
742744
},
743745
ExpnKind::AstPass(kind) => kind.descr().to_string(),
744746
ExpnKind::Desugaring(kind) => format!("desugaring of {}", kind.descr()),
747+
ExpnKind::ParserRecovery => "parser recovery".to_string(),
745748
}
746749
}
747750
}

0 commit comments

Comments
 (0)