-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Reject SmartPointer constructions not serving the purpose #127283
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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,45 @@ | ||
#![feature(derive_smart_pointer, arbitrary_self_types)] | ||
|
||
use std::marker::SmartPointer; | ||
|
||
#[derive(SmartPointer)] | ||
//~^ ERROR: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` | ||
enum NotStruct<'a, T: ?Sized> { | ||
Variant(&'a T), | ||
} | ||
|
||
#[derive(SmartPointer)] | ||
//~^ ERROR: At least one generic type should be designated as `#[pointee]` in order to derive `SmartPointer` traits | ||
#[repr(transparent)] | ||
struct NoPointee<'a, T: ?Sized> { | ||
ptr: &'a T, | ||
} | ||
|
||
#[derive(SmartPointer)] | ||
//~^ ERROR: `SmartPointer` can only be derived on `struct`s with at least one field | ||
#[repr(transparent)] | ||
struct NoField<'a, #[pointee] T: ?Sized> {} | ||
//~^ ERROR: lifetime parameter `'a` is never used | ||
//~| ERROR: type parameter `T` is never used | ||
|
||
#[derive(SmartPointer)] | ||
//~^ ERROR: `SmartPointer` can only be derived on `struct`s with at least one field | ||
#[repr(transparent)] | ||
struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); | ||
//~^ ERROR: lifetime parameter `'a` is never used | ||
//~| ERROR: type parameter `T` is never used | ||
|
||
#[derive(SmartPointer)] | ||
//~^ ERROR: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` | ||
struct NotTransparent<'a, #[pointee] T: ?Sized> { | ||
ptr: &'a T, | ||
} | ||
|
||
// However, reordering attributes should work nevertheless. | ||
#[repr(transparent)] | ||
#[derive(SmartPointer)] | ||
struct ThisIsAPossibleSmartPointer<'a, #[pointee] T: ?Sized> { | ||
ptr: &'a T, | ||
} | ||
|
||
fn main() {} |
This file contains hidden or 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,75 @@ | ||
error: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` | ||
--> $DIR/deriving-smart-pointer-neg.rs:5:10 | ||
| | ||
LL | #[derive(SmartPointer)] | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: At least one generic type should be designated as `#[pointee]` in order to derive `SmartPointer` traits | ||
--> $DIR/deriving-smart-pointer-neg.rs:11:10 | ||
| | ||
LL | #[derive(SmartPointer)] | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: `SmartPointer` can only be derived on `struct`s with at least one field | ||
--> $DIR/deriving-smart-pointer-neg.rs:18:10 | ||
| | ||
LL | #[derive(SmartPointer)] | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: `SmartPointer` can only be derived on `struct`s with at least one field | ||
--> $DIR/deriving-smart-pointer-neg.rs:25:10 | ||
| | ||
LL | #[derive(SmartPointer)] | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: `SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]` | ||
--> $DIR/deriving-smart-pointer-neg.rs:32:10 | ||
| | ||
LL | #[derive(SmartPointer)] | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: this error originates in the derive macro `SmartPointer` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0392]: lifetime parameter `'a` is never used | ||
--> $DIR/deriving-smart-pointer-neg.rs:21:16 | ||
| | ||
LL | struct NoField<'a, #[pointee] T: ?Sized> {} | ||
| ^^ unused lifetime parameter | ||
| | ||
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` | ||
|
||
error[E0392]: type parameter `T` is never used | ||
--> $DIR/deriving-smart-pointer-neg.rs:21:31 | ||
| | ||
LL | struct NoField<'a, #[pointee] T: ?Sized> {} | ||
| ^ unused type parameter | ||
| | ||
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` | ||
|
||
error[E0392]: lifetime parameter `'a` is never used | ||
--> $DIR/deriving-smart-pointer-neg.rs:28:20 | ||
| | ||
LL | struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); | ||
| ^^ unused lifetime parameter | ||
| | ||
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` | ||
|
||
error[E0392]: type parameter `T` is never used | ||
--> $DIR/deriving-smart-pointer-neg.rs:28:35 | ||
| | ||
LL | struct NoFieldUnit<'a, #[pointee] T: ?Sized>(); | ||
| ^ unused type parameter | ||
| | ||
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` | ||
|
||
error: aborting due to 9 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0392`. |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.