rust/tests/ui/consts/required-consts/collect-in-dead-vtable.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
915 B
Rust
Raw Normal View History

//@revisions: noopt opt
2024-03-17 07:28:31 -05:00
//@ build-fail
2024-03-18 11:54:48 -05:00
//@[noopt] compile-flags: -Copt-level=0
//@[opt] compile-flags: -O
2024-03-17 03:02:18 -05:00
//! This fails without optimizations, so it should also fail with optimizations.
struct Fail<T>(T);
impl<T> Fail<T> {
2024-03-17 07:28:31 -05:00
const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed
}
trait MyTrait {
fn not_called(&self);
}
// This function is not actually called, but it is mentioned in a vtable in a function that is
// called. Make sure we still find this error.
2024-03-17 07:28:31 -05:00
// This ensures that we are properly considering vtables when gathering "mentioned" items.
impl<T> MyTrait for Vec<T> {
fn not_called(&self) {
if false {
let _ = Fail::<T>::C;
}
}
}
#[inline(never)]
fn called<T>() {
if false {
let v: Vec<T> = Vec::new();
2024-03-17 07:28:31 -05:00
let gen_vtable: &dyn MyTrait = &v; // vtable is "mentioned" here
}
}
pub fn main() {
called::<i32>();
}