-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check that #[may_dangle]
is properly applied
#129235
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leads to somewhat ugly formatting:
I think the current version is nicer, but I don’t feel that strong about it, so I can make this change if you prefer it.