diff options
Diffstat (limited to 'src/tools/clippy/tests/ui-toml/toml_disallowed_methods')
3 files changed, 87 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/clippy.toml b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/clippy.toml new file mode 100644 index 000000000..c902d2112 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/clippy.toml @@ -0,0 +1,10 @@ +disallowed-methods = [ + # just a string is shorthand for path only + "std::iter::Iterator::sum", + "f32::clamp", + "slice::sort_unstable", + # can give path and reason with an inline table + { path = "regex::Regex::is_match", reason = "no matching allowed" }, + # can use an inline table but omit reason + { path = "regex::Regex::new" }, +] diff --git a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs new file mode 100644 index 000000000..3397fa1ec --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs @@ -0,0 +1,23 @@ +#![warn(clippy::disallowed_methods)] + +extern crate regex; +use regex::Regex; + +fn main() { + let re = Regex::new(r"ab.*c").unwrap(); + re.is_match("abc"); + + let mut a = vec![1, 2, 3, 4]; + a.iter().sum::<i32>(); + + a.sort_unstable(); + + let _ = 2.0f32.clamp(3.0f32, 4.0f32); + let _ = 2.0f64.clamp(3.0f64, 4.0f64); + + let indirect: fn(&str) -> Result<Regex, regex::Error> = Regex::new; + let re = indirect(".").unwrap(); + + let in_call = Box::new(f32::clamp); + let in_method_call = ["^", "$"].into_iter().map(Regex::new); +} diff --git a/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr new file mode 100644 index 000000000..5cbb56754 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.stderr @@ -0,0 +1,54 @@ +error: use of a disallowed method `regex::Regex::new` + --> $DIR/conf_disallowed_methods.rs:7:14 + | +LL | let re = Regex::new(r"ab.*c").unwrap(); + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::disallowed-methods` implied by `-D warnings` + +error: use of a disallowed method `regex::Regex::is_match` + --> $DIR/conf_disallowed_methods.rs:8:5 + | +LL | re.is_match("abc"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: no matching allowed (from clippy.toml) + +error: use of a disallowed method `std::iter::Iterator::sum` + --> $DIR/conf_disallowed_methods.rs:11:5 + | +LL | a.iter().sum::<i32>(); + | ^^^^^^^^^^^^^^^^^^^^^ + +error: use of a disallowed method `slice::sort_unstable` + --> $DIR/conf_disallowed_methods.rs:13:5 + | +LL | a.sort_unstable(); + | ^^^^^^^^^^^^^^^^^ + +error: use of a disallowed method `f32::clamp` + --> $DIR/conf_disallowed_methods.rs:15:13 + | +LL | let _ = 2.0f32.clamp(3.0f32, 4.0f32); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: use of a disallowed method `regex::Regex::new` + --> $DIR/conf_disallowed_methods.rs:18:61 + | +LL | let indirect: fn(&str) -> Result<Regex, regex::Error> = Regex::new; + | ^^^^^^^^^^ + +error: use of a disallowed method `f32::clamp` + --> $DIR/conf_disallowed_methods.rs:21:28 + | +LL | let in_call = Box::new(f32::clamp); + | ^^^^^^^^^^ + +error: use of a disallowed method `regex::Regex::new` + --> $DIR/conf_disallowed_methods.rs:22:53 + | +LL | let in_method_call = ["^", "$"].into_iter().map(Regex::new); + | ^^^^^^^^^^ + +error: aborting due to 8 previous errors + |