Skip to content

Commit 94fc431

Browse files
committed
Auto merge of rust-lang#11560 - y21:ui-toml-tests, r=Alexendoo
Add missing tests for configuration options I noticed that a lot of lints didn't have test(s) for their configuration. This leads to issues like rust-lang#11481 where the lint just does nothing with it. This PR adds tests for *almost*[^1] all of the lints with a configuration that didn't have a test in ui-toml. The tests that I wrote here are usually two cases: one for where it's right above or under the limit set by the config where it shouldn't lint and another one for right above where it should. changelog: none [^1]: allow-one-hash-in-raw-strings is ignored by needless_raw_string_hashes
2 parents d732cce + 6e80db9 commit 94fc431

File tree

61 files changed

+501
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+501
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
literal-representation-threshold = 0xFFFFFF
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![warn(clippy::decimal_literal_representation)]
2+
fn main() {
3+
let _ = 8388608;
4+
let _ = 0x00FF_FFFF;
5+
//~^ ERROR: integer literal has a better hexadecimal representation
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![warn(clippy::decimal_literal_representation)]
2+
fn main() {
3+
let _ = 8388608;
4+
let _ = 16777215;
5+
//~^ ERROR: integer literal has a better hexadecimal representation
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: integer literal has a better hexadecimal representation
2+
--> $DIR/decimal_literal_representation.rs:4:13
3+
|
4+
LL | let _ = 16777215;
5+
| ^^^^^^^^ help: consider: `0x00FF_FFFF`
6+
|
7+
= note: `-D clippy::decimal-literal-representation` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::decimal_literal_representation)]`
9+
10+
error: aborting due to previous error
11+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
allowed-scripts = ["Cyrillic"]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![warn(clippy::disallowed_script_idents)]
2+
fn main() {
3+
let счётчик = 10;
4+
let カウンタ = 10;
5+
//~^ ERROR: identifier `カウンタ` has a Unicode script that is not allowed by configuration
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: identifier `カウンタ` has a Unicode script that is not allowed by configuration: Katakana
2+
--> $DIR/disallowed_script_idents.rs:4:9
3+
|
4+
LL | let カウンタ = 10;
5+
| ^^^^^^^^
6+
|
7+
= note: `-D clippy::disallowed-script-idents` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::disallowed_script_idents)]`
9+
10+
error: aborting due to previous error
11+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enum-variant-name-threshold = 5
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
enum Foo {
2+
AFoo,
3+
BFoo,
4+
CFoo,
5+
DFoo,
6+
}
7+
enum Foo2 {
8+
//~^ ERROR: all variants have the same postfix
9+
AFoo,
10+
BFoo,
11+
CFoo,
12+
DFoo,
13+
EFoo,
14+
}
15+
16+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: all variants have the same postfix: `Foo`
2+
--> $DIR/enum_variant_names.rs:7:1
3+
|
4+
LL | / enum Foo2 {
5+
LL | |
6+
LL | | AFoo,
7+
LL | | BFoo,
8+
... |
9+
LL | | EFoo,
10+
LL | | }
11+
| |_^
12+
|
13+
= help: remove the postfixes and use full paths to the variants instead of glob imports
14+
= note: `-D clippy::enum-variant-names` implied by `-D warnings`
15+
= help: to override `-D warnings` add `#[allow(clippy::enum_variant_names)]`
16+
17+
error: aborting due to previous error
18+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enum-variant-size-threshold = 500
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enum Fine {
2+
A(()),
3+
B([u8; 500]),
4+
}
5+
enum Bad {
6+
//~^ ERROR: large size difference between variants
7+
A(()),
8+
B(Box<[u8; 501]>),
9+
}
10+
11+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
enum Fine {
2+
A(()),
3+
B([u8; 500]),
4+
}
5+
enum Bad {
6+
//~^ ERROR: large size difference between variants
7+
A(()),
8+
B([u8; 501]),
9+
}
10+
11+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: large size difference between variants
2+
--> $DIR/enum_variant_size.rs:5:1
3+
|
4+
LL | / enum Bad {
5+
LL | |
6+
LL | | A(()),
7+
| | ----- the second-largest variant contains at least 0 bytes
8+
LL | | B([u8; 501]),
9+
| | ------------ the largest variant contains at least 501 bytes
10+
LL | | }
11+
| |_^ the entire enum is at least 502 bytes
12+
|
13+
= note: `-D clippy::large-enum-variant` implied by `-D warnings`
14+
= help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]`
15+
help: consider boxing the large fields to reduce the total size of the enum
16+
|
17+
LL | B(Box<[u8; 501]>),
18+
| ~~~~~~~~~~~~~~
19+
20+
error: aborting due to previous error
21+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enforce-iter-loop-reborrow = true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![warn(clippy::explicit_iter_loop)]
2+
3+
fn main() {
4+
let mut vec = vec![1, 2, 3];
5+
let rmvec = &mut vec;
6+
for _ in &*rmvec {}
7+
//~^ ERROR: it is more concise to loop over references to containers
8+
for _ in &mut *rmvec {}
9+
//~^ ERROR: it is more concise to loop over references to containers
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![warn(clippy::explicit_iter_loop)]
2+
3+
fn main() {
4+
let mut vec = vec![1, 2, 3];
5+
let rmvec = &mut vec;
6+
for _ in rmvec.iter() {}
7+
//~^ ERROR: it is more concise to loop over references to containers
8+
for _ in rmvec.iter_mut() {}
9+
//~^ ERROR: it is more concise to loop over references to containers
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
2+
--> $DIR/explicit_iter_loop.rs:6:14
3+
|
4+
LL | for _ in rmvec.iter() {}
5+
| ^^^^^^^^^^^^ help: to write this more concisely, try: `&*rmvec`
6+
|
7+
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::explicit_iter_loop)]`
9+
10+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
11+
--> $DIR/explicit_iter_loop.rs:8:14
12+
|
13+
LL | for _ in rmvec.iter_mut() {}
14+
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *rmvec`
15+
16+
error: aborting due to 2 previous errors
17+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
stack-size-threshold = 1000
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![warn(clippy::large_stack_frames)]
2+
3+
// We use this helper function instead of writing [0; 4294967297] directly to represent a
4+
// case that large_stack_arrays can't catch
5+
fn create_array<const N: usize>() -> [u8; N] {
6+
[0; N]
7+
}
8+
9+
fn f() {
10+
let _x = create_array::<1000>();
11+
}
12+
fn f2() {
13+
//~^ ERROR: this function allocates a large amount of stack space
14+
let _x = create_array::<1001>();
15+
}
16+
17+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: this function allocates a large amount of stack space
2+
--> $DIR/large_stack_frames.rs:12:1
3+
|
4+
LL | / fn f2() {
5+
LL | |
6+
LL | | let _x = create_array::<1001>();
7+
LL | | }
8+
| |_^
9+
|
10+
= note: allocating large amounts of stack space can overflow the stack
11+
= note: `-D clippy::large-stack-frames` implied by `-D warnings`
12+
= help: to override `-D warnings` add `#[allow(clippy::large_stack_frames)]`
13+
14+
error: aborting due to previous error
15+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pass-by-value-size-limit = 512
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![warn(clippy::large_types_passed_by_value)]
2+
3+
fn f(_v: [u8; 512]) {}
4+
fn f2(_v: &[u8; 513]) {}
5+
//~^ ERROR: this argument (513 byte) is passed by value
6+
7+
fn main() {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![warn(clippy::large_types_passed_by_value)]
2+
3+
fn f(_v: [u8; 512]) {}
4+
fn f2(_v: [u8; 513]) {}
5+
//~^ ERROR: this argument (513 byte) is passed by value
6+
7+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: this argument (513 byte) is passed by value, but might be more efficient if passed by reference (limit: 512 byte)
2+
--> $DIR/large_types_passed_by_value.rs:4:11
3+
|
4+
LL | fn f2(_v: [u8; 513]) {}
5+
| ^^^^^^^^^ help: consider passing by reference instead: `&[u8; 513]`
6+
|
7+
= note: `-D clippy::large-types-passed-by-value` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::large_types_passed_by_value)]`
9+
10+
error: aborting due to previous error
11+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
matches-for-let-else = "AllTypes"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![warn(clippy::manual_let_else)]
2+
3+
enum Foo {
4+
A(u8),
5+
B,
6+
}
7+
8+
fn main() {
9+
let Foo::A(x) = Foo::A(1) else { return };
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![warn(clippy::manual_let_else)]
2+
3+
enum Foo {
4+
A(u8),
5+
B,
6+
}
7+
8+
fn main() {
9+
let x = match Foo::A(1) {
10+
//~^ ERROR: this could be rewritten as `let...else`
11+
Foo::A(x) => x,
12+
Foo::B => return,
13+
};
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: this could be rewritten as `let...else`
2+
--> $DIR/manual_let_else.rs:9:5
3+
|
4+
LL | / let x = match Foo::A(1) {
5+
LL | |
6+
LL | | Foo::A(x) => x,
7+
LL | | Foo::B => return,
8+
LL | | };
9+
| |______^ help: consider writing: `let Foo::A(x) = Foo::A(1) else { return };`
10+
|
11+
= note: `-D clippy::manual-let-else` implied by `-D warnings`
12+
= help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]`
13+
14+
error: aborting due to previous error
15+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
allowed-dotfiles = ["dot"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![warn(clippy::path_ends_with_ext)]
2+
3+
use std::path::Path;
4+
5+
fn f(p: &Path) {
6+
p.ends_with(".dot");
7+
}
8+
9+
fn main() {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
large-error-threshold = 512
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![warn(clippy::result_large_err)]
2+
3+
fn f() -> Result<(), [u8; 511]> {
4+
todo!()
5+
}
6+
fn f2() -> Result<(), [u8; 512]> {
7+
//~^ ERROR: the `Err`-variant returned from this function is very large
8+
todo!()
9+
}
10+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: the `Err`-variant returned from this function is very large
2+
--> $DIR/result_large_err.rs:6:12
3+
|
4+
LL | fn f2() -> Result<(), [u8; 512]> {
5+
| ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
6+
|
7+
= help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>`
8+
= note: `-D clippy::result-large-err` implied by `-D warnings`
9+
= help: to override `-D warnings` add `#[allow(clippy::result_large_err)]`
10+
11+
error: aborting due to previous error
12+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn f(x: Box<[u8; 500]>) {}
2+
//~^ ERROR: local variable doesn't need to be boxed here
3+
fn f2(x: Box<[u8; 501]>) {}
4+
5+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: local variable doesn't need to be boxed here
2+
--> $DIR/boxed_local.rs:1:6
3+
|
4+
LL | fn f(x: Box<[u8; 500]>) {}
5+
| ^
6+
|
7+
= note: `-D clippy::boxed-local` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::boxed_local)]`
9+
10+
error: aborting due to previous error
11+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
too-large-for-stack = 500
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![warn(clippy::useless_vec)]
2+
3+
fn main() {
4+
let x = [0u8; 500];
5+
//~^ ERROR: useless use of `vec!`
6+
x.contains(&1);
7+
let y = vec![0u8; 501];
8+
y.contains(&1);
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![warn(clippy::useless_vec)]
2+
3+
fn main() {
4+
let x = vec![0u8; 500];
5+
//~^ ERROR: useless use of `vec!`
6+
x.contains(&1);
7+
let y = vec![0u8; 501];
8+
y.contains(&1);
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: useless use of `vec!`
2+
--> $DIR/useless_vec.rs:4:13
3+
|
4+
LL | let x = vec![0u8; 500];
5+
| ^^^^^^^^^^^^^^ help: you can use an array directly: `[0u8; 500]`
6+
|
7+
= note: `-D clippy::useless-vec` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::useless_vec)]`
9+
10+
error: aborting due to previous error
11+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
too-many-arguments-threshold = 10
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![warn(clippy::too_many_arguments)]
2+
3+
fn not_too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8) {}
4+
fn too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8, p11: u8) {}
5+
//~^ ERROR: this function has too many arguments
6+
7+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: this function has too many arguments (11/10)
2+
--> $DIR/too_many_arguments.rs:4:1
3+
|
4+
LL | fn too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8, p11: u8) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::too-many-arguments` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]`
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)