add uitest for indexing in unnecessary const items

This commit is contained in:
Lzu Tao 2024-05-24 09:24:54 +07:00
parent 0eb9f41a07
commit aff0e6d6d3
3 changed files with 43 additions and 3 deletions

View file

@ -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());
}

View file

@ -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()];
}

View file

@ -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