diff --git a/Cargo.toml b/Cargo.toml index 95de98e8ee5..3c7d9be64e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,5 @@ plugin = true [dev-dependencies] compiletest_rs = "*" +regex = "*" +regex_macros = "*" diff --git a/src/lib.rs b/src/lib.rs index cf5def800a2..92cc7ef254c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ #![feature(plugin_registrar, box_syntax)] #![feature(rustc_private, collections)] - #![allow(unused_imports)] #[macro_use] diff --git a/src/mut_mut.rs b/src/mut_mut.rs index b1e21def574..160b99a1d15 100644 --- a/src/mut_mut.rs +++ b/src/mut_mut.rs @@ -27,7 +27,7 @@ impl LintPass for MutMut { } fn check_expr_expd(cx: &Context, expr: &Expr, info: Option<&ExpnInfo>) { - if in_external_macro(info) { return; } + if in_macro(info) { return; } fn unwrap_addr(expr : &Expr) -> Option<&Expr> { match expr.node { @@ -51,8 +51,8 @@ fn check_expr_expd(cx: &Context, expr: &Expr, info: Option<&ExpnInfo>) { }) } -fn in_external_macro(info: Option<&ExpnInfo>) -> bool { - info.map_or(false, |i| i.callee.span.is_some()) +fn in_macro(info: Option<&ExpnInfo>) -> bool { + info.is_some() } fn unwrap_mut(ty : &Ty) -> Option<&Ty> { diff --git a/src/ptr_arg.rs b/src/ptr_arg.rs index 86b87a942be..64c3c84c7b6 100644 --- a/src/ptr_arg.rs +++ b/src/ptr_arg.rs @@ -27,7 +27,7 @@ impl LintPass for PtrArg { } fn check_item(&mut self, cx: &Context, item: &Item) { - if let &ItemFn(ref decl, _, _, _, _) = &item.node { + if let &ItemFn(ref decl, _, _, _, _, _) = &item.node { check_fn(cx, decl); } } diff --git a/tests/compile-fail/mut_mut.rs b/tests/compile-fail/mut_mut.rs index 65e3762e2c4..d7adc067740 100644 --- a/tests/compile-fail/mut_mut.rs +++ b/tests/compile-fail/mut_mut.rs @@ -1,11 +1,18 @@ #![feature(plugin)] #![plugin(clippy)] +//#![plugin(regex_macros)] +//extern crate regex; + #[deny(mut_mut)] fn fun(x : &mut &mut u32) -> bool { //~ERROR **x > 0 } +macro_rules! mut_ptr { + ($p:expr) => { &mut $p } +} + #[deny(mut_mut)] #[allow(unused_mut, unused_variables)] fn main() { @@ -22,4 +29,6 @@ fn main() { //~^^^^ ERROR ***y + **x; } + + let mut z = mut_ptr!(&mut 3u32); //~ERROR } diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 04f3fc16b1b..6fcf71d38ad 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; fn run_mode(mode: &'static str) { let mut config = compiletest::default_config(); let cfg_mode = mode.parse().ok().expect("Invalid mode"); - config.target_rustcflags = Some("-L target/debug/".to_string()); + config.target_rustcflags = Some("-l regex_macros -L target/debug/".to_string()); config.mode = cfg_mode; config.src_base = PathBuf::from(format!("tests/{}", mode)); diff --git a/tests/run-pass.rs b/tests/run-pass.rs new file mode 100644 index 00000000000..bc39278606c --- /dev/null +++ b/tests/run-pass.rs @@ -0,0 +1,11 @@ +#![feature(plugin)] +#![plugin(clippy, regex_macros)] + +extern crate regex; + +#[test] +#[deny(mut_mut)] +fn test_regex() { + let pattern = regex!(r"^(?P[#]+)\s(?P.+)$"); + assert!(pattern.is_match("# headline")); +}