forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#91272 - FabianWolff:issue-90870-const-fn-eq…
…, r=wesleywiser Print a suggestion when comparing references to primitive types in `const fn` Fixes rust-lang#90870.
- Loading branch information
Showing
5 changed files
with
170 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |