From 7620a5f52a238cbafdfcaa50edcc1acb6a0a3244 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 2 Apr 2022 09:57:04 -0700 Subject: [PATCH] diagnostics: add test case for bogus T:Sized suggestion Closes #69228 --- src/test/ui/consts/const-eval/size-of-t.rs | 13 +++++++++++++ src/test/ui/consts/const-eval/size-of-t.stderr | 11 +++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/test/ui/consts/const-eval/size-of-t.rs create mode 100644 src/test/ui/consts/const-eval/size-of-t.stderr 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() { + let _arr: [u8; size_of::()]; + //~^ 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::()]; + | ^ 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 +