Skip to content

Commit

Permalink
Don't use ExpnKind::descr to get the name of a bang macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jan 26, 2020
1 parent 698fcd3 commit 787c458
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/librustc_lint/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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,
Expand Down
21 changes: 14 additions & 7 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
})
}
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_span/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy
Submodule clippy updated 45 files
+1 −0 CHANGELOG.md
+1 −1 README.md
+18 −4 clippy_lints/src/empty_enum.rs
+13 −1 clippy_lints/src/eq_op.rs
+22 −16 clippy_lints/src/formatting.rs
+5 −0 clippy_lints/src/let_underscore.rs
+5 −1 clippy_lints/src/lib.rs
+4 −4 clippy_lints/src/loops.rs
+2 −10 clippy_lints/src/main_recursion.rs
+102 −1 clippy_lints/src/methods/mod.rs
+199 −181 clippy_lints/src/types.rs
+15 −10 clippy_lints/src/unused_io_amount.rs
+2 −0 clippy_lints/src/utils/conf.rs
+24 −14 clippy_lints/src/utils/mod.rs
+8 −0 clippy_lints/src/utils/paths.rs
+8 −1 src/lintlist/mod.rs
+1 −1 tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
+1 −0 tests/ui-toml/vec_box_sized/clippy.toml
+15 −0 tests/ui-toml/vec_box_sized/test.rs
+22 −0 tests/ui-toml/vec_box_sized/test.stderr
+1 −1 tests/ui/empty_enum.stderr
+9 −0 tests/ui/eq_op.rs
+11 −0 tests/ui/formatting.rs
+9 −1 tests/ui/formatting.stderr
+22 −0 tests/ui/issue-3746.rs
+7 −0 tests/ui/let_underscore.rs
+12 −12 tests/ui/let_underscore.stderr
+0 −90 tests/ui/match_same_arms.rs
+26 −132 tests/ui/match_same_arms.stderr
+84 −0 tests/ui/match_same_arms2.rs
+109 −0 tests/ui/match_same_arms2.stderr
+1 −2 tests/ui/missing_const_for_fn/could_be_const.rs
+5 −5 tests/ui/missing_const_for_fn/could_be_const.stderr
+2 −85 tests/ui/needless_range_loop.rs
+16 −104 tests/ui/needless_range_loop.stderr
+85 −0 tests/ui/needless_range_loop2.rs
+91 −0 tests/ui/needless_range_loop2.stderr
+38 −0 tests/ui/option_as_ref_deref.fixed
+41 −0 tests/ui/option_as_ref_deref.rs
+92 −0 tests/ui/option_as_ref_deref.stderr
+6 −0 tests/ui/unused_io_amount.rs
+17 −5 tests/ui/unused_io_amount.stderr
+3 −1 tests/ui/vec_box_sized.fixed
+3 −1 tests/ui/vec_box_sized.rs
+3 −3 tests/ui/vec_box_sized.stderr

0 comments on commit 787c458

Please sign in to comment.