Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing tests for configuration options #11560

Merged
merged 2 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/ui-toml/decimal_literal_representation/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
literal-representation-threshold = 0xFFFFFF
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![warn(clippy::decimal_literal_representation)]
fn main() {
let _ = 8388608;
let _ = 0x00FF_FFFF;
//~^ ERROR: integer literal has a better hexadecimal representation
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![warn(clippy::decimal_literal_representation)]
fn main() {
let _ = 8388608;
let _ = 16777215;
//~^ ERROR: integer literal has a better hexadecimal representation
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: integer literal has a better hexadecimal representation
--> $DIR/decimal_literal_representation.rs:4:13
|
LL | let _ = 16777215;
| ^^^^^^^^ help: consider: `0x00FF_FFFF`
|
= note: `-D clippy::decimal-literal-representation` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::decimal_literal_representation)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui-toml/disallowed_script_idents/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allowed-scripts = ["Cyrillic"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![warn(clippy::disallowed_script_idents)]
fn main() {
let счётчик = 10;
let カウンタ = 10;
//~^ ERROR: identifier `カウンタ` has a Unicode script that is not allowed by configuration
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: identifier `カウンタ` has a Unicode script that is not allowed by configuration: Katakana
--> $DIR/disallowed_script_idents.rs:4:9
|
LL | let カウンタ = 10;
| ^^^^^^^^
|
= note: `-D clippy::disallowed-script-idents` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::disallowed_script_idents)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui-toml/enum_variant_names/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum-variant-name-threshold = 5
16 changes: 16 additions & 0 deletions tests/ui-toml/enum_variant_names/enum_variant_names.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
enum Foo {
AFoo,
BFoo,
CFoo,
DFoo,
}
enum Foo2 {
//~^ ERROR: all variants have the same postfix
AFoo,
BFoo,
CFoo,
DFoo,
EFoo,
}

fn main() {}
18 changes: 18 additions & 0 deletions tests/ui-toml/enum_variant_names/enum_variant_names.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: all variants have the same postfix: `Foo`
--> $DIR/enum_variant_names.rs:7:1
|
LL | / enum Foo2 {
LL | |
LL | | AFoo,
LL | | BFoo,
... |
LL | | EFoo,
LL | | }
| |_^
|
= help: remove the postfixes and use full paths to the variants instead of glob imports
= note: `-D clippy::enum-variant-names` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::enum_variant_names)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui-toml/enum_variant_size/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum-variant-size-threshold = 500
11 changes: 11 additions & 0 deletions tests/ui-toml/enum_variant_size/enum_variant_size.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enum Fine {
A(()),
B([u8; 500]),
}
enum Bad {
//~^ ERROR: large size difference between variants
A(()),
B(Box<[u8; 501]>),
}

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui-toml/enum_variant_size/enum_variant_size.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
enum Fine {
A(()),
B([u8; 500]),
}
enum Bad {
//~^ ERROR: large size difference between variants
A(()),
B([u8; 501]),
}

fn main() {}
21 changes: 21 additions & 0 deletions tests/ui-toml/enum_variant_size/enum_variant_size.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error: large size difference between variants
--> $DIR/enum_variant_size.rs:5:1
|
LL | / enum Bad {
LL | |
LL | | A(()),
| | ----- the second-largest variant contains at least 0 bytes
LL | | B([u8; 501]),
| | ------------ the largest variant contains at least 501 bytes
LL | | }
| |_^ the entire enum is at least 502 bytes
|
= note: `-D clippy::large-enum-variant` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::large_enum_variant)]`
help: consider boxing the large fields to reduce the total size of the enum
|
LL | B(Box<[u8; 501]>),
| ~~~~~~~~~~~~~~

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui-toml/explicit_iter_loop/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enforce-iter-loop-reborrow = true
10 changes: 10 additions & 0 deletions tests/ui-toml/explicit_iter_loop/explicit_iter_loop.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![warn(clippy::explicit_iter_loop)]

fn main() {
let mut vec = vec![1, 2, 3];
let rmvec = &mut vec;
for _ in &*rmvec {}
//~^ ERROR: it is more concise to loop over references to containers
for _ in &mut *rmvec {}
//~^ ERROR: it is more concise to loop over references to containers
}
10 changes: 10 additions & 0 deletions tests/ui-toml/explicit_iter_loop/explicit_iter_loop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![warn(clippy::explicit_iter_loop)]

fn main() {
let mut vec = vec![1, 2, 3];
let rmvec = &mut vec;
for _ in rmvec.iter() {}
//~^ ERROR: it is more concise to loop over references to containers
for _ in rmvec.iter_mut() {}
//~^ ERROR: it is more concise to loop over references to containers
}
17 changes: 17 additions & 0 deletions tests/ui-toml/explicit_iter_loop/explicit_iter_loop.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/explicit_iter_loop.rs:6:14
|
LL | for _ in rmvec.iter() {}
| ^^^^^^^^^^^^ help: to write this more concisely, try: `&*rmvec`
|
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::explicit_iter_loop)]`

error: it is more concise to loop over references to containers instead of using explicit iteration methods
--> $DIR/explicit_iter_loop.rs:8:14
|
LL | for _ in rmvec.iter_mut() {}
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *rmvec`

error: aborting due to 2 previous errors

1 change: 1 addition & 0 deletions tests/ui-toml/large_stack_frames/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stack-size-threshold = 1000
17 changes: 17 additions & 0 deletions tests/ui-toml/large_stack_frames/large_stack_frames.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![warn(clippy::large_stack_frames)]

// We use this helper function instead of writing [0; 4294967297] directly to represent a
// case that large_stack_arrays can't catch
fn create_array<const N: usize>() -> [u8; N] {
[0; N]
}

fn f() {
let _x = create_array::<1000>();
}
fn f2() {
//~^ ERROR: this function allocates a large amount of stack space
let _x = create_array::<1001>();
}

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui-toml/large_stack_frames/large_stack_frames.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: this function allocates a large amount of stack space
--> $DIR/large_stack_frames.rs:12:1
|
LL | / fn f2() {
LL | |
LL | | let _x = create_array::<1001>();
LL | | }
| |_^
|
= note: allocating large amounts of stack space can overflow the stack
= note: `-D clippy::large-stack-frames` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::large_stack_frames)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui-toml/large_types_passed_by_value/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pass-by-value-size-limit = 512
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![warn(clippy::large_types_passed_by_value)]

fn f(_v: [u8; 512]) {}
fn f2(_v: &[u8; 513]) {}
//~^ ERROR: this argument (513 byte) is passed by value

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![warn(clippy::large_types_passed_by_value)]

fn f(_v: [u8; 512]) {}
fn f2(_v: [u8; 513]) {}
//~^ ERROR: this argument (513 byte) is passed by value

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: this argument (513 byte) is passed by value, but might be more efficient if passed by reference (limit: 512 byte)
--> $DIR/large_types_passed_by_value.rs:4:11
|
LL | fn f2(_v: [u8; 513]) {}
| ^^^^^^^^^ help: consider passing by reference instead: `&[u8; 513]`
|
= note: `-D clippy::large-types-passed-by-value` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::large_types_passed_by_value)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui-toml/manual_let_else/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
matches-for-let-else = "AllTypes"
10 changes: 10 additions & 0 deletions tests/ui-toml/manual_let_else/manual_let_else.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![warn(clippy::manual_let_else)]

enum Foo {
A(u8),
B,
}

fn main() {
let Foo::A(x) = Foo::A(1) else { return };
}
14 changes: 14 additions & 0 deletions tests/ui-toml/manual_let_else/manual_let_else.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![warn(clippy::manual_let_else)]

enum Foo {
A(u8),
B,
}

fn main() {
let x = match Foo::A(1) {
//~^ ERROR: this could be rewritten as `let...else`
Foo::A(x) => x,
Foo::B => return,
};
}
15 changes: 15 additions & 0 deletions tests/ui-toml/manual_let_else/manual_let_else.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: this could be rewritten as `let...else`
--> $DIR/manual_let_else.rs:9:5
|
LL | / let x = match Foo::A(1) {
LL | |
LL | | Foo::A(x) => x,
LL | | Foo::B => return,
LL | | };
| |______^ help: consider writing: `let Foo::A(x) = Foo::A(1) else { return };`
|
= note: `-D clippy::manual-let-else` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::manual_let_else)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui-toml/path_ends_with_ext/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
allowed-dotfiles = ["dot"]
9 changes: 9 additions & 0 deletions tests/ui-toml/path_ends_with_ext/path_ends_with_ext.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![warn(clippy::path_ends_with_ext)]

use std::path::Path;

fn f(p: &Path) {
p.ends_with(".dot");
}

fn main() {}
1 change: 1 addition & 0 deletions tests/ui-toml/result_large_err/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
large-error-threshold = 512
10 changes: 10 additions & 0 deletions tests/ui-toml/result_large_err/result_large_err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![warn(clippy::result_large_err)]

fn f() -> Result<(), [u8; 511]> {
todo!()
}
fn f2() -> Result<(), [u8; 512]> {
//~^ ERROR: the `Err`-variant returned from this function is very large
todo!()
}
fn main() {}
12 changes: 12 additions & 0 deletions tests/ui-toml/result_large_err/result_large_err.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error: the `Err`-variant returned from this function is very large
--> $DIR/result_large_err.rs:6:12
|
LL | fn f2() -> Result<(), [u8; 512]> {
| ^^^^^^^^^^^^^^^^^^^^^ the `Err`-variant is at least 512 bytes
|
= help: try reducing the size of `[u8; 512]`, for example by boxing large elements or replacing it with `Box<[u8; 512]>`
= note: `-D clippy::result-large-err` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::result_large_err)]`

error: aborting due to previous error

5 changes: 5 additions & 0 deletions tests/ui-toml/too_large_for_stack/boxed_local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn f(x: Box<[u8; 500]>) {}
//~^ ERROR: local variable doesn't need to be boxed here
fn f2(x: Box<[u8; 501]>) {}

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui-toml/too_large_for_stack/boxed_local.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: local variable doesn't need to be boxed here
--> $DIR/boxed_local.rs:1:6
|
LL | fn f(x: Box<[u8; 500]>) {}
| ^
|
= note: `-D clippy::boxed-local` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::boxed_local)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui-toml/too_large_for_stack/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
too-large-for-stack = 500
9 changes: 9 additions & 0 deletions tests/ui-toml/too_large_for_stack/useless_vec.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![warn(clippy::useless_vec)]

fn main() {
let x = [0u8; 500];
//~^ ERROR: useless use of `vec!`
x.contains(&1);
let y = vec![0u8; 501];
y.contains(&1);
}
9 changes: 9 additions & 0 deletions tests/ui-toml/too_large_for_stack/useless_vec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![warn(clippy::useless_vec)]

fn main() {
let x = vec![0u8; 500];
//~^ ERROR: useless use of `vec!`
x.contains(&1);
let y = vec![0u8; 501];
y.contains(&1);
}
11 changes: 11 additions & 0 deletions tests/ui-toml/too_large_for_stack/useless_vec.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: useless use of `vec!`
--> $DIR/useless_vec.rs:4:13
|
LL | let x = vec![0u8; 500];
| ^^^^^^^^^^^^^^ help: you can use an array directly: `[0u8; 500]`
|
= note: `-D clippy::useless-vec` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::useless_vec)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui-toml/too_many_arguments/clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
too-many-arguments-threshold = 10
7 changes: 7 additions & 0 deletions tests/ui-toml/too_many_arguments/too_many_arguments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![warn(clippy::too_many_arguments)]

fn not_too_many(p1: u8, p2: u8, p3: u8, p4: u8, p5: u8, p6: u8, p7: u8, p8: u8, p9: u8, p10: u8) {}
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) {}
//~^ ERROR: this function has too many arguments

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui-toml/too_many_arguments/too_many_arguments.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: this function has too many arguments (11/10)
--> $DIR/too_many_arguments.rs:4:1
|
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) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::too-many-arguments` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::too_many_arguments)]`

error: aborting due to previous error

Loading