summaryrefslogtreecommitdiff
path: root/compiler/rustc_lint_defs
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-11-21 16:51:16 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-12-15 16:07:28 +0000
commitd66824dbc4fb74598251a89d7c3c5fb2df5afeba (patch)
tree14f9cf94e9a62acd51d8dc04d9e4df8f5cccd7d5 /compiler/rustc_lint_defs
parented71e32e1440765d3e133e9892d59ca130477cec (diff)
downloadrust-d66824dbc4fb74598251a89d7c3c5fb2df5afeba.tar.gz
Make alignment checks a future incompat lint
Diffstat (limited to 'compiler/rustc_lint_defs')
-rw-r--r--compiler/rustc_lint_defs/src/builtin.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs
index a3008e9e321..dddc200b2fb 100644
--- a/compiler/rustc_lint_defs/src/builtin.rs
+++ b/compiler/rustc_lint_defs/src/builtin.rs
@@ -1020,6 +1020,42 @@ declare_lint! {
}
declare_lint! {
+ /// The `invalid_alignment` lint detects dereferences of misaligned pointers during
+ /// constant evluation.
+ ///
+ /// ### Example
+ ///
+ /// ```rust,compile_fail
+ /// const FOO: () = unsafe {
+ /// let x = [0_u8; 10];
+ /// let y = x.as_ptr() as *const u32;
+ /// *y; // the address of a `u8` array is unknown and thus we don't know if
+ /// // it is aligned enough for reading a `u32`.
+ /// }
+ /// ```
+ ///
+ /// {{produces}}
+ ///
+ /// ### Explanation
+ ///
+ /// The compiler allowed dereferencing raw pointers irrespective of alignment
+ /// during const eval due to the const evaluator at the time not making it easy
+ /// or cheap to check. Now that it is both, this is not accepted anymore.
+ ///
+ /// Since it was undefined behaviour to begin with, this breakage does not violate
+ /// Rust's stability guarantees. Using undefined behaviour can cause arbitrary
+ /// behaviour, including failure to build.
+ ///
+ /// [future-incompatible]: ../index.md#future-incompatible-lints
+ pub INVALID_ALIGNMENT,
+ Deny,
+ "raw pointers must be aligned before dereferencing",
+ @future_incompatible = FutureIncompatibleInfo {
+ reference: "issue #68585 <https://github.com/rust-lang/rust/issues/104616>",
+ };
+}
+
+declare_lint! {
/// The `exported_private_dependencies` lint detects private dependencies
/// that are exposed in a public interface.
///