Skip to content

Rollup of 9 pull requests #96108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d78e3e3
Add platform support document links to tier table
Michcioperz Mar 4, 2022
c1d5c2b
Add missing platform support docs to sidebar
Michcioperz Mar 4, 2022
9cfdb89
Only add codegen backend to dep info if -Zbinary-dep-depinfo is used
bjorn3 Feb 13, 2022
c681a88
Don't include invalid paths in the depinfo for builtin backends
bjorn3 Feb 13, 2022
147e5da
Add test
bjorn3 Mar 24, 2022
7f945b2
add simd_arith_offset intrinsics
RalfJung Apr 12, 2022
e886dc5
portable-simd: use simd_arith_offset to avoid ptr-int transmutation
RalfJung Apr 12, 2022
d5f3863
Consider lifetimes when comparing types for equality in MIR validator
JakobDegen Apr 13, 2022
4a0f8d5
improve diagnostics for unterminated nested block comment
yue4u Apr 13, 2022
1b7008d
refactor: change to use peekable
yue4u Apr 14, 2022
48029ab
Remove some now-dead code that was only relevant before deaggregation.
oli-obk Apr 14, 2022
e30d6d9
make unaligned_references lint deny-by-default
RalfJung Mar 27, 2022
1a6c2ff
make unaligned_reference warning visible in future compat report
RalfJung Apr 15, 2022
4117e8c
test: add pop_first() pop_last() test cases for BTreeSet
Gumichocopengin8 Apr 15, 2022
e162602
test: add get_key_value() test cases for BTreeSet
Gumichocopengin8 Apr 15, 2022
3f2f4a3
test: add try_insert() test cases for BTreeSet
Gumichocopengin8 Apr 15, 2022
3f46ba6
chore: formatting
Gumichocopengin8 Apr 15, 2022
73f9571
add codegen smoke test
RalfJung Apr 13, 2022
63a8652
MaybeUninit array cleanup
clarfonthey Apr 16, 2022
d14bda4
Rollup merge of #93969 - bjorn3:codegen_backend_dep_info, r=pnkfelix
Dylan-DPC Apr 16, 2022
6dd92bf
Rollup merge of #94605 - Michcioperz:patch-1, r=pnkfelix
Dylan-DPC Apr 16, 2022
49a31cd
Rollup merge of #95372 - RalfJung:unaligned_references, r=oli-obk
Dylan-DPC Apr 16, 2022
946d76e
Rollup merge of #95859 - rainy-me:unterminated-nested-block-comment, …
Dylan-DPC Apr 16, 2022
ea131bc
Rollup merge of #95961 - RalfJung:gather-scatter, r=workingjubilee
Dylan-DPC Apr 16, 2022
fd7a1f1
Rollup merge of #96004 - JakobDegen:fix-validator-ice, r=petrochenkov
Dylan-DPC Apr 16, 2022
ab7fb29
Rollup merge of #96050 - oli-obk:deaggregator_cleanup, r=RalfJung
Dylan-DPC Apr 16, 2022
04ccba8
Rollup merge of #96070 - Gumichocopengin8:test/btree-map, r=thomcc
Dylan-DPC Apr 16, 2022
f559cf9
Rollup merge of #96099 - clarfonthey:maybeuninit_array_cleanup, r=dto…
Dylan-DPC Apr 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make unaligned_references lint deny-by-default
  • Loading branch information
RalfJung committed Apr 15, 2022
commit e30d6d9096e23a6206b6950b8f28a85d327a42fc
1 change: 0 additions & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#![feature(thread_id_value)]
#![feature(vec_into_raw_parts)]
#![allow(rustc::default_hash_types)]
#![deny(unaligned_references)]
#![allow(rustc::potential_query_instability)]

#[macro_use]
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,6 @@ declare_lint! {
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(unaligned_references)]
///
/// #[repr(packed)]
/// pub struct Foo {
/// field1: u64,
Expand Down Expand Up @@ -1139,7 +1137,7 @@ declare_lint! {
/// [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,
Warn,
Deny,
"detects unaligned references to fields of packed structs",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #82523 <https://github.com/rust-lang/rust/issues/82523>",
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/binding/issue-53114-safety-checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ fn let_wild_gets_unsafe_field() {
let u1 = U { a: I(0) };
let u2 = U { a: I(1) };
let p = P { a: &2, b: &3 };
let _ = &p.b; //~ WARN reference to packed field
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,); //~ WARN reference to packed field
let (_,) = (&p.b,); //~ ERROR reference to packed field
//~^ WARN will become a hard error
let (_,) = (u1.a,); //~ ERROR [E0133]
let (_,) = (&u2.a,); //~ ERROR [E0133]
Expand All @@ -36,13 +36,13 @@ fn match_unsafe_field_to_wild() {
let u1 = U { a: I(0) };
let u2 = U { a: I(1) };
let p = P { a: &2, b: &3 };
match &p.b { _ => { } } //~ WARN reference to packed field
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,) { (_,) => { } } //~ WARN reference to packed field
match (&p.b,) { (_,) => { } } //~ ERROR reference to packed field
//~^ WARN will become a hard error
match (u1.a,) { (_,) => { } } //~ ERROR [E0133]
match (&u2.a,) { (_,) => { } } //~ ERROR [E0133]
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/binding/issue-53114-safety-checks.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
warning: reference to packed field is unaligned
error: reference to packed field is unaligned
--> $DIR/issue-53114-safety-checks.rs:23:13
|
LL | let _ = &p.b;
| ^^^^
|
= note: `#[warn(unaligned_references)]` on by default
= note: `#[deny(unaligned_references)]` on by default
= 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: reference to packed field is unaligned
error: reference to packed field is unaligned
--> $DIR/issue-53114-safety-checks.rs:29:17
|
LL | let (_,) = (&p.b,);
Expand All @@ -21,7 +21,7 @@ LL | let (_,) = (&p.b,);
= 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: reference to packed field is unaligned
error: reference to packed field is unaligned
--> $DIR/issue-53114-safety-checks.rs:39:11
|
LL | match &p.b { _ => { } }
Expand All @@ -32,7 +32,7 @@ LL | match &p.b { _ => { } }
= 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: reference to packed field is unaligned
error: reference to packed field is unaligned
--> $DIR/issue-53114-safety-checks.rs:45:12
|
LL | match (&p.b,) { (_,) => { } }
Expand Down Expand Up @@ -99,6 +99,6 @@ LL | match (&u2.a,) { (_,) => { } }
|
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior

error: aborting due to 7 previous errors; 4 warnings emitted
error: aborting due to 11 previous errors

For more information about this error, try `rustc --explain E0133`.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// edition:2021

// check-pass

// Given how the closure desugaring is implemented (at least at the time of writing this test),
// we don't need to truncate the captured path to a reference into a packed-struct if the field
// being referenced will be moved into the closure, since it's safe to move out a field from a
Expand All @@ -11,9 +9,8 @@
// inlined we will truncate the capture to access just the struct regardless of if the field
// might get moved into the closure.
//
// It is possible for someone to try writing the code that relies on the desugaring to access a ref
// into a packed-struct without explicity using unsafe. Here we test that the compiler warns the
// user that such an access is still unsafe.
// It is possible for someone to try writing the code that relies on the desugaring to create a ref
// into a packed-struct. Here we test that the compiler still detects that case.
fn test_missing_unsafe_warning_on_repr_packed() {
#[repr(packed)]
struct Foo { x: String }
Expand All @@ -22,7 +19,7 @@ fn test_missing_unsafe_warning_on_repr_packed() {

let c = || {
println!("{}", foo.x);
//~^ WARNING: reference to packed field is unaligned
//~^ ERROR: reference to packed field is unaligned
//~| WARNING: this was previously accepted by the compiler but is being phased out
let _z = foo.x;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
warning: reference to packed field is unaligned
--> $DIR/repr_packed.rs:24:24
error: reference to packed field is unaligned
--> $DIR/repr_packed.rs:21:24
|
LL | println!("{}", foo.x);
| ^^^^^
|
= note: `#[warn(unaligned_references)]` on by default
= note: `#[deny(unaligned_references)]` on by default
= 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: this warning originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted
error: aborting due to previous error

1 change: 0 additions & 1 deletion src/test/ui/packed/issue-27060.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub struct Good {
aligned: [u8; 32],
}

#[deny(unaligned_references)]
fn main() {
let good = Good {
data: &0,
Expand Down
14 changes: 5 additions & 9 deletions src/test/ui/packed/issue-27060.stderr
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
error: reference to packed field is unaligned
--> $DIR/issue-27060.rs:16:13
--> $DIR/issue-27060.rs:15:13
|
LL | let _ = &good.data;
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/issue-27060.rs:8:8
|
LL | #[deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
= note: `#[deny(unaligned_references)]` on by default
= 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:18:13
--> $DIR/issue-27060.rs:17:13
|
LL | let _ = &good.data2[0];
| ^^^^^^^^^^^^^^
Expand All @@ -26,7 +22,7 @@ LL | let _ = &good.data2[0];
= 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:21:13
--> $DIR/issue-27060.rs:20:13
|
LL | let _ = &good.data;
| ^^^^^^^^^^
Expand All @@ -37,7 +33,7 @@ LL | let _ = &good.data;
= 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:23:13
--> $DIR/issue-27060.rs:22:13
|
LL | let _ = &good.data2[0];
| ^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/packed/packed-struct-address-of-element.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// run-pass
#![allow(dead_code)]
#![deny(unaligned_references)]
#![feature(raw_ref_op)]
// ignore-emscripten weird assertion?

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/packed/packed-struct-borrow-element-64bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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
Expand Down
8 changes: 6 additions & 2 deletions src/test/ui/packed/packed-struct-borrow-element-64bit.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
warning: reference to packed field is unaligned
--> $DIR/packed-struct-borrow-element-64bit.rs:14:15
--> $DIR/packed-struct-borrow-element-64bit.rs:15:15
|
LL | let brw = &foo.baz;
| ^^^^^^^^
|
= note: `#[warn(unaligned_references)]` on by default
note: the lint level is defined here
--> $DIR/packed-struct-borrow-element-64bit.rs:12:8
|
LL | #[warn(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
= 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)
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/packed/packed-struct-borrow-element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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
Expand Down
10 changes: 7 additions & 3 deletions src/test/ui/packed/packed-struct-borrow-element.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
warning: reference to packed field is unaligned
--> $DIR/packed-struct-borrow-element.rs:25:15
--> $DIR/packed-struct-borrow-element.rs:26:15
|
LL | let brw = &foo.baz;
| ^^^^^^^^
|
= note: `#[warn(unaligned_references)]` on by default
note: the lint level is defined here
--> $DIR/packed-struct-borrow-element.rs:23:8
|
LL | #[warn(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
= 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: reference to packed field is unaligned
--> $DIR/packed-struct-borrow-element.rs:30:15
--> $DIR/packed-struct-borrow-element.rs:31:15
|
LL | let brw = &foo.baz;
| ^^^^^^^^
Expand Down