Skip to content

Commit

Permalink
stashing: tweak ExpnData based on eddyb's feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Feb 28, 2020
1 parent 1ee095f commit 461d798
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/librustc/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
let expn_data = span.ctxt().outer_expn_data();
match expn_data.kind {
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
// well, it's "external"
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) | ExpnKind::ParserRecovery => true,
ExpnKind::Macro(MacroKind::Bang, _) => {
if expn_data.def_site.is_dummy() {
// Dummy span for the `def_site` means it's an external macro.
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{Applicability, Handler, Level, StashKey};
use crate::{Diagnostic, DiagnosticId, DiagnosticStyledString};

use log::debug;
use rustc_span::{MultiSpan, Span};
use rustc_span::{ExpnData, ExpnKind, MultiSpan, Span};
use std::fmt::{self, Debug};
use std::ops::{Deref, DerefMut};
use std::thread::panicking;
Expand Down Expand Up @@ -133,7 +133,8 @@ impl<'a> DiagnosticBuilder<'a> {
// suite! { len; is_empty; }
// ```
// ...would result in overwriting due to using the same `def_site` span for `A`.
let span = span.fresh_expansion(span.ctxt().outer_expn_data());
let data = ExpnData::default(ExpnKind::ParserRecovery, span, span.edition());
let span = span.fresh_expansion(data);
handler.stash_diagnostic(span, key, diag);
span
})
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ pub trait Emitter {

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

ExpnKind::Macro(macro_kind, _) => Some(macro_kind),
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,10 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {

// These are not macros.
// FIXME(eddyb) maybe there is a way to handle them usefully?
ExpnKind::Root | ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => return None,
ExpnKind::Root
| ExpnKind::AstPass(_)
| ExpnKind::Desugaring(_)
| ExpnKind::ParserRecovery => return None,
};

// If the callee is an imported macro from an external crate, need to get
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_span/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ pub enum ExpnKind {
AstPass(AstPass),
/// Desugaring done by the compiler during HIR lowering.
Desugaring(DesugaringKind),
/// AST fragements produced by parser recovery.
ParserRecovery,
}

impl ExpnKind {
Expand All @@ -742,6 +744,7 @@ impl ExpnKind {
},
ExpnKind::AstPass(kind) => kind.descr().to_string(),
ExpnKind::Desugaring(kind) => format!("desugaring of {}", kind.descr()),
ExpnKind::ParserRecovery => "parser recovery".to_string(),
}
}
}
Expand Down

0 comments on commit 461d798

Please sign in to comment.