forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check non_exhaustive attr and private fields for transparent types
- Loading branch information
Showing
5 changed files
with
254 additions
and
5 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
10 changes: 10 additions & 0 deletions
10
src/test/ui/repr/auxiliary/repr-transparent-non-exhaustive.rs
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,10 @@ | ||
#![crate_type = "lib"] | ||
|
||
pub struct Private { _priv: () } | ||
|
||
#[non_exhaustive] | ||
pub struct NonExhaustive {} | ||
|
||
pub struct ExternalIndirection<T> { | ||
pub x: T, | ||
} |
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,60 @@ | ||
#![deny(repr_transparent_external_private_fields)] | ||
|
||
// aux-build: repr-transparent-non-exhaustive.rs | ||
extern crate repr_transparent_non_exhaustive; | ||
|
||
use repr_transparent_non_exhaustive::{Private, NonExhaustive, ExternalIndirection}; | ||
|
||
pub struct InternalPrivate { | ||
_priv: (), | ||
} | ||
|
||
#[non_exhaustive] | ||
pub struct InternalNonExhaustive; | ||
|
||
pub struct InternalIndirection<T> { | ||
x: T, | ||
} | ||
|
||
pub type Sized = i32; | ||
|
||
#[repr(transparent)] | ||
pub struct T1(Sized, InternalPrivate); | ||
#[repr(transparent)] | ||
pub struct T2(Sized, InternalNonExhaustive); | ||
#[repr(transparent)] | ||
pub struct T3(Sized, InternalIndirection<(InternalPrivate, InternalNonExhaustive)>); | ||
#[repr(transparent)] | ||
pub struct T4(Sized, ExternalIndirection<(InternalPrivate, InternalNonExhaustive)>); | ||
|
||
#[repr(transparent)] | ||
pub struct T5(Sized, Private); | ||
//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
//~| WARN this was previously accepted by the compiler | ||
|
||
#[repr(transparent)] | ||
pub struct T6(Sized, NonExhaustive); | ||
//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
//~| WARN this was previously accepted by the compiler | ||
|
||
#[repr(transparent)] | ||
pub struct T7(Sized, InternalIndirection<Private>); | ||
//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
//~| WARN this was previously accepted by the compiler | ||
|
||
#[repr(transparent)] | ||
pub struct T8(Sized, InternalIndirection<NonExhaustive>); | ||
//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
//~| WARN this was previously accepted by the compiler | ||
|
||
#[repr(transparent)] | ||
pub struct T9(Sized, ExternalIndirection<Private>); | ||
//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
//~| WARN this was previously accepted by the compiler | ||
|
||
#[repr(transparent)] | ||
pub struct T10(Sized, ExternalIndirection<NonExhaustive>); | ||
//~^ ERROR zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
//~| WARN this was previously accepted by the compiler | ||
|
||
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,67 @@ | ||
error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
--> $DIR/repr-transparent-non-exhaustive.rs:31:22 | ||
| | ||
LL | pub struct T5(Sized, Private); | ||
| ^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/repr-transparent-non-exhaustive.rs:1:9 | ||
| | ||
LL | #![deny(repr_transparent_external_private_fields)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> | ||
= note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future. | ||
|
||
error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
--> $DIR/repr-transparent-non-exhaustive.rs:36:22 | ||
| | ||
LL | pub struct T6(Sized, NonExhaustive); | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> | ||
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future. | ||
|
||
error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
--> $DIR/repr-transparent-non-exhaustive.rs:41:22 | ||
| | ||
LL | pub struct T7(Sized, InternalIndirection<Private>); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> | ||
= note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future. | ||
|
||
error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
--> $DIR/repr-transparent-non-exhaustive.rs:46:22 | ||
| | ||
LL | pub struct T8(Sized, InternalIndirection<NonExhaustive>); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> | ||
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future. | ||
|
||
error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
--> $DIR/repr-transparent-non-exhaustive.rs:51:22 | ||
| | ||
LL | pub struct T9(Sized, ExternalIndirection<Private>); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> | ||
= note: this struct contains `Private`, which contains private fields, and makes it not a breaking change to become non-zero-sized in the future. | ||
|
||
error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types | ||
--> $DIR/repr-transparent-non-exhaustive.rs:56:23 | ||
| | ||
LL | pub struct T10(Sized, ExternalIndirection<NonExhaustive>); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586> | ||
= note: this struct contains `NonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future. | ||
|
||
error: aborting due to 6 previous errors | ||
|