]> git.lizzy.rs Git - rust.git/blob - tests/ui/rfc-2632-const-trait-impl/const-drop-fail.rs
Rollup merge of #106661 - mjguzik:linux_statx, r=Mark-Simulacrum
[rust.git] / tests / 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 #![cfg_attr(precise, feature(const_precise_live_drops))]
5
6 use std::marker::{Destruct, PhantomData};
7
8 struct NonTrivialDrop;
9
10 impl Drop for NonTrivialDrop {
11     fn drop(&mut self) {
12         println!("Non trivial drop");
13     }
14 }
15
16 struct ConstImplWithDropGlue(NonTrivialDrop);
17
18 impl const Drop for ConstImplWithDropGlue {
19     fn drop(&mut self) {}
20 }
21
22 #[const_trait]
23 trait A { fn a() { } }
24
25 impl A for NonTrivialDrop {}
26
27 struct ConstDropImplWithBounds<T: ~const 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 Destruct>(_: T) {}
36
37 macro_rules! check_all {
38     ($($exp:expr),*$(,)?) => {$(
39         const _: () = check($exp);
40     )*};
41 }
42
43 check_all! {
44     NonTrivialDrop,
45     //~^ ERROR can't drop
46     ConstImplWithDropGlue(NonTrivialDrop),
47     //~^ ERROR can't drop
48     ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
49     //~^ ERROR the trait bound
50     //~| ERROR the trait bound
51 }
52
53 struct ConstDropImplWithNonConstBounds<T: A>(PhantomData<T>);
54
55 impl<T: ~const A> const Drop for ConstDropImplWithNonConstBounds<T> {
56 //~^ ERROR `Drop` impl requires `T: ~const A` but the struct it is implemented for does not
57     fn drop(&mut self) {
58         T::a();
59     }
60 }
61
62 fn main() {}