Don't use ExpnKind::descr to get the name of a bang macro.
This commit is contained in:
parent
698fcd38fa
commit
787c458eeb
@ -6,6 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use syntax::ast::{Ident, Item, ItemKind};
|
||||
|
||||
@ -226,8 +227,9 @@ impl EarlyLintPass for LintPassImpl {
|
||||
if last.ident.name == sym::LintPass {
|
||||
let expn_data = lint_pass.path.span.ctxt().outer_expn_data();
|
||||
let call_site = expn_data.call_site;
|
||||
if expn_data.kind.descr() != sym::impl_lint_pass
|
||||
&& call_site.ctxt().outer_expn_data().kind.descr() != sym::declare_lint_pass
|
||||
if expn_data.kind != ExpnKind::Macro(MacroKind::Bang, sym::impl_lint_pass)
|
||||
&& call_site.ctxt().outer_expn_data().kind
|
||||
!= ExpnKind::Macro(MacroKind::Bang, sym::declare_lint_pass)
|
||||
{
|
||||
cx.struct_span_lint(
|
||||
LINT_PASS_IMPL_WITHOUT_MACRO,
|
||||
|
@ -776,12 +776,19 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
let callsite_span = self.span_from_span(callsite);
|
||||
let callee = span.source_callee()?;
|
||||
|
||||
// Ignore attribute macros, their spans are usually mangled
|
||||
if let ExpnKind::Macro(MacroKind::Attr, _) | ExpnKind::Macro(MacroKind::Derive, _) =
|
||||
callee.kind
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let mac_name = match callee.kind {
|
||||
ExpnKind::Macro(mac_kind, name) => match mac_kind {
|
||||
MacroKind::Bang => name,
|
||||
|
||||
// Ignore attribute macros, their spans are usually mangled
|
||||
// FIXME(eddyb) is this really the case anymore?
|
||||
MacroKind::Attr | MacroKind::Derive => return None,
|
||||
},
|
||||
|
||||
// These are not macros.
|
||||
// FIXME(eddyb) maybe there is a way to handle them usefully?
|
||||
ExpnKind::Root | ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => return None,
|
||||
};
|
||||
|
||||
// If the callee is an imported macro from an external crate, need to get
|
||||
// the source span and name from the session, as their spans are localized
|
||||
@ -799,7 +806,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||
let callee_span = self.span_from_span(callee.def_site);
|
||||
Some(MacroRef {
|
||||
span: callsite_span,
|
||||
qualname: callee.kind.descr().to_string(), // FIXME: generate the real qualname
|
||||
qualname: mac_name.to_string(), // FIXME: generate the real qualname
|
||||
callee_span,
|
||||
})
|
||||
}
|
||||
|
@ -140,7 +140,9 @@ impl ExpnId {
|
||||
loop {
|
||||
let expn_data = self.expn_data();
|
||||
// Stop going up the backtrace once include! is encountered
|
||||
if expn_data.is_root() || expn_data.kind.descr() == sym::include {
|
||||
if expn_data.is_root()
|
||||
|| expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include)
|
||||
{
|
||||
break;
|
||||
}
|
||||
self = expn_data.call_site.ctxt().outer_expn();
|
||||
@ -717,7 +719,7 @@ impl ExpnData {
|
||||
}
|
||||
|
||||
/// Expansion kind.
|
||||
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)]
|
||||
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)]
|
||||
pub enum ExpnKind {
|
||||
/// No expansion, aka root expansion. Only `ExpnId::root()` has this kind.
|
||||
Root,
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 3e74853d1f9893cf2a47f28b658711d8f9f97b6b
|
||||
Subproject commit fa046d2e7f14cda09d14230cc8c772e1565e0757
|
Loading…
Reference in New Issue
Block a user