forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#129235 - GoldsteinE:check-may-dangle, r=com…
…piler-errors Check that `#[may_dangle]` is properly applied It's only valid when applied to a type or lifetime parameter in `Drop` trait implementation. Tracking issue: rust-lang#34761 cc rust-lang#34761 (comment)
- Loading branch information
Showing
7 changed files
with
142 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#![feature(dropck_eyepatch)] | ||
|
||
struct Implee1<'a, T, const N: usize>(&'a T); | ||
struct Implee2<'a, T, const N: usize>(&'a T); | ||
struct Implee3<'a, T, const N: usize>(&'a T); | ||
trait NotDrop {} | ||
|
||
unsafe impl<#[may_dangle] 'a, T, const N: usize> NotDrop for Implee1<'a, T, N> {} | ||
//~^ ERROR must be applied to a lifetime or type generic parameter in `Drop` impl | ||
|
||
unsafe impl<'a, #[may_dangle] T, const N: usize> NotDrop for Implee2<'a, T, N> {} | ||
//~^ ERROR must be applied to a lifetime or type generic parameter in `Drop` impl | ||
|
||
unsafe impl<'a, T, #[may_dangle] const N: usize> Drop for Implee1<'a, T, N> { | ||
//~^ ERROR must be applied to a lifetime or type generic parameter in `Drop` impl | ||
fn drop(&mut self) {} | ||
} | ||
|
||
// Ok, lifetime param in a `Drop` impl. | ||
unsafe impl<#[may_dangle] 'a, T, const N: usize> Drop for Implee2<'a, T, N> { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
// Ok, type param in a `Drop` impl. | ||
unsafe impl<'a, #[may_dangle] T, const N: usize> Drop for Implee3<'a, T, N> { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
// Check that this check is not textual. | ||
mod fake { | ||
trait Drop { | ||
fn drop(&mut self); | ||
} | ||
struct Implee<T>(T); | ||
|
||
unsafe impl<#[may_dangle] T> Drop for Implee<T> { | ||
//~^ ERROR must be applied to a lifetime or type generic parameter in `Drop` impl | ||
fn drop(&mut self) {} | ||
} | ||
} | ||
|
||
#[may_dangle] //~ ERROR must be applied to a lifetime or type generic parameter in `Drop` impl | ||
struct Dangling; | ||
|
||
#[may_dangle] //~ ERROR must be applied to a lifetime or type generic parameter in `Drop` impl | ||
impl NotDrop for () { | ||
} | ||
|
||
#[may_dangle] //~ ERROR must be applied to a lifetime or type generic parameter in `Drop` impl | ||
fn main() { | ||
#[may_dangle] //~ ERROR must be applied to a lifetime or type generic parameter in `Drop` impl | ||
let () = (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
error: `#[may_dangle]` must be applied to a lifetime or type generic parameter in `Drop` impl | ||
--> $DIR/may_dangle.rs:8:13 | ||
| | ||
LL | unsafe impl<#[may_dangle] 'a, T, const N: usize> NotDrop for Implee1<'a, T, N> {} | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: `#[may_dangle]` must be applied to a lifetime or type generic parameter in `Drop` impl | ||
--> $DIR/may_dangle.rs:11:17 | ||
| | ||
LL | unsafe impl<'a, #[may_dangle] T, const N: usize> NotDrop for Implee2<'a, T, N> {} | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: `#[may_dangle]` must be applied to a lifetime or type generic parameter in `Drop` impl | ||
--> $DIR/may_dangle.rs:14:20 | ||
| | ||
LL | unsafe impl<'a, T, #[may_dangle] const N: usize> Drop for Implee1<'a, T, N> { | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: `#[may_dangle]` must be applied to a lifetime or type generic parameter in `Drop` impl | ||
--> $DIR/may_dangle.rs:42:1 | ||
| | ||
LL | #[may_dangle] | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: `#[may_dangle]` must be applied to a lifetime or type generic parameter in `Drop` impl | ||
--> $DIR/may_dangle.rs:45:1 | ||
| | ||
LL | #[may_dangle] | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: `#[may_dangle]` must be applied to a lifetime or type generic parameter in `Drop` impl | ||
--> $DIR/may_dangle.rs:49:1 | ||
| | ||
LL | #[may_dangle] | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: `#[may_dangle]` must be applied to a lifetime or type generic parameter in `Drop` impl | ||
--> $DIR/may_dangle.rs:51:5 | ||
| | ||
LL | #[may_dangle] | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: `#[may_dangle]` must be applied to a lifetime or type generic parameter in `Drop` impl | ||
--> $DIR/may_dangle.rs:36:17 | ||
| | ||
LL | unsafe impl<#[may_dangle] T> Drop for Implee<T> { | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 8 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
error: `must_not_suspend` attribute should be applied to a struct, enum, or trait | ||
error: `must_not_suspend` attribute should be applied to a struct, enum, union, or trait | ||
--> $DIR/other_items.rs:5:1 | ||
| | ||
LL | #[must_not_suspend] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
LL | mod inner {} | ||
| ------------ is not a struct, enum, or trait | ||
| ------------ is not a struct, enum, union, or trait | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
error: `must_not_suspend` attribute should be applied to a struct, enum, or trait | ||
error: `must_not_suspend` attribute should be applied to a struct, enum, union, or trait | ||
--> $DIR/return.rs:5:1 | ||
| | ||
LL | #[must_not_suspend] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
LL | / fn foo() -> i32 { | ||
LL | | 0 | ||
LL | | } | ||
| |_- is not a struct, enum, or trait | ||
| |_- is not a struct, enum, union, or trait | ||
|
||
error: aborting due to 1 previous error | ||
|