Rollup merge of #91272 - FabianWolff:issue-90870-const-fn-eq, r=wesleywiser
Print a suggestion when comparing references to primitive types in `const fn` Fixes #90870.
This commit is contained in:
commit
871cf2bc9e
5 changed files with 170 additions and 10 deletions
34
src/test/ui/consts/issue-90870.fixed
Normal file
34
src/test/ui/consts/issue-90870.fixed
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Regression test for issue #90870.
|
||||
|
||||
// run-rustfix
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
const fn f(a: &u8, b: &u8) -> bool {
|
||||
*a == *b
|
||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
||||
//~| HELP: consider dereferencing here
|
||||
}
|
||||
|
||||
const fn g(a: &&&&i64, b: &&&&i64) -> bool {
|
||||
****a == ****b
|
||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
||||
//~| HELP: consider dereferencing here
|
||||
}
|
||||
|
||||
const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
|
||||
while let ([l, at @ ..], [r, bt @ ..]) = (a, b) {
|
||||
if *l == *r {
|
||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
||||
//~| HELP: consider dereferencing here
|
||||
a = at;
|
||||
b = bt;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
a.is_empty() && b.is_empty()
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
34
src/test/ui/consts/issue-90870.rs
Normal file
34
src/test/ui/consts/issue-90870.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Regression test for issue #90870.
|
||||
|
||||
// run-rustfix
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
const fn f(a: &u8, b: &u8) -> bool {
|
||||
a == b
|
||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
||||
//~| HELP: consider dereferencing here
|
||||
}
|
||||
|
||||
const fn g(a: &&&&i64, b: &&&&i64) -> bool {
|
||||
a == b
|
||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
||||
//~| HELP: consider dereferencing here
|
||||
}
|
||||
|
||||
const fn h(mut a: &[u8], mut b: &[u8]) -> bool {
|
||||
while let ([l, at @ ..], [r, bt @ ..]) = (a, b) {
|
||||
if l == r {
|
||||
//~^ ERROR: calls in constant functions are limited to constant functions, tuple structs and tuple variants [E0015]
|
||||
//~| HELP: consider dereferencing here
|
||||
a = at;
|
||||
b = bt;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
a.is_empty() && b.is_empty()
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
36
src/test/ui/consts/issue-90870.stderr
Normal file
36
src/test/ui/consts/issue-90870.stderr
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
--> $DIR/issue-90870.rs:8:5
|
||||
|
|
||||
LL | a == b
|
||||
| ^^^^^^
|
||||
|
|
||||
help: consider dereferencing here
|
||||
|
|
||||
LL | *a == *b
|
||||
| + +
|
||||
|
||||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
--> $DIR/issue-90870.rs:14:5
|
||||
|
|
||||
LL | a == b
|
||||
| ^^^^^^
|
||||
|
|
||||
help: consider dereferencing here
|
||||
|
|
||||
LL | ****a == ****b
|
||||
| ++++ ++++
|
||||
|
||||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
--> $DIR/issue-90870.rs:21:12
|
||||
|
|
||||
LL | if l == r {
|
||||
| ^^^^^^
|
||||
|
|
||||
help: consider dereferencing here
|
||||
|
|
||||
LL | if *l == *r {
|
||||
| + +
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0015`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue