mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Delegate utils::in_external_macro to rustc::lint::in_external_macro
This commit is contained in:
parent
b02e53de34
commit
b1fa7b91ba
1 changed files with 3 additions and 27 deletions
|
@ -19,7 +19,7 @@ use std::str::FromStr;
|
|||
use std::rc::Rc;
|
||||
use syntax::ast::{self, LitKind};
|
||||
use syntax::attr;
|
||||
use syntax::codemap::{CompilerDesugaringKind, ExpnFormat, ExpnInfo, Span, DUMMY_SP};
|
||||
use syntax::codemap::{CompilerDesugaringKind, ExpnFormat, Span, DUMMY_SP};
|
||||
use syntax::errors::DiagnosticBuilder;
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::keywords;
|
||||
|
@ -78,33 +78,9 @@ pub fn is_range_expression(span: Span) -> bool {
|
|||
}
|
||||
|
||||
/// Returns true if the macro that expanded the crate was outside of the
|
||||
/// current crate or was a
|
||||
/// compiler plugin.
|
||||
/// current crate or was a compiler plugin.
|
||||
pub fn in_external_macro<'a, T: LintContext<'a>>(cx: &T, span: Span) -> bool {
|
||||
/// Invokes `in_macro` with the expansion info of the given span slightly
|
||||
/// heavy, try to use
|
||||
/// this after other checks have already happened.
|
||||
fn in_macro_ext<'a, T: LintContext<'a>>(cx: &T, info: &ExpnInfo) -> bool {
|
||||
// no ExpnInfo = no macro
|
||||
if let ExpnFormat::MacroAttribute(..) = info.format {
|
||||
// these are all plugins
|
||||
return true;
|
||||
}
|
||||
// no span for the callee = external macro
|
||||
info.def_site.map_or(true, |span| {
|
||||
// no snippet = external macro or compiler-builtin expansion
|
||||
cx.sess()
|
||||
.codemap()
|
||||
.span_to_snippet(span)
|
||||
.ok()
|
||||
.map_or(true, |code| !code.starts_with("macro_rules"))
|
||||
})
|
||||
}
|
||||
|
||||
span.ctxt()
|
||||
.outer()
|
||||
.expn_info()
|
||||
.map_or(false, |info| in_macro_ext(cx, &info))
|
||||
::rustc::lint::in_external_macro(cx.sess(), span)
|
||||
}
|
||||
|
||||
/// Check if a `DefId`'s path matches the given absolute type path usage.
|
||||
|
|
Loading…
Reference in a new issue