Skip to content

Commit 348e77c

Browse files
authored
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
2 parents 30c0738 + 7620a5f commit 348e77c

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// https://github.com/rust-lang/rust/issues/69228
2+
// Used to give bogus suggestion about T not being Sized.
3+
4+
use std::mem::size_of;
5+
6+
fn foo<T>() {
7+
let _arr: [u8; size_of::<T>()];
8+
//~^ ERROR generic parameters may not be used in const operations
9+
//~| NOTE cannot perform const operation
10+
//~| NOTE type parameters may not be used in const expressions
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: generic parameters may not be used in const operations
2+
--> $DIR/size-of-t.rs:7:30
3+
|
4+
LL | let _arr: [u8; size_of::<T>()];
5+
| ^ cannot perform const operation using `T`
6+
|
7+
= note: type parameters may not be used in const expressions
8+
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)