]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs
3d4de088f5530f02cd9b8235160281c9192adb00
[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: ~const A>(PhantomData<T>);
28 //~^ ERROR `~const` is not allowed
29
30 impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
31     fn drop(&mut self) {
32         T::a();
33     }
34 }
35
36 const fn check<T: ~const Drop>(_: T) {}
37
38 macro_rules! check_all {
39     ($($exp:expr),*$(,)?) => {$(
40         const _: () = check($exp);
41     )*};
42 }
43
44 check_all! {
45     NonTrivialDrop,
46     //~^ ERROR the trait bound
47     ConstImplWithDropGlue(NonTrivialDrop),
48     //~^ ERROR the trait bound
49     ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
50     //~^ ERROR the trait bound
51     //~| ERROR the trait bound
52 }
53
54 fn main() {}