moved in_macro to (new) utils.rs

This commit is contained in:
llogiq 2015-06-01 22:30:34 +02:00
parent 1ee2e4ffe8
commit 30de91d3e9
4 changed files with 15 additions and 12 deletions

View File

@ -6,7 +6,7 @@ use syntax::ast::*;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::codemap::{Span, ExpnInfo}; use syntax::codemap::{Span, ExpnInfo};
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use mut_mut::in_macro; use utils::in_macro;
declare_lint! { pub INLINE_ALWAYS, Warn, declare_lint! { pub INLINE_ALWAYS, Warn,
"#[inline(always)] is usually a bad idea."} "#[inline(always)] is usually a bad idea."}

View File

@ -19,7 +19,7 @@ use syntax::ast::*;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::codemap::{Span, Spanned, ExpnInfo}; use syntax::codemap::{Span, Spanned, ExpnInfo};
use syntax::print::pprust::expr_to_string; use syntax::print::pprust::expr_to_string;
use mut_mut::in_macro; use utils::in_macro;
declare_lint! { declare_lint! {
pub COLLAPSIBLE_IF, pub COLLAPSIBLE_IF,

View File

@ -3,6 +3,7 @@ use syntax::ast::*;
use rustc::lint::{Context, LintPass, LintArray, Lint}; use rustc::lint::{Context, LintPass, LintArray, Lint};
use rustc::middle::ty::{expr_ty, sty, ty_ptr, ty_rptr, mt}; use rustc::middle::ty::{expr_ty, sty, ty_ptr, ty_rptr, mt};
use syntax::codemap::{BytePos, ExpnInfo, MacroFormat, Span}; use syntax::codemap::{BytePos, ExpnInfo, MacroFormat, Span};
use utils::in_macro;
declare_lint!(pub MUT_MUT, Warn, declare_lint!(pub MUT_MUT, Warn,
"Warn on usage of double-mut refs, e.g. '&mut &mut ...'"); "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> { fn unwrap_mut(ty : &Ty) -> Option<&Ty> {
match ty.node { match ty.node {
TyPtr(MutTy{ ty: ref pty, mutbl: MutMutable }) => Option::Some(pty), TyPtr(MutTy{ ty: ref pty, mutbl: MutMutable }) => Option::Some(pty),

12
src/utils.rs Normal file
View 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")
)
})
})
}