mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
made macro test even simpler, added a few tests
This commit is contained in:
parent
a67e0f6e2f
commit
0d651c72ff
7 changed files with 27 additions and 6 deletions
|
@ -17,3 +17,5 @@ plugin = true
|
|||
|
||||
[dev-dependencies]
|
||||
compiletest_rs = "*"
|
||||
regex = "*"
|
||||
regex_macros = "*"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#![feature(plugin_registrar, box_syntax)]
|
||||
#![feature(rustc_private, collections)]
|
||||
|
||||
#![allow(unused_imports)]
|
||||
|
||||
#[macro_use]
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
11
tests/run-pass.rs
Normal file
11
tests/run-pass.rs
Normal file
|
@ -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<level>[#]+)\s(?P<title>.+)$");
|
||||
assert!(pattern.is_match("# headline"));
|
||||
}
|
Loading…
Reference in a new issue