Auto merge of #57830 - Centril:rollup, r=Centril

Rollup of 9 pull requests

Successful merges:

 - #57537 (Small perf improvement for fmt)
 - #57552 (Default images)
 - #57604 (Make `str` indexing generic on `SliceIndex`.)
 - #57667 (Fix memory leak in P::filter_map)
 - #57677 (const_eval: Predetermine the layout of all locals when pushing a stack frame)
 - #57791 (Add regression test for #54582)
 - #57798 (Corrected spelling inconsistency)
 - #57809 (Add powerpc64-unknown-freebsd)
 - #57813 (fix validation range printing when encountering undef)

Failed merges:

r? @ghost
This commit is contained in:
bors 2019-01-22 13:40:01 +00:00
commit ad30e9a681
40 changed files with 495 additions and 284 deletions

View file

@ -13,6 +13,13 @@ const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
//~^ ERROR it is undefined behavior to use this value
union Transmute {
uninit: (),
out: NonZeroU8,
}
const UNINIT: NonZeroU8 = unsafe { Transmute { uninit: () }.out };
//~^ ERROR it is undefined behavior to use this value
// Also test other uses of rustc_layout_scalar_valid_range_start
#[rustc_layout_scalar_valid_range_start(10)]

View file

@ -23,7 +23,15 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-nonnull.rs:21:1
--> $DIR/ub-nonnull.rs:20:1
|
LL | const UNINIT: NonZeroU8 = unsafe { Transmute { uninit: () }.out };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected something greater or equal to 1
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-nonnull.rs:28:1
|
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
@ -31,13 +39,13 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-nonnull.rs:27:1
--> $DIR/ub-nonnull.rs:34:1
|
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 20, but expected something less or equal to 10, or greater or equal to 30
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
error: aborting due to 5 previous errors
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0080`.

View file

@ -1,4 +1,4 @@
error[E0277]: the trait bound `i32: std::slice::SliceIndex<[{integer}]>` is not satisfied
error[E0277]: the type `[{integer}]` cannot be indexed by `i32`
--> $DIR/index-help.rs:3:5
|
LL | x[0i32]; //~ ERROR E0277

View file

@ -3,7 +3,7 @@
fn main() {
fn bar<T>(_: T) {}
[0][0u8]; //~ ERROR: the trait bound `u8: std::slice::SliceIndex<[{integer}]>` is not satisfied
[0][0u8]; //~ ERROR: the type `[{integer}]` cannot be indexed by `u8`
[0][0]; // should infer to be a usize

View file

@ -1,7 +1,7 @@
error[E0277]: the trait bound `u8: std::slice::SliceIndex<[{integer}]>` is not satisfied
error[E0277]: the type `[{integer}]` cannot be indexed by `u8`
--> $DIR/indexing-requires-a-uint.rs:6:5
|
LL | [0][0u8]; //~ ERROR: the trait bound `u8: std::slice::SliceIndex<[{integer}]>` is not satisfied
LL | [0][0u8]; //~ ERROR: the type `[{integer}]` cannot be indexed by `u8`
| ^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<[{integer}]>` is not implemented for `u8`

View file

@ -3,14 +3,14 @@ pub fn main() {
let s: String = "abcdef".to_string();
v[3_usize];
v[3];
v[3u8]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
v[3i8]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
v[3u32]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
v[3i32]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
v[3u8]; //~ERROR : the type `[isize]` cannot be indexed by `u8`
v[3i8]; //~ERROR : the type `[isize]` cannot be indexed by `i8`
v[3u32]; //~ERROR : the type `[isize]` cannot be indexed by `u32`
v[3i32]; //~ERROR : the type `[isize]` cannot be indexed by `i32`
s.as_bytes()[3_usize];
s.as_bytes()[3];
s.as_bytes()[3u8]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
s.as_bytes()[3i8]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
s.as_bytes()[3u32]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
s.as_bytes()[3i32]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
s.as_bytes()[3u8]; //~ERROR : the type `[u8]` cannot be indexed by `u8`
s.as_bytes()[3i8]; //~ERROR : the type `[u8]` cannot be indexed by `i8`
s.as_bytes()[3u32]; //~ERROR : the type `[u8]` cannot be indexed by `u32`
s.as_bytes()[3i32]; //~ERROR : the type `[u8]` cannot be indexed by `i32`
}

View file

@ -1,70 +1,70 @@
error[E0277]: the trait bound `u8: std::slice::SliceIndex<[isize]>` is not satisfied
error[E0277]: the type `[isize]` cannot be indexed by `u8`
--> $DIR/integral-indexing.rs:6:5
|
LL | v[3u8]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
LL | v[3u8]; //~ERROR : the type `[isize]` cannot be indexed by `u8`
| ^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<[isize]>` is not implemented for `u8`
= note: required because of the requirements on the impl of `std::ops::Index<u8>` for `std::vec::Vec<isize>`
error[E0277]: the trait bound `i8: std::slice::SliceIndex<[isize]>` is not satisfied
error[E0277]: the type `[isize]` cannot be indexed by `i8`
--> $DIR/integral-indexing.rs:7:5
|
LL | v[3i8]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
LL | v[3i8]; //~ERROR : the type `[isize]` cannot be indexed by `i8`
| ^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<[isize]>` is not implemented for `i8`
= note: required because of the requirements on the impl of `std::ops::Index<i8>` for `std::vec::Vec<isize>`
error[E0277]: the trait bound `u32: std::slice::SliceIndex<[isize]>` is not satisfied
error[E0277]: the type `[isize]` cannot be indexed by `u32`
--> $DIR/integral-indexing.rs:8:5
|
LL | v[3u32]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
LL | v[3u32]; //~ERROR : the type `[isize]` cannot be indexed by `u32`
| ^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<[isize]>` is not implemented for `u32`
= note: required because of the requirements on the impl of `std::ops::Index<u32>` for `std::vec::Vec<isize>`
error[E0277]: the trait bound `i32: std::slice::SliceIndex<[isize]>` is not satisfied
error[E0277]: the type `[isize]` cannot be indexed by `i32`
--> $DIR/integral-indexing.rs:9:5
|
LL | v[3i32]; //~ERROR : std::slice::SliceIndex<[isize]>` is not satisfied
LL | v[3i32]; //~ERROR : the type `[isize]` cannot be indexed by `i32`
| ^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<[isize]>` is not implemented for `i32`
= note: required because of the requirements on the impl of `std::ops::Index<i32>` for `std::vec::Vec<isize>`
error[E0277]: the trait bound `u8: std::slice::SliceIndex<[u8]>` is not satisfied
error[E0277]: the type `[u8]` cannot be indexed by `u8`
--> $DIR/integral-indexing.rs:12:5
|
LL | s.as_bytes()[3u8]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
LL | s.as_bytes()[3u8]; //~ERROR : the type `[u8]` cannot be indexed by `u8`
| ^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<[u8]>` is not implemented for `u8`
= note: required because of the requirements on the impl of `std::ops::Index<u8>` for `[u8]`
error[E0277]: the trait bound `i8: std::slice::SliceIndex<[u8]>` is not satisfied
error[E0277]: the type `[u8]` cannot be indexed by `i8`
--> $DIR/integral-indexing.rs:13:5
|
LL | s.as_bytes()[3i8]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
LL | s.as_bytes()[3i8]; //~ERROR : the type `[u8]` cannot be indexed by `i8`
| ^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<[u8]>` is not implemented for `i8`
= note: required because of the requirements on the impl of `std::ops::Index<i8>` for `[u8]`
error[E0277]: the trait bound `u32: std::slice::SliceIndex<[u8]>` is not satisfied
error[E0277]: the type `[u8]` cannot be indexed by `u32`
--> $DIR/integral-indexing.rs:14:5
|
LL | s.as_bytes()[3u32]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
LL | s.as_bytes()[3u32]; //~ERROR : the type `[u8]` cannot be indexed by `u32`
| ^^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<[u8]>` is not implemented for `u32`
= note: required because of the requirements on the impl of `std::ops::Index<u32>` for `[u8]`
error[E0277]: the trait bound `i32: std::slice::SliceIndex<[u8]>` is not satisfied
error[E0277]: the type `[u8]` cannot be indexed by `i32`
--> $DIR/integral-indexing.rs:15:5
|
LL | s.as_bytes()[3i32]; //~ERROR : std::slice::SliceIndex<[u8]>` is not satisfied
LL | s.as_bytes()[3i32]; //~ERROR : the type `[u8]` cannot be indexed by `i32`
| ^^^^^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<[u8]>` is not implemented for `i32`

View file

@ -0,0 +1,16 @@
// run-pass
pub trait Stage: Sync {}
pub enum Enum {
A,
B,
}
impl Stage for Enum {}
pub static ARRAY: [(&Stage, &str); 1] = [
(&Enum::A, ""),
];
fn main() {}

View file

@ -1,4 +1,4 @@
error[E0277]: the trait bound `i32: std::slice::SliceIndex<[i32]>` is not satisfied
error[E0277]: the type `[i32]` cannot be indexed by `i32`
--> $DIR/slice-index.rs:11:5
|
LL | x[1i32]; //~ ERROR E0277
@ -7,7 +7,7 @@ LL | x[1i32]; //~ ERROR E0277
= help: the trait `std::slice::SliceIndex<[i32]>` is not implemented for `i32`
= note: required because of the requirements on the impl of `std::ops::Index<i32>` for `[i32]`
error[E0277]: the trait bound `std::ops::RangeTo<i32>: std::slice::SliceIndex<[i32]>` is not satisfied
error[E0277]: the type `[i32]` cannot be indexed by `std::ops::RangeTo<i32>`
--> $DIR/slice-index.rs:12:5
|
LL | x[..1i32]; //~ ERROR E0277

View file

@ -1,5 +1,5 @@
error[E0609]: no field `opts` on type `*const Session`
--> $DIR/parenthesised-deref-suggestion.rs:7:30
--> $DIR/parenthesized-deref-suggestion.rs:7:30
|
LL | (sess as *const Session).opts; //~ ERROR no field `opts` on type `*const Session`
| ^^^^
@ -9,7 +9,7 @@ LL | (*(sess as *const Session)).opts; //~ ERROR no field `opts` on type `*c
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0609]: no field `0` on type `[u32; 1]`
--> $DIR/parenthesised-deref-suggestion.rs:10:21
--> $DIR/parenthesized-deref-suggestion.rs:10:21
|
LL | (x as [u32; 1]).0; //~ ERROR no field `0` on type `[u32; 1]`
| ----------------^

View file

@ -1,4 +1,7 @@
pub fn main() {
let s: &str = "hello";
let c: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
let _: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
let _ = s.get(4); //~ ERROR the type `str` cannot be indexed by `{integer}`
let _ = s.get_unchecked(4); //~ ERROR the type `str` cannot be indexed by `{integer}`
let _: u8 = s['c']; //~ ERROR the type `str` cannot be indexed by `char`
}

View file

@ -1,13 +1,43 @@
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-idx.rs:3:17
|
LL | let c: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
| ^^^^ `str` cannot be indexed by `{integer}`
LL | let _: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
| ^^^^ string indices are ranges of `usize`
|
= help: the trait `std::ops::Index<{integer}>` is not implemented for `str`
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
= note: required because of the requirements on the impl of `std::ops::Index<{integer}>` for `str`
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-idx.rs:4:15
|
LL | let _ = s.get(4); //~ ERROR the type `str` cannot be indexed by `{integer}`
| ^^^ string indices are ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
error: aborting due to previous error
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-idx.rs:5:15
|
LL | let _ = s.get_unchecked(4); //~ ERROR the type `str` cannot be indexed by `{integer}`
| ^^^^^^^^^^^^^ string indices are ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
error[E0277]: the type `str` cannot be indexed by `char`
--> $DIR/str-idx.rs:6:17
|
LL | let _: u8 = s['c']; //~ ERROR the type `str` cannot be indexed by `char`
| ^^^^^^ string indices are ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `char`
= note: required because of the requirements on the impl of `std::ops::Index<char>` for `str`
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0277`.

View file

@ -5,7 +5,13 @@ fn mutate(s: &mut str) {
//~^ ERROR the size for values of type
//~| ERROR the size for values of type
s[1usize] = bot();
//~^ ERROR the type `str` cannot be mutably indexed by `usize`
//~^ ERROR the type `str` cannot be indexed by `usize`
s.get_mut(1);
//~^ ERROR the type `str` cannot be indexed by `{integer}`
s.get_unchecked_mut(1);
//~^ ERROR the type `str` cannot be indexed by `{integer}`
s['c'];
//~^ ERROR the type `str` cannot be indexed by `char`
}
pub fn main() {}

View file

@ -22,16 +22,44 @@ LL | s[1..2] = bot();
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: the left-hand-side of an assignment must have a statically known size
error[E0277]: the type `str` cannot be mutably indexed by `usize`
error[E0277]: the type `str` cannot be indexed by `usize`
--> $DIR/str-mut-idx.rs:7:5
|
LL | s[1usize] = bot();
| ^^^^^^^^^ `str` cannot be mutably indexed by `usize`
| ^^^^^^^^^ string indices are ranges of `usize`
|
= help: the trait `std::ops::IndexMut<usize>` is not implemented for `str`
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `usize`
= note: required because of the requirements on the impl of `std::ops::Index<usize>` for `str`
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-mut-idx.rs:9:7
|
LL | s.get_mut(1);
| ^^^^^^^ string indices are ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
error: aborting due to 3 previous errors
error[E0277]: the type `str` cannot be indexed by `{integer}`
--> $DIR/str-mut-idx.rs:11:7
|
LL | s.get_unchecked_mut(1);
| ^^^^^^^^^^^^^^^^^ string indices are ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `{integer}`
= note: you can use `.chars().nth()` or `.bytes().nth()`
see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>
error[E0277]: the type `str` cannot be indexed by `char`
--> $DIR/str-mut-idx.rs:13:5
|
LL | s['c'];
| ^^^^^^ string indices are ranges of `usize`
|
= help: the trait `std::slice::SliceIndex<str>` is not implemented for `char`
= note: required because of the requirements on the impl of `std::ops::Index<char>` for `str`
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0277`.