Skip to content

diagnostics: add test case for bogus T:Sized suggestion #95593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/test/ui/consts/const-eval/size-of-t.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions src/test/ui/consts/const-eval/size-of-t.stderr
Original file line number Diff line number Diff line change
@@ -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