mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
moved in_macro to (new) utils.rs
This commit is contained in:
parent
1ee2e4ffe8
commit
30de91d3e9
4 changed files with 15 additions and 12 deletions
|
@ -6,7 +6,7 @@ use syntax::ast::*;
|
|||
use syntax::ptr::P;
|
||||
use syntax::codemap::{Span, ExpnInfo};
|
||||
use syntax::parse::token::InternedString;
|
||||
use mut_mut::in_macro;
|
||||
use utils::in_macro;
|
||||
|
||||
declare_lint! { pub INLINE_ALWAYS, Warn,
|
||||
"#[inline(always)] is usually a bad idea."}
|
||||
|
|
|
@ -19,7 +19,7 @@ use syntax::ast::*;
|
|||
use syntax::ptr::P;
|
||||
use syntax::codemap::{Span, Spanned, ExpnInfo};
|
||||
use syntax::print::pprust::expr_to_string;
|
||||
use mut_mut::in_macro;
|
||||
use utils::in_macro;
|
||||
|
||||
declare_lint! {
|
||||
pub COLLAPSIBLE_IF,
|
||||
|
|
|
@ -3,6 +3,7 @@ use syntax::ast::*;
|
|||
use rustc::lint::{Context, LintPass, LintArray, Lint};
|
||||
use rustc::middle::ty::{expr_ty, sty, ty_ptr, ty_rptr, mt};
|
||||
use syntax::codemap::{BytePos, ExpnInfo, MacroFormat, Span};
|
||||
use utils::in_macro;
|
||||
|
||||
declare_lint!(pub MUT_MUT, Warn,
|
||||
"Warn on usage of double-mut refs, e.g. '&mut &mut ...'");
|
||||
|
@ -51,16 +52,6 @@ fn check_expr_expd(cx: &Context, expr: &Expr, info: Option<&ExpnInfo>) {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn in_macro(cx: &Context, opt_info: Option<&ExpnInfo>) -> bool {
|
||||
opt_info.map_or(false, |info| {
|
||||
info.callee.span.map_or(true, |span| {
|
||||
cx.sess().codemap().span_to_snippet(span).ok().map_or(true, |code|
|
||||
!code.starts_with("macro_rules")
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn unwrap_mut(ty : &Ty) -> Option<&Ty> {
|
||||
match ty.node {
|
||||
TyPtr(MutTy{ ty: ref pty, mutbl: MutMutable }) => Option::Some(pty),
|
||||
|
|
12
src/utils.rs
Normal file
12
src/utils.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use rustc::lint::Context;
|
||||
use syntax::codemap::ExpnInfo;
|
||||
|
||||
fn in_macro(cx: &Context, opt_info: Option<&ExpnInfo>) -> bool {
|
||||
opt_info.map_or(false, |info| {
|
||||
info.callee.span.map_or(true, |span| {
|
||||
cx.sess().codemap().span_to_snippet(span).ok().map_or(true, |code|
|
||||
!code.starts_with("macro_rules")
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue