]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs
Rollup merge of #93813 - xldenis:public-mir-passes, r=wesleywiser
[rust.git] / src / test / ui / rfc-2632-const-trait-impl / const-drop-fail.rs
1 // revisions: stock precise
2 #![feature(const_trait_impl)]
3 #![feature(const_mut_refs)]
4 #![feature(const_fn_trait_bound)]
5 #![cfg_attr(precise, feature(const_precise_live_drops))]
6
7 use std::marker::PhantomData;
8
9 struct NonTrivialDrop;
10
11 impl Drop for NonTrivialDrop {
12     fn drop(&mut self) {
13         println!("Non trivial drop");
14     }
15 }
16
17 struct ConstImplWithDropGlue(NonTrivialDrop);
18
19 impl const Drop for ConstImplWithDropGlue {
20     fn drop(&mut self) {}
21 }
22
23 trait A { fn a() { println!("A"); } }
24
25 impl A for NonTrivialDrop {}
26
27 struct ConstDropImplWithBounds<T: A>(PhantomData<T>);
28
29 impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
30     fn drop(&mut self) {
31         T::a();
32     }
33 }
34
35 const fn check<T: ~const Drop>(_: T) {}
36
37 macro_rules! check_all {
38     ($($exp:expr),*$(,)?) => {$(
39         const _: () = check($exp);
40     )*};
41 }
42
43 check_all! {
44     NonTrivialDrop,
45     //~^ ERROR the trait bound
46     ConstImplWithDropGlue(NonTrivialDrop),
47     //~^ ERROR the trait bound
48     ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
49     //~^ ERROR the trait bound
50 }
51
52 fn main() {}