From b6326121abd129a3d52b5b9cef7980c4a1b22663 Mon Sep 17 00:00:00 2001 From: mcarton Date: Sun, 14 May 2017 14:58:16 +0200 Subject: [PATCH] Fix span in `blacklisted_name` --- clippy_lints/src/blacklisted_name.rs | 2 +- tests/ui/blacklisted_name.rs | 19 ++++- tests/ui/blacklisted_name.stderr | 78 +++++++++++++++----- tests/ui/conf_french_blacklisted_name.stderr | 2 +- 4 files changed, 78 insertions(+), 23 deletions(-) diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index 3713aa0a2..f8f0ea998 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName { if self.blacklist.iter().any(|s| ident.node == *s) { span_lint(cx, BLACKLISTED_NAME, - pat.span, + ident.span, &format!("use of a blacklisted/placeholder name `{}`", ident.node)); } } diff --git a/tests/ui/blacklisted_name.rs b/tests/ui/blacklisted_name.rs index c1abbf1bb..94c175713 100644 --- a/tests/ui/blacklisted_name.rs +++ b/tests/ui/blacklisted_name.rs @@ -1,9 +1,7 @@ #![feature(plugin)] #![plugin(clippy)] -#![allow(dead_code)] -#![allow(single_match)] -#![allow(unused_variables, similar_names)] +#![allow(dead_code, similar_names, single_match, toplevel_ref_arg, unused_mut, unused_variables)] #![deny(blacklisted_name)] fn test(foo: ()) {} @@ -21,3 +19,18 @@ fn main() { _ => (), } } + +fn issue_1647(mut foo: u8) { + let mut bar = 0; + if let Some(mut baz) = Some(42) {} +} + +fn issue_1647_ref() { + let ref bar = 0; + if let Some(ref baz) = Some(42) {} +} + +fn issue_1647_ref_mut() { + let ref mut bar = 0; + if let Some(ref mut baz) = Some(42) {} +} diff --git a/tests/ui/blacklisted_name.stderr b/tests/ui/blacklisted_name.stderr index 29e9da227..93405f992 100644 --- a/tests/ui/blacklisted_name.stderr +++ b/tests/ui/blacklisted_name.stderr @@ -1,50 +1,92 @@ error: use of a blacklisted/placeholder name `foo` - --> $DIR/blacklisted_name.rs:9:9 + --> $DIR/blacklisted_name.rs:7:9 | -9 | fn test(foo: ()) {} +7 | fn test(foo: ()) {} | ^^^ | note: lint level defined here - --> $DIR/blacklisted_name.rs:7:9 + --> $DIR/blacklisted_name.rs:5:9 | -7 | #![deny(blacklisted_name)] +5 | #![deny(blacklisted_name)] | ^^^^^^^^^^^^^^^^ error: use of a blacklisted/placeholder name `foo` - --> $DIR/blacklisted_name.rs:12:9 + --> $DIR/blacklisted_name.rs:10:9 | -12 | let foo = 42; +10 | let foo = 42; | ^^^ error: use of a blacklisted/placeholder name `bar` - --> $DIR/blacklisted_name.rs:13:9 + --> $DIR/blacklisted_name.rs:11:9 | -13 | let bar = 42; +11 | let bar = 42; | ^^^ error: use of a blacklisted/placeholder name `baz` - --> $DIR/blacklisted_name.rs:14:9 + --> $DIR/blacklisted_name.rs:12:9 | -14 | let baz = 42; +12 | let baz = 42; | ^^^ error: use of a blacklisted/placeholder name `foo` - --> $DIR/blacklisted_name.rs:20:10 + --> $DIR/blacklisted_name.rs:18:10 | -20 | (foo, Some(bar), baz @ Some(_)) => (), +18 | (foo, Some(bar), baz @ Some(_)) => (), | ^^^ error: use of a blacklisted/placeholder name `bar` - --> $DIR/blacklisted_name.rs:20:20 + --> $DIR/blacklisted_name.rs:18:20 | -20 | (foo, Some(bar), baz @ Some(_)) => (), +18 | (foo, Some(bar), baz @ Some(_)) => (), | ^^^ error: use of a blacklisted/placeholder name `baz` - --> $DIR/blacklisted_name.rs:20:26 + --> $DIR/blacklisted_name.rs:18:26 | -20 | (foo, Some(bar), baz @ Some(_)) => (), - | ^^^^^^^^^^^^^ +18 | (foo, Some(bar), baz @ Some(_)) => (), + | ^^^ -error: aborting due to 7 previous errors +error: use of a blacklisted/placeholder name `foo` + --> $DIR/blacklisted_name.rs:23:19 + | +23 | fn issue_1647(mut foo: u8) { + | ^^^ + +error: use of a blacklisted/placeholder name `bar` + --> $DIR/blacklisted_name.rs:24:13 + | +24 | let mut bar = 0; + | ^^^ + +error: use of a blacklisted/placeholder name `baz` + --> $DIR/blacklisted_name.rs:25:21 + | +25 | if let Some(mut baz) = Some(42) {} + | ^^^ + +error: use of a blacklisted/placeholder name `bar` + --> $DIR/blacklisted_name.rs:29:13 + | +29 | let ref bar = 0; + | ^^^ + +error: use of a blacklisted/placeholder name `baz` + --> $DIR/blacklisted_name.rs:30:21 + | +30 | if let Some(ref baz) = Some(42) {} + | ^^^ + +error: use of a blacklisted/placeholder name `bar` + --> $DIR/blacklisted_name.rs:34:17 + | +34 | let ref mut bar = 0; + | ^^^ + +error: use of a blacklisted/placeholder name `baz` + --> $DIR/blacklisted_name.rs:35:25 + | +35 | if let Some(ref mut baz) = Some(42) {} + | ^^^ + +error: aborting due to 14 previous errors diff --git a/tests/ui/conf_french_blacklisted_name.stderr b/tests/ui/conf_french_blacklisted_name.stderr index b750f4564..244ba32c4 100644 --- a/tests/ui/conf_french_blacklisted_name.stderr +++ b/tests/ui/conf_french_blacklisted_name.stderr @@ -44,7 +44,7 @@ error: use of a blacklisted/placeholder name `titi` --> $DIR/conf_french_blacklisted_name.rs:20:28 | 20 | (toto, Some(tata), titi @ Some(_)) => (), - | ^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to 7 previous errors