check non_exhaustive attr and private fields for transparent types
This commit is contained in:
parent
b3f4c31199
commit
944c0e23b8
5 changed files with 254 additions and 5 deletions
|
@ -3132,6 +3132,56 @@ declare_lint! {
|
|||
"detects unexpected names and values in `#[cfg]` conditions",
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
/// The `repr_transparent_external_private_fields` lint
|
||||
/// detects types marked #[repr(trasparent)] that (transitively)
|
||||
/// contain an external ZST type marked #[non_exhaustive]
|
||||
///
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust,ignore (needs external crate)
|
||||
/// #![deny(repr_transparent_external_private_fields)]
|
||||
/// use foo::NonExhaustiveZst;
|
||||
///
|
||||
/// #[repr(transparent)]
|
||||
/// struct Bar(u32, ([u32; 0], NonExhaustiveZst));
|
||||
/// ```
|
||||
///
|
||||
/// This will produce:
|
||||
///
|
||||
/// ```text
|
||||
/// error: deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
|
||||
/// --> src/main.rs:3:1
|
||||
/// |
|
||||
/// 3 | #[macro_use]
|
||||
/// | ^^^^^^^^^^^^
|
||||
/// |
|
||||
/// note: the lint level is defined here
|
||||
/// --> src/main.rs:1:9
|
||||
/// |
|
||||
/// 1 | #![deny(repr_transparent_external_private_fields)]
|
||||
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/// ```
|
||||
///
|
||||
/// ### Explanation
|
||||
///
|
||||
/// Previous, Rust accepted fields that contain external private zero-sized types,
|
||||
/// even though it should not be a breaking change to add a non-zero-sized field to
|
||||
/// that private type.
|
||||
///
|
||||
/// This is a [future-incompatible] lint to transition this
|
||||
/// to a hard error in the future. See [issue #78586] for more details.
|
||||
///
|
||||
/// [issue #78586]: https://github.com/rust-lang/rust/issues/78586
|
||||
/// [future-incompatible]: ../index.md#future-incompatible-lints
|
||||
pub REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
|
||||
Warn,
|
||||
"tranparent type contains an external ZST that is marked #[non_exhaustive] or contains private fields",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reference: "issue #78586 <https://github.com/rust-lang/rust/issues/78586>",
|
||||
};
|
||||
}
|
||||
|
||||
declare_lint_pass! {
|
||||
/// Does nothing as a lint pass, but registers some `Lint`s
|
||||
/// that are used by other parts of the compiler.
|
||||
|
@ -3237,6 +3287,7 @@ declare_lint_pass! {
|
|||
DEPRECATED_WHERE_CLAUSE_LOCATION,
|
||||
TEST_UNSTABLE_LINT,
|
||||
FFI_UNWIND_CALLS,
|
||||
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue