about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-04-02 22:38:21 +0200
committerGitHub <noreply@github.com>2022-04-02 22:38:21 +0200
commit348e77cd87858ddb0eff5a2eb6c14d2c0b92f3c6 (patch)
tree6de9025dc836e1e6aee9d55aca8903c267786cfc
parent30c0738d1f733120a52d9845b3cf592096e57e76 (diff)
parent7620a5f52a238cbafdfcaa50edcc1acb6a0a3244 (diff)
downloadrust-348e77cd87858ddb0eff5a2eb6c14d2c0b92f3c6.tar.gz
rust-348e77cd87858ddb0eff5a2eb6c14d2c0b92f3c6.zip
Rollup merge of #95593 - notriddle:notriddle/size-of-in-const-context, r=compiler-errors
diagnostics: add test case for bogus T:Sized suggestion

Closes #69228
-rw-r--r--src/test/ui/consts/const-eval/size-of-t.rs13
-rw-r--r--src/test/ui/consts/const-eval/size-of-t.stderr11
2 files changed, 24 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-eval/size-of-t.rs b/src/test/ui/consts/const-eval/size-of-t.rs
new file mode 100644
index 00000000000..efbdeec7008
--- /dev/null
+++ b/src/test/ui/consts/const-eval/size-of-t.rs
@@ -0,0 +1,13 @@
+// https://github.com/rust-lang/rust/issues/69228
+// Used to give bogus suggestion about T not being Sized.
+
+use std::mem::size_of;
+
+fn foo<T>() {
+    let _arr: [u8; size_of::<T>()];
+    //~^ ERROR generic parameters may not be used in const operations
+    //~| NOTE cannot perform const operation
+    //~| NOTE type parameters may not be used in const expressions
+}
+
+fn main() {}
diff --git a/src/test/ui/consts/const-eval/size-of-t.stderr b/src/test/ui/consts/const-eval/size-of-t.stderr
new file mode 100644
index 00000000000..abe6410465e
--- /dev/null
+++ b/src/test/ui/consts/const-eval/size-of-t.stderr
@@ -0,0 +1,11 @@
+error: generic parameters may not be used in const operations
+  --> $DIR/size-of-t.rs:7:30
+   |
+LL |     let _arr: [u8; size_of::<T>()];
+   |                              ^ cannot perform const operation using `T`
+   |
+   = note: type parameters may not be used in const expressions
+   = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
+
+error: aborting due to previous error
+