Skip to content

Commit 787c458

Browse files
committed
Don't use ExpnKind::descr to get the name of a bang macro.
1 parent 698fcd3 commit 787c458

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/librustc_lint/internal.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_data_structures::fx::FxHashMap;
66
use rustc_errors::Applicability;
77
use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind};
88
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
9+
use rustc_span::hygiene::{ExpnKind, MacroKind};
910
use rustc_span::symbol::{sym, Symbol};
1011
use syntax::ast::{Ident, Item, ItemKind};
1112

@@ -226,8 +227,9 @@ impl EarlyLintPass for LintPassImpl {
226227
if last.ident.name == sym::LintPass {
227228
let expn_data = lint_pass.path.span.ctxt().outer_expn_data();
228229
let call_site = expn_data.call_site;
229-
if expn_data.kind.descr() != sym::impl_lint_pass
230-
&& call_site.ctxt().outer_expn_data().kind.descr() != sym::declare_lint_pass
230+
if expn_data.kind != ExpnKind::Macro(MacroKind::Bang, sym::impl_lint_pass)
231+
&& call_site.ctxt().outer_expn_data().kind
232+
!= ExpnKind::Macro(MacroKind::Bang, sym::declare_lint_pass)
231233
{
232234
cx.struct_span_lint(
233235
LINT_PASS_IMPL_WITHOUT_MACRO,

src/librustc_save_analysis/lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,19 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
776776
let callsite_span = self.span_from_span(callsite);
777777
let callee = span.source_callee()?;
778778

779-
// Ignore attribute macros, their spans are usually mangled
780-
if let ExpnKind::Macro(MacroKind::Attr, _) | ExpnKind::Macro(MacroKind::Derive, _) =
781-
callee.kind
782-
{
783-
return None;
784-
}
779+
let mac_name = match callee.kind {
780+
ExpnKind::Macro(mac_kind, name) => match mac_kind {
781+
MacroKind::Bang => name,
782+
783+
// Ignore attribute macros, their spans are usually mangled
784+
// FIXME(eddyb) is this really the case anymore?
785+
MacroKind::Attr | MacroKind::Derive => return None,
786+
},
787+
788+
// These are not macros.
789+
// FIXME(eddyb) maybe there is a way to handle them usefully?
790+
ExpnKind::Root | ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => return None,
791+
};
785792

786793
// If the callee is an imported macro from an external crate, need to get
787794
// the source span and name from the session, as their spans are localized
@@ -799,7 +806,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
799806
let callee_span = self.span_from_span(callee.def_site);
800807
Some(MacroRef {
801808
span: callsite_span,
802-
qualname: callee.kind.descr().to_string(), // FIXME: generate the real qualname
809+
qualname: mac_name.to_string(), // FIXME: generate the real qualname
803810
callee_span,
804811
})
805812
}

src/librustc_span/hygiene.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ impl ExpnId {
140140
loop {
141141
let expn_data = self.expn_data();
142142
// Stop going up the backtrace once include! is encountered
143-
if expn_data.is_root() || expn_data.kind.descr() == sym::include {
143+
if expn_data.is_root()
144+
|| expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include)
145+
{
144146
break;
145147
}
146148
self = expn_data.call_site.ctxt().outer_expn();
@@ -717,7 +719,7 @@ impl ExpnData {
717719
}
718720

719721
/// Expansion kind.
720-
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable_Generic)]
722+
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable, HashStable_Generic)]
721723
pub enum ExpnKind {
722724
/// No expansion, aka root expansion. Only `ExpnId::root()` has this kind.
723725
Root,

src/tools/clippy

Submodule clippy updated 45 files

0 commit comments

Comments
 (0)