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#127283 - dingxiangfei2009:check-repr-transp…
…arent, r=davidtwco Reject SmartPointer constructions not serving the purpose Tracking issue: rust-lang#123430 With this PR we will reject a row of malformed `SmartPointer` implementor candidates. cc `@Darksonn` `@davidtwco` for context.
- Loading branch information
Showing
6 changed files
with
159 additions
and
4 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
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 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 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