diff options
| author | bors <bors@rust-lang.org> | 2023-01-31 22:34:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-01-31 22:34:26 +0000 |
| commit | 5b6ed253c42a69b93e7447fb0874a89ab6bc1cfb (patch) | |
| tree | ba7e23c105713658431c3101d22977d8282e397f /compiler/rustc_mir_transform/src | |
| parent | dc1d9d50fba2f6a1ccab8748a0050cde38253f60 (diff) | |
| parent | dfc4a7b2d02528f246e455f587605cce224bb99c (diff) | |
| download | rust-5b6ed253c42a69b93e7447fb0874a89ab6bc1cfb.tar.gz rust-5b6ed253c42a69b93e7447fb0874a89ab6bc1cfb.zip | |
Auto merge of #102513 - RalfJung:no-more-unaligned-reference, r=cjgillot,scottmcm
make unaligned_reference a hard error The `unaligned_references` lint has been warn-by-default since Rust 1.53 (https://github.com/rust-lang/rust/pull/82525) and deny-by-default with mention in cargo future-incompat reports since Rust 1.62 (https://github.com/rust-lang/rust/pull/95372). Current nightly will become Rust 1.66, so (unless major surprises show up with crater) I think it is time we make this a hard error, and close this old soundness gap in the language. EDIT: Turns out this will only land for Rust 1.67, so there is another 6 weeks of time here for crates to adjust. Fixes https://github.com/rust-lang/rust/issues/82523.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/check_packed_ref.rs | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/compiler/rustc_mir_transform/src/check_packed_ref.rs b/compiler/rustc_mir_transform/src/check_packed_ref.rs index 3e7571aa7a2..9dc8dba23a4 100644 --- a/compiler/rustc_mir_transform/src/check_packed_ref.rs +++ b/compiler/rustc_mir_transform/src/check_packed_ref.rs @@ -1,7 +1,7 @@ +use rustc_errors::struct_span_err; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::{self, TyCtxt}; -use rustc_session::lint::builtin::UNALIGNED_REFERENCES; use crate::util; use crate::MirLint; @@ -49,31 +49,22 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> { // shouldn't do. unreachable!(); } else { - let source_info = self.source_info; - let lint_root = self.body.source_scopes[source_info.scope] - .local_data - .as_ref() - .assert_crate_local() - .lint_root; - self.tcx.struct_span_lint_hir( - UNALIGNED_REFERENCES, - lint_root, - source_info.span, - "reference to packed field is unaligned", - |lint| { - lint - .note( - "fields of packed structs are not properly aligned, and creating \ - a misaligned reference is undefined behavior (even if that \ - reference is never dereferenced)", - ) - .help( - "copy the field contents to a local variable, or replace the \ - reference with a raw pointer and use `read_unaligned`/`write_unaligned` \ - (loads and stores via `*p` must be properly aligned even when using raw pointers)" - ) - }, - ); + struct_span_err!( + self.tcx.sess, + self.source_info.span, + E0793, + "reference to packed field is unaligned" + ) + .note( + "fields of packed structs are not properly aligned, and creating \ + a misaligned reference is undefined behavior (even if that \ + reference is never dereferenced)", + ).help( + "copy the field contents to a local variable, or replace the \ + reference with a raw pointer and use `read_unaligned`/`write_unaligned` \ + (loads and stores via `*p` must be properly aligned even when using raw pointers)" + ) + .emit(); } } } |
