2018-12-09 16:26:16 -06:00
|
|
|
#![allow(
|
|
|
|
dead_code,
|
2023-06-10 06:43:30 -05:00
|
|
|
clippy::needless_if,
|
2018-12-09 16:26:16 -06:00
|
|
|
clippy::similar_names,
|
|
|
|
clippy::single_match,
|
|
|
|
clippy::toplevel_ref_arg,
|
|
|
|
unused_mut,
|
|
|
|
unused_variables
|
|
|
|
)]
|
2022-06-08 14:08:37 -05:00
|
|
|
#![warn(clippy::disallowed_names)]
|
2016-02-22 08:42:24 -06:00
|
|
|
|
2017-02-08 07:58:07 -06:00
|
|
|
fn test(foo: ()) {}
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `foo`
|
|
|
|
//~| NOTE: `-D clippy::disallowed-names` implied by `-D warnings`
|
2016-02-22 08:42:24 -06:00
|
|
|
|
|
|
|
fn main() {
|
2017-02-08 07:58:07 -06:00
|
|
|
let foo = 42;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `foo`
|
2017-02-08 07:58:07 -06:00
|
|
|
let baz = 42;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `baz`
|
2020-06-13 08:24:36 -05:00
|
|
|
let quux = 42;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `quux`
|
2020-06-13 19:40:36 -05:00
|
|
|
// Unlike these others, `bar` is actually considered an acceptable name.
|
|
|
|
// Among many other legitimate uses, bar commonly refers to a period of time in music.
|
2020-06-13 08:24:36 -05:00
|
|
|
// See https://github.com/rust-lang/rust-clippy/issues/5225.
|
2020-06-13 19:40:36 -05:00
|
|
|
let bar = 42;
|
2016-02-22 08:42:24 -06:00
|
|
|
|
2020-06-13 08:24:36 -05:00
|
|
|
let food = 42;
|
|
|
|
let foodstuffs = 42;
|
|
|
|
let bazaar = 42;
|
2016-02-22 08:42:24 -06:00
|
|
|
|
|
|
|
match (42, Some(1337), Some(0)) {
|
2020-06-13 08:24:36 -05:00
|
|
|
(foo, Some(baz), quux @ Some(_)) => (),
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `foo`
|
|
|
|
//~| ERROR: use of a disallowed/placeholder name `baz`
|
|
|
|
//~| ERROR: use of a disallowed/placeholder name `quux`
|
2016-02-22 08:42:24 -06:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
2017-05-14 07:58:16 -05:00
|
|
|
|
|
|
|
fn issue_1647(mut foo: u8) {
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `foo`
|
2020-06-13 08:24:36 -05:00
|
|
|
let mut baz = 0;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `baz`
|
2020-06-13 08:24:36 -05:00
|
|
|
if let Some(mut quux) = Some(42) {}
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `quux`
|
2017-05-14 07:58:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_1647_ref() {
|
2020-06-13 08:24:36 -05:00
|
|
|
let ref baz = 0;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `baz`
|
2020-06-13 08:24:36 -05:00
|
|
|
if let Some(ref quux) = Some(42) {}
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `quux`
|
2017-05-14 07:58:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn issue_1647_ref_mut() {
|
2020-06-13 08:24:36 -05:00
|
|
|
let ref mut baz = 0;
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `baz`
|
2020-06-13 08:24:36 -05:00
|
|
|
if let Some(ref mut quux) = Some(42) {}
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: use of a disallowed/placeholder name `quux`
|
2017-05-14 07:58:16 -05:00
|
|
|
}
|
2021-06-19 13:14:05 -05:00
|
|
|
|
2024-06-09 21:11:47 -05:00
|
|
|
#[cfg(test)]
|
2021-06-19 13:14:05 -05:00
|
|
|
mod tests {
|
|
|
|
fn issue_7305() {
|
2022-06-08 14:08:37 -05:00
|
|
|
// `disallowed_names` lint should not be triggered inside of the test code.
|
2021-06-19 13:14:05 -05:00
|
|
|
let foo = 0;
|
|
|
|
|
2022-05-13 00:20:25 -05:00
|
|
|
// Check that even in nested functions warning is still not triggered.
|
2021-06-19 13:14:05 -05:00
|
|
|
fn nested() {
|
|
|
|
let foo = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-19 20:16:30 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_with_disallowed_name() {
|
|
|
|
let foo = 0;
|
|
|
|
}
|