]> git.lizzy.rs Git - rust.git/blob - tests/ui/dropck/dropck-eyepatch-implies-unsafe-impl.rs
Rollup merge of #106446 - bzEq:fix-unwind-lsda, r=Amanieu
[rust.git] / tests / ui / dropck / dropck-eyepatch-implies-unsafe-impl.rs
1 #![feature(dropck_eyepatch)]
2
3 // This test ensures that a use of `#[may_dangle]` is rejected if
4 // it is not attached to an `unsafe impl`.
5
6 use std::fmt;
7
8 struct Dt<A: fmt::Debug>(&'static str, A);
9 struct Dr<'a, B:'a+fmt::Debug>(&'static str, &'a B);
10 struct Pt<A,B: fmt::Debug>(&'static str, A, B);
11 struct Pr<'a, 'b, B:'a+'b+fmt::Debug>(&'static str, &'a B, &'b B);
12 struct St<A: fmt::Debug>(&'static str, A);
13 struct Sr<'a, B:'a+fmt::Debug>(&'static str, &'a B);
14
15 impl<A: fmt::Debug> Drop for Dt<A> {
16     fn drop(&mut self) { println!("drop {} {:?}", self.0, self.1); }
17 }
18 impl<'a, B: fmt::Debug> Drop for Dr<'a, B> {
19     fn drop(&mut self) { println!("drop {} {:?}", self.0, self.1); }
20 }
21 impl<#[may_dangle] A, B: fmt::Debug> Drop for Pt<A, B> {
22     //~^ ERROR requires an `unsafe impl` declaration due to `#[may_dangle]` attribute
23
24     // (unsafe to access self.1  due to #[may_dangle] on A)
25     fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
26 }
27 impl<#[may_dangle] 'a, 'b, B: fmt::Debug> Drop for Pr<'a, 'b, B> {
28     //~^ ERROR requires an `unsafe impl` declaration due to `#[may_dangle]` attribute
29
30     // (unsafe to access self.1 due to #[may_dangle] on 'a)
31     fn drop(&mut self) { println!("drop {} {:?}", self.0, self.2); }
32 }
33
34 fn main() {
35 }