Auto merge of #72627 - Dylan-DPC:rollup-bavnoq5, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

 - #72270 (add a lint against references to packed fields)
 - #72294 (JS cleanup)
 - #72342 (Warn about unused crate deps)
 - #72401 (Use correct function for detecting `const fn` in unsafety checking)
 - #72581 (Allow unlabeled breaks from desugared `?` in labeled blocks)
 - #72592 (Update books)

Failed merges:

r? @ghost
This commit is contained in:
bors 2020-05-26 20:58:52 +00:00
commit e5335592e7
39 changed files with 682 additions and 327 deletions

View file

@ -7,19 +7,10 @@ pub struct Good {
aligned: [u8; 32],
}
#[repr(packed)]
pub struct JustArray {
array: [u32]
}
// kill this test when that turns to a hard error
#[allow(safe_packed_borrows)]
fn main() {
let good = Good {
data: &0,
data2: [&0, &0],
aligned: [0; 32]
};
let good = Good { data: &0, data2: [&0, &0], aligned: [0; 32] };
unsafe {
let _ = &good.data; // ok

View file

@ -5,11 +5,6 @@ pub struct Good {
aligned: [u8; 32],
}
#[repr(packed)]
pub struct JustArray {
array: [u32]
}
#[deny(safe_packed_borrows)]
fn main() {
let good = Good {

View file

@ -1,11 +1,11 @@
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
--> $DIR/issue-27060.rs:26:13
--> $DIR/issue-27060.rs:21:13
|
LL | let _ = &good.data;
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/issue-27060.rs:13:8
--> $DIR/issue-27060.rs:8:8
|
LL | #[deny(safe_packed_borrows)]
| ^^^^^^^^^^^^^^^^^^^
@ -14,7 +14,7 @@ LL | #[deny(safe_packed_borrows)]
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133)
--> $DIR/issue-27060.rs:28:13
--> $DIR/issue-27060.rs:23:13
|
LL | let _ = &good.data2[0];
| ^^^^^^^^^^^^^^

View file

@ -0,0 +1,12 @@
// compile-flags: --edition 2018
#![feature(label_break_value, try_blocks)]
// run-pass
fn main() {
let _: Result<(), ()> = try {
'foo: {
Err(())?;
break 'foo;
}
};
}

View file

@ -0,0 +1,22 @@
#![deny(unaligned_references)]
#[repr(packed)]
pub struct Good {
data: &'static u32,
data2: [&'static u32; 2],
aligned: [u8; 32],
}
fn main() {
unsafe {
let good = Good { data: &0, data2: [&0, &0], aligned: [0; 32] };
let _ = &good.data; //~ ERROR reference to packed field
let _ = &good.data as *const _; //~ ERROR reference to packed field
let _: *const _ = &good.data; //~ ERROR reference to packed field
let _ = &good.data2[0]; //~ ERROR reference to packed field
let _ = &*good.data; // ok, behind a pointer
let _ = &good.aligned; // ok, has align 1
let _ = &good.aligned[2]; // ok, has align 1
}
}

View file

@ -0,0 +1,39 @@
error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:14:17
|
LL | let _ = &good.data;
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
|
LL | #![deny(unaligned_references)]
| ^^^^^^^^^^^^^^^^^^^^
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:15:17
|
LL | let _ = &good.data as *const _;
| ^^^^^^^^^^
|
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:16:27
|
LL | let _: *const _ = &good.data;
| ^^^^^^^^^^
|
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:17:17
|
LL | let _ = &good.data2[0];
| ^^^^^^^^^^^^^^
|
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
error: aborting due to 4 previous errors

View file

@ -0,0 +1,13 @@
#![stable(feature = "foo", since = "1.33.0")]
#![feature(staged_api)]
#![feature(const_compare_raw_pointers)]
#![feature(const_fn)]
#[stable(feature = "foo", since = "1.33.0")]
#[rustc_const_unstable(feature = "const_foo", issue = "none")]
const fn unstable(a: *const i32, b: *const i32) -> bool {
a == b
//~^ pointer operation is unsafe
}
fn main() {}

View file

@ -0,0 +1,11 @@
error[E0133]: pointer operation is unsafe and requires unsafe function or block
--> $DIR/unsafe-unstable-const-fn.rs:9:5
|
LL | a == b
| ^^^^^^ pointer operation
|
= note: operations on pointers in constants
error: aborting due to previous error
For more information about this error, try `rustc --explain E0133`.

View file

@ -0,0 +1 @@
pub const BAR: &str = "bar";

View file

@ -0,0 +1,5 @@
// edition:2018
// aux-crate:bar=bar.rs
pub const FOO: &str = "foo";
pub use bar::BAR;

View file

@ -0,0 +1,21 @@
// Test warnings for a library crate
// check-pass
// aux-crate:bar=bar.rs
// compile-flags:--crate-type lib -Wunused-crate-dependencies
pub fn fib(n: u32) -> Vec<u32> {
//~^ WARNING external crate `bar` unused in
let mut prev = 0;
let mut cur = 1;
let mut v = vec![];
for _ in 0..n {
v.push(prev);
let n = prev + cur;
prev = cur;
cur = n;
}
v
}

View file

@ -0,0 +1,10 @@
warning: external crate `bar` unused in `libfib`: remove the dependency or add `use bar as _;`
--> $DIR/libfib.rs:7:1
|
LL | pub fn fib(n: u32) -> Vec<u32> {
| ^
|
= note: requested on the command line with `-W unused-crate-dependencies`
warning: 1 warning emitted

View file

@ -0,0 +1,11 @@
// Suppress by using crate
// edition:2018
// check-pass
// aux-crate:bar=bar.rs
#![warn(unused_crate_dependencies)]
use bar as _;
fn main() {}

View file

@ -0,0 +1,13 @@
// Warn about unused aliased for the crate
// edition:2018
// check-pass
// aux-crate:bar=bar.rs
// aux-crate:barbar=bar.rs
#![warn(unused_crate_dependencies)]
//~^ WARNING external crate `barbar` unused in
use bar as _;
fn main() {}

View file

@ -0,0 +1,14 @@
warning: external crate `barbar` unused in `unused_aliases`: remove the dependency or add `use barbar as _;`
--> $DIR/unused-aliases.rs:8:1
|
LL | #![warn(unused_crate_dependencies)]
| ^
|
note: the lint level is defined here
--> $DIR/unused-aliases.rs:8:9
|
LL | #![warn(unused_crate_dependencies)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
warning: 1 warning emitted

View file

@ -0,0 +1,13 @@
// Suppress by using crate
// edition:2015
// check-pass
// aux-crate:bar=bar.rs
#![warn(unused_crate_dependencies)]
extern crate bar;
fn main() {
println!("bar {}", bar::BAR);
}

View file

@ -0,0 +1,10 @@
// Check for unused crate dep, no path
// edition:2018
// check-pass
// aux-crate:bar=bar.rs
#![warn(unused_crate_dependencies)]
//~^ WARNING external crate `bar` unused in
fn main() {}

View file

@ -0,0 +1,14 @@
warning: external crate `bar` unused in `warn_attr`: remove the dependency or add `use bar as _;`
--> $DIR/warn-attr.rs:7:1
|
LL | #![warn(unused_crate_dependencies)]
| ^
|
note: the lint level is defined here
--> $DIR/warn-attr.rs:7:9
|
LL | #![warn(unused_crate_dependencies)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
warning: 1 warning emitted

View file

@ -0,0 +1,10 @@
// Check for unused crate dep, no path
// edition:2018
// check-pass
// compile-flags: -Wunused-crate-dependencies
// aux-crate:bar=bar.rs
// no-prefer-dynamic
fn main() {}
//~^ WARNING external crate `bar` unused in

View file

@ -0,0 +1,10 @@
warning: external crate `bar` unused in `warn_cmdline_static`: remove the dependency or add `use bar as _;`
--> $DIR/warn-cmdline-static.rs:9:1
|
LL | fn main() {}
| ^
|
= note: requested on the command line with `-W unused-crate-dependencies`
warning: 1 warning emitted

View file

@ -0,0 +1,9 @@
// Check for unused crate dep, no path
// edition:2018
// check-pass
// compile-flags: -Wunused-crate-dependencies
// aux-crate:bar=bar.rs
fn main() {}
//~^ WARNING external crate `bar` unused in

View file

@ -0,0 +1,10 @@
warning: external crate `bar` unused in `warn_cmdline`: remove the dependency or add `use bar as _;`
--> $DIR/warn-cmdline.rs:8:1
|
LL | fn main() {}
| ^
|
= note: requested on the command line with `-W unused-crate-dependencies`
warning: 1 warning emitted