Skip to content

Commit 1c50f0f

Browse files
committed
Allow paths to contain spaces in disallowed_methods
1 parent be61b7a commit 1c50f0f

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

clippy_utils/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,13 @@ pub fn create_disallowed_map(
756756
) -> DefIdMap<(&'static str, Option<&'static str>)> {
757757
disallowed
758758
.iter()
759-
.map(|x| (x.path(), x.path().split("::").collect::<Vec<_>>(), x.reason()))
759+
.map(|x| {
760+
(
761+
x.path(),
762+
x.path().split("::").map(str::trim).collect::<Vec<_>>(),
763+
x.reason(),
764+
)
765+
})
760766
.flat_map(|(name, path, reason)| def_path_def_ids(tcx, &path).map(move |id| (id, (name, reason))))
761767
.collect()
762768
}

tests/ui-toml/toml_disallowed_methods/clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ disallowed-methods = [
1414
"conf_disallowed_methods::Struct::method",
1515
"conf_disallowed_methods::Trait::provided_method",
1616
"conf_disallowed_methods::Trait::implemented_method",
17+
"conf_disallowed_methods :: path :: with :: spaces",
1718
]

tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ mod local_mod {
2929
pub fn f() {}
3030
}
3131

32+
// Disallowed as `path :: with :: spaces` in clippy.toml.
33+
pub mod path {
34+
pub mod with {
35+
pub fn spaces() {}
36+
}
37+
}
38+
3239
fn main() {
3340
let re = Regex::new(r"ab.*c").unwrap();
3441
re.is_match("abc");
@@ -57,4 +64,6 @@ fn main() {
5764
s.method();
5865
s.provided_method();
5966
s.implemented_method();
67+
68+
path::with::spaces();
6069
}
Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: use of a disallowed method `regex::Regex::new`
2-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:35:14
2+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:40:14
33
|
44
LL | let re = Regex::new(r"ab.*c").unwrap();
55
| ^^^^^^^^^^
@@ -8,84 +8,90 @@ LL | let re = Regex::new(r"ab.*c").unwrap();
88
= help: to override `-D warnings` add `#[allow(clippy::disallowed_methods)]`
99

1010
error: use of a disallowed method `regex::Regex::is_match`
11-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:36:8
11+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:41:8
1212
|
1313
LL | re.is_match("abc");
1414
| ^^^^^^^^
1515
|
1616
= note: no matching allowed
1717

1818
error: use of a disallowed method `std::iter::Iterator::sum`
19-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:39:14
19+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:44:14
2020
|
2121
LL | a.iter().sum::<i32>();
2222
| ^^^
2323

2424
error: use of a disallowed method `slice::sort_unstable`
25-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:41:7
25+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:46:7
2626
|
2727
LL | a.sort_unstable();
2828
| ^^^^^^^^^^^^^
2929

3030
error: use of a disallowed method `f32::clamp`
31-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:44:20
31+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:49:20
3232
|
3333
LL | let _ = 2.0f32.clamp(3.0f32, 4.0f32);
3434
| ^^^^^
3535

3636
error: use of a disallowed method `regex::Regex::new`
37-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:47:61
37+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:52:61
3838
|
3939
LL | let indirect: fn(&str) -> Result<Regex, regex::Error> = Regex::new;
4040
| ^^^^^^^^^^
4141

4242
error: use of a disallowed method `f32::clamp`
43-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:50:28
43+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:55:28
4444
|
4545
LL | let in_call = Box::new(f32::clamp);
4646
| ^^^^^^^^^^
4747

4848
error: use of a disallowed method `regex::Regex::new`
49-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:51:53
49+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:56:53
5050
|
5151
LL | let in_method_call = ["^", "$"].into_iter().map(Regex::new);
5252
| ^^^^^^^^^^
5353

5454
error: use of a disallowed method `futures::stream::select_all`
55-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:54:31
55+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:59:31
5656
|
5757
LL | let same_name_as_module = select_all(vec![empty::<()>()]);
5858
| ^^^^^^^^^^
5959

6060
error: use of a disallowed method `conf_disallowed_methods::local_fn`
61-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:56:5
61+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:61:5
6262
|
6363
LL | local_fn();
6464
| ^^^^^^^^
6565

6666
error: use of a disallowed method `conf_disallowed_methods::local_mod::f`
67-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:57:5
67+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:62:5
6868
|
6969
LL | local_mod::f();
7070
| ^^^^^^^^^^^^
7171

7272
error: use of a disallowed method `conf_disallowed_methods::Struct::method`
73-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:59:7
73+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:64:7
7474
|
7575
LL | s.method();
7676
| ^^^^^^
7777

7878
error: use of a disallowed method `conf_disallowed_methods::Trait::provided_method`
79-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:60:7
79+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:65:7
8080
|
8181
LL | s.provided_method();
8282
| ^^^^^^^^^^^^^^^
8383

8484
error: use of a disallowed method `conf_disallowed_methods::Trait::implemented_method`
85-
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:61:7
85+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:66:7
8686
|
8787
LL | s.implemented_method();
8888
| ^^^^^^^^^^^^^^^^^^
8989

90-
error: aborting due to 14 previous errors
90+
error: use of a disallowed method `conf_disallowed_methods :: path :: with :: spaces`
91+
--> tests/ui-toml/toml_disallowed_methods/conf_disallowed_methods.rs:68:5
92+
|
93+
LL | path::with::spaces();
94+
| ^^^^^^^^^^^^^^^^^^
95+
96+
error: aborting due to 15 previous errors
9197

0 commit comments

Comments
 (0)