Delegate utils::in_external_macro to rustc::lint::in_external_macro

This commit is contained in:
Dale Wijnand 2018-07-24 07:49:39 +01:00
parent b02e53de34
commit b1fa7b91ba
No known key found for this signature in database
GPG key ID: 4F256E3D151DF5EF

View file

@ -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.