mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
add uitest for indexing in unnecessary const items
This commit is contained in:
parent
0eb9f41a07
commit
aff0e6d6d3
3 changed files with 43 additions and 3 deletions
|
@ -43,7 +43,7 @@ fn get_number() -> i32 {
|
|||
0
|
||||
}
|
||||
|
||||
fn get_usize() -> usize {
|
||||
const fn get_usize() -> usize {
|
||||
0
|
||||
}
|
||||
fn get_struct() -> Struct {
|
||||
|
@ -113,4 +113,15 @@ fn main() {
|
|||
'label: {
|
||||
break 'label
|
||||
};
|
||||
let () = const {
|
||||
assert!([42, 55].len() > get_usize());
|
||||
};
|
||||
}
|
||||
|
||||
const _: () = {
|
||||
assert!([42, 55].len() > get_usize());
|
||||
};
|
||||
|
||||
const fn foo() {
|
||||
assert!([42, 55].len() > get_usize());
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ fn get_number() -> i32 {
|
|||
0
|
||||
}
|
||||
|
||||
fn get_usize() -> usize {
|
||||
const fn get_usize() -> usize {
|
||||
0
|
||||
}
|
||||
fn get_struct() -> Struct {
|
||||
|
@ -117,4 +117,15 @@ fn main() {
|
|||
'label: {
|
||||
break 'label
|
||||
};
|
||||
let () = const {
|
||||
[42, 55][get_usize()];
|
||||
};
|
||||
}
|
||||
|
||||
const _: () = {
|
||||
[42, 55][get_usize()];
|
||||
};
|
||||
|
||||
const fn foo() {
|
||||
[42, 55][get_usize()];
|
||||
}
|
||||
|
|
|
@ -119,5 +119,23 @@ LL | | s: String::from("blah"),
|
|||
LL | | };
|
||||
| |______^ help: statement can be reduced to: `String::from("blah");`
|
||||
|
||||
error: aborting due to 19 previous errors
|
||||
error: unnecessary operation
|
||||
--> tests/ui/unnecessary_operation.rs:121:9
|
||||
|
|
||||
LL | [42, 55][get_usize()];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());`
|
||||
|
||||
error: unnecessary operation
|
||||
--> tests/ui/unnecessary_operation.rs:126:5
|
||||
|
|
||||
LL | [42, 55][get_usize()];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());`
|
||||
|
||||
error: unnecessary operation
|
||||
--> tests/ui/unnecessary_operation.rs:130:5
|
||||
|
|
||||
LL | [42, 55][get_usize()];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: statement can be written as: `assert!([42, 55].len() > get_usize());`
|
||||
|
||||
error: aborting due to 22 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue