Skip to content

Commit

Permalink
Auto merge of #5096 - eddyb:mac-name, r=oli-obk
Browse files Browse the repository at this point in the history
Don't use ExpnKind::descr to get the name of a bang macro.

This is the same change as the first commit in rust-lang/rust#68407, but applied to clippy.
The new code should work both before and after the changes in rust-lang/rust#68407.

changelog: none
  • Loading branch information
bors committed Jan 26, 2020
2 parents fd6f609 + 0e52a0e commit b6a9766
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use rustc_hir::intravisit::{NestedVisitorMap, Visitor};
use rustc_hir::Node;
use rustc_hir::*;
use rustc_lint::{LateContext, Level, Lint, LintContext};
use rustc_span::hygiene::ExpnKind;
use rustc_span::hygiene::{ExpnKind, MacroKind};
use rustc_span::symbol::{self, kw, Symbol};
use rustc_span::{BytePos, Pos, Span, DUMMY_SP};
use smallvec::SmallVec;
Expand Down Expand Up @@ -758,14 +758,15 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
loop {
if span.from_expansion() {
let data = span.ctxt().outer_expn_data();
let mac_name = data.kind.descr();
let new_span = data.call_site;

if mac_name.as_str() == name {
return Some(new_span);
} else {
span = new_span;
if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind {
if mac_name.as_str() == name {
return Some(new_span);
}
}

span = new_span;
} else {
return None;
}
Expand All @@ -785,17 +786,16 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
if span.from_expansion() {
let data = span.ctxt().outer_expn_data();
let mac_name = data.kind.descr();
let new_span = data.call_site;

if mac_name.as_str() == name {
Some(new_span)
} else {
None
if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind {
if mac_name.as_str() == name {
return Some(new_span);
}
}
} else {
None
}

None
}

/// Convenience function to get the return type of a function.
Expand Down

0 comments on commit b6a9766

Please sign in to comment.