summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_lint_defs/src/builtin.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_lint_defs/src/builtin.rs')
-rw-r--r--compiler/rustc_lint_defs/src/builtin.rs122
1 files changed, 73 insertions, 49 deletions
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs
index b6481d70b..46ec1a2dc 100644
--- a/compiler/rustc_lint_defs/src/builtin.rs
+++ b/compiler/rustc_lint_defs/src/builtin.rs
@@ -1188,51 +1188,6 @@ declare_lint! {
}
declare_lint! {
- /// The `unaligned_references` lint detects unaligned references to fields
- /// of [packed] structs.
- ///
- /// [packed]: https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
- ///
- /// ### Example
- ///
- /// ```rust,compile_fail
- /// #[repr(packed)]
- /// pub struct Foo {
- /// field1: u64,
- /// field2: u8,
- /// }
- ///
- /// fn main() {
- /// unsafe {
- /// let foo = Foo { field1: 0, field2: 0 };
- /// let _ = &foo.field1;
- /// println!("{}", foo.field1); // An implicit `&` is added here, triggering the lint.
- /// }
- /// }
- /// ```
- ///
- /// {{produces}}
- ///
- /// ### Explanation
- ///
- /// Creating a reference to an insufficiently aligned packed field is [undefined behavior] and
- /// should be disallowed. Using an `unsafe` block does not change anything about this. Instead,
- /// the code should do a copy of the data in the packed field or use raw pointers and unaligned
- /// accesses. See [issue #82523] for more information.
- ///
- /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
- /// [issue #82523]: https://github.com/rust-lang/rust/issues/82523
- pub UNALIGNED_REFERENCES,
- Deny,
- "detects unaligned references to fields of packed structs",
- @future_incompatible = FutureIncompatibleInfo {
- reference: "issue #82523 <https://github.com/rust-lang/rust/issues/82523>",
- reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
- };
- report_in_external_macro
-}
-
-declare_lint! {
/// The `const_item_mutation` lint detects attempts to mutate a `const`
/// item.
///
@@ -3308,7 +3263,6 @@ declare_lint_pass! {
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
INVALID_TYPE_PARAM_DEFAULT,
RENAMED_AND_REMOVED_LINTS,
- UNALIGNED_REFERENCES,
CONST_ITEM_MUTATION,
PATTERNS_IN_FNS_WITHOUT_BODY,
MISSING_FRAGMENT_SPECIFIER,
@@ -3381,6 +3335,7 @@ declare_lint_pass! {
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
NAMED_ARGUMENTS_USED_POSITIONALLY,
IMPLIED_BOUNDS_ENTAILMENT,
+ BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
]
}
@@ -3531,9 +3486,15 @@ declare_lint! {
///
/// ### Explanation
///
- /// Previously, there were very like checks being performed on `#[doc(..)]`
- /// unlike the other attributes. It'll now catch all the issues that it
- /// silently ignored previously.
+ /// Previously, incorrect usage of the `#[doc(..)]` attribute was not
+ /// being validated. Usually these should be rejected as a hard error,
+ /// but this lint was introduced to avoid breaking any existing
+ /// crates which included them.
+ ///
+ /// This is a [future-incompatible] lint to transition this to a hard
+ /// error in the future. See [issue #82730] for more details.
+ ///
+ /// [issue #82730]: https://github.com/rust-lang/rust/issues/82730
pub INVALID_DOC_ATTRIBUTES,
Warn,
"detects invalid `#[doc(...)]` attributes",
@@ -4109,3 +4070,66 @@ declare_lint! {
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
};
}
+
+declare_lint! {
+ /// The `byte_slice_in_packed_struct_with_derive` lint detects cases where a byte slice field
+ /// (`[u8]`) or string slice field (`str`) is used in a `packed` struct that derives one or
+ /// more built-in traits.
+ ///
+ /// ### Example
+ ///
+ /// ```rust
+ /// #[repr(packed)]
+ /// #[derive(Hash)]
+ /// struct FlexZeroSlice {
+ /// width: u8,
+ /// data: [u8],
+ /// }
+ /// ```
+ ///
+ /// {{produces}}
+ ///
+ /// ### Explanation
+ ///
+ /// This was previously accepted but is being phased out, because fields in packed structs are
+ /// now required to implement `Copy` for `derive` to work. Byte slices and string slices are a
+ /// temporary exception because certain crates depended on them.
+ pub BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
+ Warn,
+ "`[u8]` or `str` used in a packed struct with `derive`",
+ @future_incompatible = FutureIncompatibleInfo {
+ reference: "issue #107457 <https://github.com/rust-lang/rust/issues/107457>",
+ reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
+ };
+ report_in_external_macro
+}
+
+declare_lint! {
+ /// The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments.
+ ///
+ /// ### Example
+ ///
+ /// ```rust,compile_fail
+ /// #![deny(invalid_macro_export_arguments)]
+ ///
+ /// #[macro_export(invalid_parameter)]
+ /// macro_rules! myMacro {
+ /// () => {
+ /// // [...]
+ /// }
+ /// }
+ ///
+ /// #[macro_export(too, many, items)]
+ /// ```
+ ///
+ /// {{produces}}
+ ///
+ /// ### Explanation
+ ///
+ /// The only valid argument is `#[macro_export(local_inner_macros)]` or no argument (`#[macro_export]`).
+ /// You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`.
+ ///
+ pub INVALID_MACRO_EXPORT_ARGUMENTS,
+ Warn,
+ "\"invalid_parameter\" isn't a valid argument for `#[macro_export]`",
+}