fix indentation
This commit is contained in:
parent
68d4b3af12
commit
58fee220a9
@ -34,9 +34,9 @@ fn get_lints(&self) -> LintArray {
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &Context, expr: &Expr) {
|
||||
if !in_macro(cx, expr.span) {
|
||||
check_if(cx, expr)
|
||||
}
|
||||
if !in_macro(cx, expr.span) {
|
||||
check_if(cx, expr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
56
src/utils.rs
56
src/utils.rs
@ -28,34 +28,34 @@ pub fn in_macro(cx: &Context, span: Span) -> bool {
|
||||
/// returns true if the macro that expanded the crate was outside of
|
||||
/// the current crate or was a compiler plugin
|
||||
pub fn in_external_macro(cx: &Context, 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(cx: &Context, opt_info: Option<&ExpnInfo>) -> bool {
|
||||
// no ExpnInfo = no macro
|
||||
opt_info.map_or(false, |info| {
|
||||
match info.callee.format {
|
||||
ExpnFormat::CompilerExpansion(..) => {
|
||||
if info.callee.name() == "closure expansion" {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
ExpnFormat::MacroAttribute(..) => {
|
||||
// these are all plugins
|
||||
return true;
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
// no span for the callee = external macro
|
||||
info.callee.span.map_or(true, |span| {
|
||||
// no snippet = external macro or compiler-builtin expansion
|
||||
cx.sess().codemap().span_to_snippet(span).ok().map_or(true, |code|
|
||||
// macro doesn't start with "macro_rules"
|
||||
// = compiler plugin
|
||||
!code.starts_with("macro_rules")
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
/// 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(cx: &Context, opt_info: Option<&ExpnInfo>) -> bool {
|
||||
// no ExpnInfo = no macro
|
||||
opt_info.map_or(false, |info| {
|
||||
match info.callee.format {
|
||||
ExpnFormat::CompilerExpansion(..) => {
|
||||
if info.callee.name() == "closure expansion" {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
ExpnFormat::MacroAttribute(..) => {
|
||||
// these are all plugins
|
||||
return true;
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
// no span for the callee = external macro
|
||||
info.callee.span.map_or(true, |span| {
|
||||
// no snippet = external macro or compiler-builtin expansion
|
||||
cx.sess().codemap().span_to_snippet(span).ok().map_or(true, |code|
|
||||
// macro doesn't start with "macro_rules"
|
||||
// = compiler plugin
|
||||
!code.starts_with("macro_rules")
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
cx.sess().codemap().with_expn_info(span.expn_id,
|
||||
|info| in_macro_ext(cx, info))
|
||||
|
Loading…
Reference in New Issue
Block a user