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
This commit is contained in:
commit
348e77cd87
2 changed files with 24 additions and 0 deletions
13
src/test/ui/consts/const-eval/size-of-t.rs
Normal file
13
src/test/ui/consts/const-eval/size-of-t.rs
Normal file
|
@ -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() {}
|
11
src/test/ui/consts/const-eval/size-of-t.stderr
Normal file
11
src/test/ui/consts/const-eval/size-of-t.stderr
Normal file
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue