diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-08 11:08:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-08 11:08:57 +0100 |
| commit | 871cf2bc9e4221ec1dfdcfdb3f8d66ab42d6201b (patch) | |
| tree | 4fa59bf40f2861bed6eb5a82497fda254b714e17 /src/test | |
| parent | c104236f820df5223d77f01f4f651808eb397720 (diff) | |
| parent | b38a54049ed89f00f0519b37d10ae2ae1e69b173 (diff) | |
| download | rust-871cf2bc9e4221ec1dfdcfdb3f8d66ab42d6201b.tar.gz rust-871cf2bc9e4221ec1dfdcfdb3f8d66ab42d6201b.zip | |
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.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/consts/issue-90870.fixed | 34 | ||||
| -rw-r--r-- | src/test/ui/consts/issue-90870.rs | 34 | ||||
| -rw-r--r-- | src/test/ui/consts/issue-90870.stderr | 36 |
3 files changed, 104 insertions, 0 deletions
diff --git a/src/test/ui/consts/issue-90870.fixed b/src/test/ui/consts/issue-90870.fixed new file mode 100644 index 00000000000..e767effcdd0 --- /dev/null +++ b/src/test/ui/consts/issue-90870.fixed @@ -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() {} diff --git a/src/test/ui/consts/issue-90870.rs b/src/test/ui/consts/issue-90870.rs new file mode 100644 index 00000000000..35b3c8242aa --- /dev/null +++ b/src/test/ui/consts/issue-90870.rs @@ -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() {} diff --git a/src/test/ui/consts/issue-90870.stderr b/src/test/ui/consts/issue-90870.stderr new file mode 100644 index 00000000000..0e33e6ebe5a --- /dev/null +++ b/src/test/ui/consts/issue-90870.stderr @@ -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`. |
