]> git.lizzy.rs Git - rust.git/commitdiff
make unaligned_reference a hard error
authorRalf Jung <post@ralfj.de>
Fri, 30 Sep 2022 12:54:30 +0000 (14:54 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 31 Jan 2023 19:28:11 +0000 (20:28 +0100)
27 files changed:
compiler/rustc_error_codes/src/error_codes.rs
compiler/rustc_error_codes/src/error_codes/E0793.md [new file with mode: 0644]
compiler/rustc_lint/src/lib.rs
compiler/rustc_lint_defs/src/builtin.rs
compiler/rustc_mir_transform/src/check_packed_ref.rs
src/tools/miri/tests/fail/unaligned_pointers/reference_to_packed.rs
src/tools/miri/tests/fail/unaligned_pointers/reference_to_packed.stderr
tests/ui/binding/issue-53114-safety-checks.rs
tests/ui/binding/issue-53114-safety-checks.stderr
tests/ui/closures/2229_closure_analysis/diagnostics/repr_packed.rs
tests/ui/closures/2229_closure_analysis/diagnostics/repr_packed.stderr
tests/ui/derives/deriving-with-repr-packed-2.rs
tests/ui/derives/deriving-with-repr-packed-2.stderr
tests/ui/derives/deriving-with-repr-packed.rs
tests/ui/derives/deriving-with-repr-packed.stderr
tests/ui/lint/unaligned_references.rs
tests/ui/lint/unaligned_references.stderr
tests/ui/lint/unaligned_references_external_macro.rs
tests/ui/lint/unaligned_references_external_macro.stderr
tests/ui/packed/issue-27060-rpass.rs [deleted file]
tests/ui/packed/issue-27060-rpass.stderr [deleted file]
tests/ui/packed/issue-27060.rs
tests/ui/packed/issue-27060.stderr
tests/ui/packed/packed-struct-borrow-element-64bit.rs
tests/ui/packed/packed-struct-borrow-element-64bit.stderr
tests/ui/packed/packed-struct-borrow-element.rs
tests/ui/packed/packed-struct-borrow-element.stderr

index 4ae372bb90432cc86908ed3f41dc6d0b64982806..072b0f2fcceab7e4e357b10fe6f61f85358a66e0 100644 (file)
@@ -5,7 +5,7 @@
 // /!\ IMPORTANT /!\
 //
 // Error messages' format must follow the RFC 1567 available here:
-// https://github.com/rust-lang/rfcs/pull/1567
+// https://rust-lang.github.io/rfcs/1567-long-error-codes-explanation-normalization.html
 
 register_diagnostics! {
 E0001: include_str!("./error_codes/E0001.md"),
 E0790: include_str!("./error_codes/E0790.md"),
 E0791: include_str!("./error_codes/E0791.md"),
 E0792: include_str!("./error_codes/E0792.md"),
+E0793: include_str!("./error_codes/E0793.md"),
 ;
 //  E0006, // merged with E0005
 //  E0008, // cannot bind by-move into a pattern guard
diff --git a/compiler/rustc_error_codes/src/error_codes/E0793.md b/compiler/rustc_error_codes/src/error_codes/E0793.md
new file mode 100644 (file)
index 0000000..b2e51e2
--- /dev/null
@@ -0,0 +1,64 @@
+An unaligned references to a field of a [packed] struct got created.
+
+Erroneous code example:
+
+```compile_fail,E0793
+#[repr(packed)]
+pub struct Foo {
+    field1: u64,
+    field2: u8,
+}
+
+unsafe {
+    let foo = Foo { field1: 0, field2: 0 };
+    // Accessing the field directly is fine.
+    let val = foo.field1;
+    // A reference to a packed field causes a error.
+    let val = &foo.field1; // ERROR
+    // An implicit `&` is added in format strings, causing the same error.
+    println!("{}", foo.field1); // ERROR
+}
+```
+
+Creating a reference to an insufficiently aligned packed field is
+[undefined behavior] and therefore 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.
+
+```
+#[repr(packed)]
+pub struct Foo {
+    field1: u64,
+    field2: u8,
+}
+
+unsafe {
+    let foo = Foo { field1: 0, field2: 0 };
+
+    // Instead of a reference, we can create a raw pointer...
+    let ptr = std::ptr::addr_of!(foo.field1);
+    // ... and then (crucially!) access it in an explicitly unaligned way.
+    let val = unsafe { ptr.read_unaligned() };
+    // This would *NOT* be correct:
+    // let val = unsafe { *ptr }; // Undefined Behavior due to unaligned load!
+
+    // For formatting, we can create a copy to avoid the direct reference.
+    let copy = foo.field1;
+    println!("{}", copy);
+    // Creating a copy can be written in a single line with curly braces.
+    // (This is equivalent to the two lines above.)
+    println!("{}", { foo.field1 });
+}
+```
+
+### Additional information
+
+Note that this error is specifically about *references* to packed fields.
+Direct by-value access of those fields is fine, since then the compiler has
+enough information to generate the correct kind of access.
+
+See [issue #82523] for more information.
+
+[packed]: https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
+[undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
+[issue #82523]: https://github.com/rust-lang/rust/issues/82523
index ba15dbd86cfa4caff089c597a84391a69ff7a400..4ca37ef6850c11bcc0a0e351c1725f1c353c9278 100644 (file)
@@ -324,7 +324,6 @@ macro_rules! add_lint_group {
     store.register_renamed("exceeding_bitshifts", "arithmetic_overflow");
     store.register_renamed("redundant_semicolon", "redundant_semicolons");
     store.register_renamed("overlapping_patterns", "overlapping_range_endpoints");
-    store.register_renamed("safe_packed_borrows", "unaligned_references");
     store.register_renamed("disjoint_capture_migration", "rust_2021_incompatible_closure_captures");
     store.register_renamed("or_patterns_back_compat", "rust_2021_incompatible_or_patterns");
     store.register_renamed("non_fmt_panic", "non_fmt_panics");
@@ -487,6 +486,16 @@ macro_rules! add_lint_group {
         "converted into hard error, see issue #71800 \
          <https://github.com/rust-lang/rust/issues/71800> for more information",
     );
+    store.register_removed(
+        "safe_packed_borrows",
+        "converted into hard error, see issue #82523 \
+         <https://github.com/rust-lang/rust/issues/82523> for more information",
+    );
+    store.register_removed(
+        "unaligned_references",
+        "converted into hard error, see issue #82523 \
+         <https://github.com/rust-lang/rust/issues/82523> for more information",
+    );
 }
 
 fn register_internals(store: &mut LintStore) {
index d731c10f46e28efec1f5659cfecfc75b43b339a5..7e9ba4cd22b8d8132f62ad6158678df3b74ad2a8 100644 (file)
     "lints that have been renamed or removed"
 }
 
-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.
         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,
index 3e7571aa7a2e7f303fa0e02cc6fbd1f51f7906ac..9dc8dba23a4ec04e215d7eb44aff2f382ee0b3e8 100644 (file)
@@ -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 @@ fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location:
                     // 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();
                 }
             }
         }
index a807200771d62c087c51e9035a8fa5d50bc30f31..816b6ab9fb32f307a66270e8c27153da9d2c3bae 100644 (file)
@@ -1,7 +1,9 @@
 // This should fail even without validation/SB
 //@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
 
-#![allow(dead_code, unused_variables, unaligned_references)]
+#![allow(dead_code, unused_variables)]
+
+use std::{ptr, mem};
 
 #[repr(packed)]
 struct Foo {
@@ -9,11 +11,16 @@ struct Foo {
     y: i32,
 }
 
+unsafe fn raw_to_ref<'a, T>(x: *const T) -> &'a T {
+    mem::transmute(x)
+}
+
 fn main() {
     // Try many times as this might work by chance.
     for _ in 0..20 {
         let foo = Foo { x: 42, y: 99 };
-        let p = &foo.x;
-        let i = *p; //~ERROR: alignment 4 is required
+        // There seem to be implicit reborrows, which make the error already appear here
+        let p: &i32 = unsafe { raw_to_ref(ptr::addr_of!(foo.x)) }; //~ERROR: alignment 4 is required
+        let i = *p;
     }
 }
index 6c2a3dca2deef732bda30071701489a75f62ba2c..7c246706dba5af1e8e9c4d07ef4560002b789c98 100644 (file)
@@ -1,8 +1,8 @@
 error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
   --> $DIR/reference_to_packed.rs:LL:CC
    |
-LL |         let i = *p;
-   |                 ^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
+LL |         let p: &i32 = unsafe { raw_to_ref(ptr::addr_of!(foo.x)) };
+   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
    |
    = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
    = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
index d0eb28c57141177fe2b2ea28a5824b1bd1bf0a60..e234db516c7da23987c4bc7c66dab524074f5696 100644 (file)
@@ -21,13 +21,11 @@ fn let_wild_gets_unsafe_field() {
     let u2 = U { a: I(1) };
     let p = P { a: &2, b: &3 };
     let _ = &p.b;  //~ ERROR    reference to packed field
-    //~^  WARN will become a hard error
     let _ = u1.a;  // #53114: should eventually signal error as well
     let _ = &u2.a; //~ ERROR  [E0133]
 
     // variation on above with `_` in substructure
     let (_,) = (&p.b,);  //~ ERROR     reference to packed field
-    //~^  WARN will become a hard error
     let (_,) = (u1.a,);  //~ ERROR   [E0133]
     let (_,) = (&u2.a,); //~ ERROR   [E0133]
 }
@@ -37,13 +35,11 @@ fn match_unsafe_field_to_wild() {
     let u2 = U { a: I(1) };
     let p = P { a: &2, b: &3 };
     match &p.b  { _ => { } } //~ ERROR     reference to packed field
-    //~^  WARN will become a hard error
     match u1.a  { _ => { } } //~ ERROR   [E0133]
     match &u2.a { _ => { } } //~ ERROR   [E0133]
 
     // variation on above with `_` in substructure
     match (&p.b,)  { (_,) => { } } //~ ERROR     reference to packed field
-    //~^  WARN will become a hard error
     match (u1.a,)  { (_,) => { } } //~ ERROR   [E0133]
     match (&u2.a,) { (_,) => { } } //~ ERROR   [E0133]
 }
index 57a065d6d4d2f1a6fc22b3a806764132e88a56c3..5c9d78772477883730bcd83e861cc5281496de37 100644 (file)
@@ -1,50 +1,41 @@
-error: reference to packed field is unaligned
+error[E0793]: reference to packed field is unaligned
   --> $DIR/issue-53114-safety-checks.rs:23:13
    |
 LL |     let _ = &p.b;
    |             ^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
-   = note: `#[deny(unaligned_references)]` on by default
 
-error: reference to packed field is unaligned
-  --> $DIR/issue-53114-safety-checks.rs:29:17
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/issue-53114-safety-checks.rs:28:17
    |
 LL |     let (_,) = (&p.b,);
    |                 ^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/issue-53114-safety-checks.rs:39:11
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/issue-53114-safety-checks.rs:37:11
    |
 LL |     match &p.b  { _ => { } }
    |           ^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/issue-53114-safety-checks.rs:45:12
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/issue-53114-safety-checks.rs:42:12
    |
 LL |     match (&p.b,)  { (_,) => { } }
    |            ^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
 error[E0133]: access to union field is unsafe and requires unsafe function or block
-  --> $DIR/issue-53114-safety-checks.rs:26:13
+  --> $DIR/issue-53114-safety-checks.rs:25:13
    |
 LL |     let _ = &u2.a;
    |             ^^^^^ access to union field
@@ -52,7 +43,7 @@ LL |     let _ = &u2.a;
    = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
 
 error[E0133]: access to union field is unsafe and requires unsafe function or block
-  --> $DIR/issue-53114-safety-checks.rs:31:17
+  --> $DIR/issue-53114-safety-checks.rs:29:17
    |
 LL |     let (_,) = (u1.a,);
    |                 ^^^^ access to union field
@@ -60,7 +51,7 @@ LL |     let (_,) = (u1.a,);
    = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
 
 error[E0133]: access to union field is unsafe and requires unsafe function or block
-  --> $DIR/issue-53114-safety-checks.rs:32:17
+  --> $DIR/issue-53114-safety-checks.rs:30:17
    |
 LL |     let (_,) = (&u2.a,);
    |                 ^^^^^ access to union field
@@ -68,7 +59,7 @@ LL |     let (_,) = (&u2.a,);
    = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
 
 error[E0133]: access to union field is unsafe and requires unsafe function or block
-  --> $DIR/issue-53114-safety-checks.rs:41:11
+  --> $DIR/issue-53114-safety-checks.rs:38:11
    |
 LL |     match u1.a  { _ => { } }
    |           ^^^^ access to union field
@@ -76,7 +67,7 @@ LL |     match u1.a  { _ => { } }
    = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
 
 error[E0133]: access to union field is unsafe and requires unsafe function or block
-  --> $DIR/issue-53114-safety-checks.rs:42:11
+  --> $DIR/issue-53114-safety-checks.rs:39:11
    |
 LL |     match &u2.a { _ => { } }
    |           ^^^^^ access to union field
@@ -84,7 +75,7 @@ LL |     match &u2.a { _ => { } }
    = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
 
 error[E0133]: access to union field is unsafe and requires unsafe function or block
-  --> $DIR/issue-53114-safety-checks.rs:47:12
+  --> $DIR/issue-53114-safety-checks.rs:43:12
    |
 LL |     match (u1.a,)  { (_,) => { } }
    |            ^^^^ access to union field
@@ -92,7 +83,7 @@ LL |     match (u1.a,)  { (_,) => { } }
    = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
 
 error[E0133]: access to union field is unsafe and requires unsafe function or block
-  --> $DIR/issue-53114-safety-checks.rs:48:12
+  --> $DIR/issue-53114-safety-checks.rs:44:12
    |
 LL |     match (&u2.a,) { (_,) => { } }
    |            ^^^^^ access to union field
@@ -101,56 +92,5 @@ LL |     match (&u2.a,) { (_,) => { } }
 
 error: aborting due to 11 previous errors
 
-For more information about this error, try `rustc --explain E0133`.
-Future incompatibility report: Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/issue-53114-safety-checks.rs:23:13
-   |
-LL |     let _ = &p.b;
-   |             ^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-   = note: `#[deny(unaligned_references)]` on by default
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/issue-53114-safety-checks.rs:29:17
-   |
-LL |     let (_,) = (&p.b,);
-   |                 ^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-   = note: `#[deny(unaligned_references)]` on by default
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/issue-53114-safety-checks.rs:39:11
-   |
-LL |     match &p.b  { _ => { } }
-   |           ^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-   = note: `#[deny(unaligned_references)]` on by default
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/issue-53114-safety-checks.rs:45:12
-   |
-LL |     match (&p.b,)  { (_,) => { } }
-   |            ^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-   = note: `#[deny(unaligned_references)]` on by default
-
+Some errors have detailed explanations: E0133, E0793.
+For more information about an error, try `rustc --explain E0133`.
index 1488f329648bb1c4149862a93d0bd288a79be357..c7ee90ea73fd68db967b1ea0b3ebf52f9e16c9e6 100644 (file)
@@ -20,7 +20,6 @@ struct Foo { x: String }
     let c = || {
         println!("{}", foo.x);
         //~^ ERROR: reference to packed field is unaligned
-        //~| WARNING: this was previously accepted by the compiler but is being phased out
         let _z = foo.x;
     };
 
index 508c4b911b70b6f57f7ae78b46c75e8bb904c966..9c2c434572ae59d5a3cd7015bf7daf31ac986159 100644 (file)
@@ -1,29 +1,13 @@
-error: reference to packed field is unaligned
+error[E0793]: reference to packed field is unaligned
   --> $DIR/repr_packed.rs:21:24
    |
 LL |         println!("{}", foo.x);
    |                        ^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
-   = note: `#[deny(unaligned_references)]` on by default
    = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to previous error
 
-Future incompatibility report: Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/repr_packed.rs:21:24
-   |
-LL |         println!("{}", foo.x);
-   |                        ^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-   = note: `#[deny(unaligned_references)]` on by default
-   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
-
+For more information about this error, try `rustc --explain E0793`.
index cbd7432fce4eef79529e3b62ca2dda5fbedda08e..79aca74dfd416f1b80ca6cc3f98fcdbe2c3953e9 100644 (file)
@@ -1,5 +1,3 @@
-#![deny(unaligned_references)]
-
 // Check that deriving certain builtin traits on certain packed structs cause
 // errors. To avoid potentially misaligned references, field copies must be
 // used, which involves adding `T: Copy` bounds.
index 83540739ee3d9391c7709548d33b90ff35b472ee..ab3646057a55cb240dc00f6a4bb0013aa4a8ad0b 100644 (file)
@@ -1,5 +1,5 @@
 error[E0599]: the method `clone` exists for struct `Foo<NonCopy>`, but its trait bounds were not satisfied
-  --> $DIR/deriving-with-repr-packed-2.rs:20:11
+  --> $DIR/deriving-with-repr-packed-2.rs:18:11
    |
 LL | pub struct Foo<T>(T, T, T);
    | -----------------
@@ -19,7 +19,7 @@ LL |     _ = x.clone();
 note: the following trait bounds were not satisfied:
       `NonCopy: Clone`
       `NonCopy: Copy`
-  --> $DIR/deriving-with-repr-packed-2.rs:7:16
+  --> $DIR/deriving-with-repr-packed-2.rs:5:16
    |
 LL | #[derive(Copy, Clone, Default, PartialEq, Eq)]
    |                ^^^^^ unsatisfied trait bound introduced in this `derive` macro
index eddf41f55536e4e7ecb5ceeff537a22fd7910b84..afa91da133dc0f0b862211777c837d3bb4564741 100644 (file)
@@ -1,5 +1,3 @@
-#![deny(unaligned_references)]
-
 // Check that deriving certain builtin traits on certain packed structs cause
 // errors. To avoid potentially misaligned references, field copies must be
 // used, which involves adding `T: Copy` bounds.
index 2cb2a696d9742ffe3357c0c7892ade4838bd01ff..7ed84af91bdc354d4a3eb14e6633c4f9e8040d1b 100644 (file)
@@ -1,5 +1,5 @@
 warning: byte slice in a packed struct that derives a built-in trait
-  --> $DIR/deriving-with-repr-packed.rs:33:5
+  --> $DIR/deriving-with-repr-packed.rs:31:5
    |
 LL | #[derive(Debug)]
    |          ----- in this derive macro expansion
@@ -14,7 +14,7 @@ LL |     data: [u8],
    = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error[E0507]: cannot move out of `self` which is behind a shared reference
-  --> $DIR/deriving-with-repr-packed.rs:24:10
+  --> $DIR/deriving-with-repr-packed.rs:22:10
    |
 LL | #[derive(Debug, Default)]
    |          ----- in this derive macro expansion
@@ -29,7 +29,7 @@ error: aborting due to previous error; 1 warning emitted
 For more information about this error, try `rustc --explain E0507`.
 Future incompatibility report: Future breakage diagnostic:
 warning: byte slice in a packed struct that derives a built-in trait
-  --> $DIR/deriving-with-repr-packed.rs:33:5
+  --> $DIR/deriving-with-repr-packed.rs:31:5
    |
 LL | #[derive(Debug)]
    |          ----- in this derive macro expansion
index e547f031a9cfdf9886a0d7ad7e384edd102e1c54..04b66885e8522cf0865bfd26444a56e8701483b0 100644 (file)
@@ -1,5 +1,3 @@
-#![deny(unaligned_references)]
-
 #[repr(packed)]
 pub struct Good {
     data: u64,
@@ -20,20 +18,14 @@ fn main() {
         let good = Good { data: 0, ptr: &0, data2: [0, 0], aligned: [0; 32] };
 
         let _ = &good.ptr; //~ ERROR reference to packed field
-        //~^ previously accepted
         let _ = &good.data; //~ ERROR reference to packed field
-        //~^ previously accepted
         // Error even when turned into raw pointer immediately.
         let _ = &good.data as *const _; //~ ERROR reference to packed field
-        //~^ previously accepted
         let _: *const _ = &good.data; //~ ERROR reference to packed field
-        //~^ previously accepted
         // Error on method call.
         let _ = good.data.clone(); //~ ERROR reference to packed field
-        //~^ previously accepted
         // Error for nested fields.
         let _ = &good.data2[0]; //~ ERROR reference to packed field
-        //~^ previously accepted
 
         let _ = &*good.ptr; // ok, behind a pointer
         let _ = &good.aligned; // ok, has align 1
@@ -43,7 +35,6 @@ fn main() {
     unsafe {
         let packed2 = Packed2 { x: 0, y: 0, z: 0 };
         let _ = &packed2.x; //~ ERROR reference to packed field
-        //~^ previously accepted
         let _ = &packed2.y; // ok, has align 2 in packed(2) struct
         let _ = &packed2.z; // ok, has align 1
     }
@@ -88,7 +79,6 @@ struct Wrapper2 {
             },
         );
         let _ref = &m1.1.a; //~ ERROR reference to packed field
-        //~^ previously accepted
 
         let m2 = Misalign(
             0,
@@ -98,6 +88,5 @@ struct Wrapper2 {
             },
         );
         let _ref = &m2.1.a; //~ ERROR reference to packed field
-        //~^ previously accepted
     }
 }
index 346f49b921e5c24a108a45128a67f3d14c6211b2..07b59464bdece1092962b48e8d0bd882c2bdb1ad 100644 (file)
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:22:17
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/unaligned_references.rs:20:17
    |
 LL |         let _ = &good.ptr;
    |                 ^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references.rs:1:9
-   |
-LL | #![deny(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
 
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:24:17
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/unaligned_references.rs:21:17
    |
 LL |         let _ = &good.data;
    |                 ^^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:27:17
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/unaligned_references.rs:23:17
    |
 LL |         let _ = &good.data as *const _;
    |                 ^^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:29:27
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/unaligned_references.rs:24:27
    |
 LL |         let _: *const _ = &good.data;
    |                           ^^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:32:17
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/unaligned_references.rs:26:17
    |
 LL |         let _ = good.data.clone();
    |                 ^^^^^^^^^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:35:17
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/unaligned_references.rs:28:17
    |
 LL |         let _ = &good.data2[0];
    |                 ^^^^^^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:45:17
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/unaligned_references.rs:37:17
    |
 LL |         let _ = &packed2.x;
    |                 ^^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:90:20
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/unaligned_references.rs:81:20
    |
 LL |         let _ref = &m1.1.a;
    |                    ^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:100:20
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/unaligned_references.rs:90:20
    |
 LL |         let _ref = &m2.1.a;
    |                    ^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
 error: aborting due to 9 previous errors
 
-Future incompatibility report: Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:22:17
-   |
-LL |         let _ = &good.ptr;
-   |                 ^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references.rs:1:9
-   |
-LL | #![deny(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:24:17
-   |
-LL |         let _ = &good.data;
-   |                 ^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references.rs:1:9
-   |
-LL | #![deny(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:27:17
-   |
-LL |         let _ = &good.data as *const _;
-   |                 ^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references.rs:1:9
-   |
-LL | #![deny(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:29:27
-   |
-LL |         let _: *const _ = &good.data;
-   |                           ^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references.rs:1:9
-   |
-LL | #![deny(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:32:17
-   |
-LL |         let _ = good.data.clone();
-   |                 ^^^^^^^^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references.rs:1:9
-   |
-LL | #![deny(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:35:17
-   |
-LL |         let _ = &good.data2[0];
-   |                 ^^^^^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references.rs:1:9
-   |
-LL | #![deny(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:45:17
-   |
-LL |         let _ = &packed2.x;
-   |                 ^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references.rs:1:9
-   |
-LL | #![deny(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:90:20
-   |
-LL |         let _ref = &m1.1.a;
-   |                    ^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references.rs:1:9
-   |
-LL | #![deny(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references.rs:100:20
-   |
-LL |         let _ref = &m2.1.a;
-   |                    ^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references.rs:1:9
-   |
-LL | #![deny(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
+For more information about this error, try `rustc --explain E0793`.
index cb597c38e779283a8ce6cf996ef18644f56bb2ae..b655a2a8f63a22086d756f994cbd917848614115 100644 (file)
@@ -3,7 +3,6 @@
 extern crate unaligned_references_external_crate;
 
 unaligned_references_external_crate::mac! { //~ERROR reference to packed field is unaligned
-    //~^ previously accepted
     #[repr(packed)]
     pub struct X {
         pub field: u16
index c46ca6742a50f528f06a5edf948e0200fd20f48d..5b08f433e32809ed521c823f9562257647ddac88 100644 (file)
@@ -1,8 +1,7 @@
-error: reference to packed field is unaligned
+error[E0793]: reference to packed field is unaligned
   --> $DIR/unaligned_references_external_macro.rs:5:1
    |
 LL | / unaligned_references_external_crate::mac! {
-LL | |
 LL | |     #[repr(packed)]
 LL | |     pub struct X {
 LL | |         pub field: u16
@@ -10,52 +9,10 @@ LL | |     }
 LL | | }
    | |_^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references_external_macro.rs:5:1
-   |
-LL | / unaligned_references_external_crate::mac! {
-LL | |
-LL | |     #[repr(packed)]
-LL | |     pub struct X {
-LL | |         pub field: u16
-LL | |     }
-LL | | }
-   | |_^
    = note: this error originates in the macro `unaligned_references_external_crate::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to previous error
 
-Future incompatibility report: Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/unaligned_references_external_macro.rs:5:1
-   |
-LL | / unaligned_references_external_crate::mac! {
-LL | |
-LL | |     #[repr(packed)]
-LL | |     pub struct X {
-LL | |         pub field: u16
-LL | |     }
-LL | | }
-   | |_^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/unaligned_references_external_macro.rs:5:1
-   |
-LL | / unaligned_references_external_crate::mac! {
-LL | |
-LL | |     #[repr(packed)]
-LL | |     pub struct X {
-LL | |         pub field: u16
-LL | |     }
-LL | | }
-   | |_^
-   = note: this error originates in the macro `unaligned_references_external_crate::mac` (in Nightly builds, run with -Z macro-backtrace for more info)
-
+For more information about this error, try `rustc --explain E0793`.
diff --git a/tests/ui/packed/issue-27060-rpass.rs b/tests/ui/packed/issue-27060-rpass.rs
deleted file mode 100644 (file)
index d9159f6..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-// run-pass
-#![allow(dead_code)]
-#[repr(packed)]
-pub struct Good {
-    data: &'static u32,
-    data2: [&'static u32; 2],
-    aligned: [u8; 32],
-}
-
-// kill this test when that turns to a hard error
-#[allow(unaligned_references)]
-fn main() {
-    let good = Good { data: &0, data2: [&0, &0], aligned: [0; 32] };
-
-    let _ = &good.data; // ok
-    let _ = &good.data2[0]; // ok
-
-    let _ = &good.data;
-    let _ = &good.data2[0];
-    let _ = &*good.data; // ok, behind a pointer
-    let _ = &good.aligned; // ok, has align 1
-    let _ = &good.aligned[2]; // ok, has align 1
-}
diff --git a/tests/ui/packed/issue-27060-rpass.stderr b/tests/ui/packed/issue-27060-rpass.stderr
deleted file mode 100644 (file)
index adf9ae9..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-Future incompatibility report: Future breakage diagnostic:
-warning: reference to packed field is unaligned
-  --> $DIR/issue-27060-rpass.rs:15:13
-   |
-LL |     let _ = &good.data; // ok
-   |             ^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/issue-27060-rpass.rs:11:9
-   |
-LL | #[allow(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-warning: reference to packed field is unaligned
-  --> $DIR/issue-27060-rpass.rs:16:13
-   |
-LL |     let _ = &good.data2[0]; // ok
-   |             ^^^^^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/issue-27060-rpass.rs:11:9
-   |
-LL | #[allow(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-warning: reference to packed field is unaligned
-  --> $DIR/issue-27060-rpass.rs:18:13
-   |
-LL |     let _ = &good.data;
-   |             ^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/issue-27060-rpass.rs:11:9
-   |
-LL | #[allow(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-warning: reference to packed field is unaligned
-  --> $DIR/issue-27060-rpass.rs:19:13
-   |
-LL |     let _ = &good.data2[0];
-   |             ^^^^^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/issue-27060-rpass.rs:11:9
-   |
-LL | #[allow(unaligned_references)]
-   |         ^^^^^^^^^^^^^^^^^^^^
-
index 886a00239f98c5165d80b6ac40d32c75f3b9d661..a0e944caa0b551b6d262f6a1d49ec67e88a854f7 100644 (file)
@@ -13,14 +13,10 @@ fn main() {
     };
 
     let _ = &good.data; //~ ERROR reference to packed field
-    //~| hard error
     let _ = &good.data2[0]; //~ ERROR reference to packed field
-    //~| hard error
 
     let _ = &good.data; //~ ERROR reference to packed field
-                        //~| hard error
     let _ = &good.data2[0]; //~ ERROR reference to packed field
-                            //~| hard error
     let _ = &*good.data; // ok, behind a pointer
     let _ = &good.aligned; // ok, has align 1
     let _ = &good.aligned[2]; // ok, has align 1
index 85e08fa02dd170854b6fa1c74fedeb99f7499787..b4753284f725dca32c9be573459ce03cf16eb818 100644 (file)
@@ -1,99 +1,39 @@
-error: reference to packed field is unaligned
+error[E0793]: reference to packed field is unaligned
   --> $DIR/issue-27060.rs:15:13
    |
 LL |     let _ = &good.data;
    |             ^^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
-   = note: `#[deny(unaligned_references)]` on by default
 
-error: reference to packed field is unaligned
-  --> $DIR/issue-27060.rs:17:13
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/issue-27060.rs:16:13
    |
 LL |     let _ = &good.data2[0];
    |             ^^^^^^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/issue-27060.rs:20:13
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/issue-27060.rs:18:13
    |
 LL |     let _ = &good.data;
    |             ^^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-error: reference to packed field is unaligned
-  --> $DIR/issue-27060.rs:22:13
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/issue-27060.rs:19:13
    |
 LL |     let _ = &good.data2[0];
    |             ^^^^^^^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
 error: aborting due to 4 previous errors
 
-Future incompatibility report: Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/issue-27060.rs:15:13
-   |
-LL |     let _ = &good.data;
-   |             ^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-   = note: `#[deny(unaligned_references)]` on by default
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/issue-27060.rs:17:13
-   |
-LL |     let _ = &good.data2[0];
-   |             ^^^^^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-   = note: `#[deny(unaligned_references)]` on by default
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/issue-27060.rs:20:13
-   |
-LL |     let _ = &good.data;
-   |             ^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-   = note: `#[deny(unaligned_references)]` on by default
-
-Future breakage diagnostic:
-error: reference to packed field is unaligned
-  --> $DIR/issue-27060.rs:22:13
-   |
-LL |     let _ = &good.data2[0];
-   |             ^^^^^^^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-   = note: `#[deny(unaligned_references)]` on by default
-
+For more information about this error, try `rustc --explain E0793`.
index 00bddfe40b25b7ae3a4e6a00e473f0608cb308cc..63315ea66737ae09043851c2669eede600d9dba0 100644 (file)
@@ -1,4 +1,3 @@
-// run-pass (note: this is spec-UB, but it works for now)
 // ignore-32bit (needs `usize` to be 8-aligned to reproduce all the errors below)
 #![allow(dead_code)]
 // ignore-emscripten weird assertion?
@@ -9,10 +8,8 @@ struct Foo4C {
     baz: usize
 }
 
-#[warn(unaligned_references)]
 pub fn main() {
     let foo = Foo4C { bar: 1, baz: 2 };
-    let brw = &foo.baz; //~WARN reference to packed field is unaligned
-    //~^ previously accepted
+    let brw = &foo.baz; //~ERROR reference to packed field is unaligned
     assert_eq!(*brw, 2);
 }
index fb2f5615c5399689df3da166ff0093a41ac982bf..32943b0f07b8c785e9b33248eec67a43afe54c6d 100644 (file)
@@ -1,35 +1,12 @@
-warning: reference to packed field is unaligned
-  --> $DIR/packed-struct-borrow-element-64bit.rs:15:15
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/packed-struct-borrow-element-64bit.rs:13:15
    |
 LL |     let brw = &foo.baz;
    |               ^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
-note: the lint level is defined here
-  --> $DIR/packed-struct-borrow-element-64bit.rs:12:8
-   |
-LL | #[warn(unaligned_references)]
-   |        ^^^^^^^^^^^^^^^^^^^^
-
-warning: 1 warning emitted
 
-Future incompatibility report: Future breakage diagnostic:
-warning: reference to packed field is unaligned
-  --> $DIR/packed-struct-borrow-element-64bit.rs:15:15
-   |
-LL |     let brw = &foo.baz;
-   |               ^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/packed-struct-borrow-element-64bit.rs:12:8
-   |
-LL | #[warn(unaligned_references)]
-   |        ^^^^^^^^^^^^^^^^^^^^
+error: aborting due to previous error
 
+For more information about this error, try `rustc --explain E0793`.
index a6ee90cef44f055abd58354860efc8cc443e741d..6cbeca44bbcbf7f92fc6c23ed9c8a50e4973e235 100644 (file)
@@ -1,4 +1,3 @@
-// run-pass (note: this is spec-UB, but it works for now)
 #![allow(dead_code)]
 // ignore-emscripten weird assertion?
 
@@ -20,15 +19,12 @@ struct Foo4C {
     baz: usize
 }
 
-#[warn(unaligned_references)]
 pub fn main() {
     let foo = Foo1 { bar: 1, baz: 2 };
-    let brw = &foo.baz; //~WARN reference to packed field is unaligned
-    //~^ previously accepted
+    let brw = &foo.baz; //~ERROR reference to packed field is unaligned
     assert_eq!(*brw, 2);
 
     let foo = Foo2 { bar: 1, baz: 2 };
-    let brw = &foo.baz; //~WARN reference to packed field is unaligned
-    //~^ previously accepted
+    let brw = &foo.baz; //~ERROR reference to packed field is unaligned
     assert_eq!(*brw, 2);
 }
index 75d55c4f6930de0779dcf7591b49b17f2a51827f..29d867fc5b9ad038183c0ec1d2df93d0abd7befb 100644 (file)
@@ -1,63 +1,21 @@
-warning: reference to packed field is unaligned
-  --> $DIR/packed-struct-borrow-element.rs:26:15
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/packed-struct-borrow-element.rs:24:15
    |
 LL |     let brw = &foo.baz;
    |               ^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
-note: the lint level is defined here
-  --> $DIR/packed-struct-borrow-element.rs:23:8
-   |
-LL | #[warn(unaligned_references)]
-   |        ^^^^^^^^^^^^^^^^^^^^
 
-warning: reference to packed field is unaligned
-  --> $DIR/packed-struct-borrow-element.rs:31:15
+error[E0793]: reference to packed field is unaligned
+  --> $DIR/packed-struct-borrow-element.rs:28:15
    |
 LL |     let brw = &foo.baz;
    |               ^^^^^^^^
    |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
    = 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)
 
-warning: 2 warnings emitted
-
-Future incompatibility report: Future breakage diagnostic:
-warning: reference to packed field is unaligned
-  --> $DIR/packed-struct-borrow-element.rs:26:15
-   |
-LL |     let brw = &foo.baz;
-   |               ^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/packed-struct-borrow-element.rs:23:8
-   |
-LL | #[warn(unaligned_references)]
-   |        ^^^^^^^^^^^^^^^^^^^^
-
-Future breakage diagnostic:
-warning: reference to packed field is unaligned
-  --> $DIR/packed-struct-borrow-element.rs:31:15
-   |
-LL |     let brw = &foo.baz;
-   |               ^^^^^^^^
-   |
-   = 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 #82523 <https://github.com/rust-lang/rust/issues/82523>
-   = 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)
-note: the lint level is defined here
-  --> $DIR/packed-struct-borrow-element.rs:23:8
-   |
-LL | #[warn(unaligned_references)]
-   |        ^^^^^^^^^^^^^^^^^^^^
+error: aborting due to 2 previous errors
 
+For more information about this error, try `rustc --explain E0793`.