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

Rollup of 5 pull requests

Successful merges:

 - #56233 (Miri and miri-related code contains repetitions of `(n << amt) >> amt`)
 - #57645 (distinguish "no data" from "heterogeneous" in ABI)
 - #57734 (Fix evaluating trivial drop glue in constants)
 - #57886 (Add suggestion for moving type declaration before associated type bindings in generic arguments.)
 - #57890 (Fix wording in diagnostics page)

Failed merges:

r? @ghost
This commit is contained in:
bors 2019-01-25 23:27:20 +00:00
commit 37d51aa8f3
30 changed files with 872 additions and 84 deletions

View file

@ -0,0 +1,13 @@
// compile-pass
#![allow(dead_code)]
struct A;
impl Drop for A {
fn drop(&mut self) {}
}
const FOO: Option<A> = None;
const BAR: () = (FOO, ()).1;
fn main() {}

View file

@ -0,0 +1,36 @@
#![feature(rustc_attrs)]
// Show that `homogeneous_aggregate` code ignores zero-length C
// arrays. This matches the recent C standard, though not the
// behavior of all older compilers, which somtimes consider `T[0]` to
// be a "flexible array member" (see discussion on #56877 for
// details).
#[repr(C)]
pub struct Foo {
x: u32
}
#[repr(C)]
pub struct Middle {
pub a: f32,
pub foo: [Foo; 0],
pub b: f32,
}
#[rustc_layout(homogeneous_aggregate)]
pub type TestMiddle = Middle;
//~^ ERROR homogeneous_aggregate: Homogeneous
#[repr(C)]
pub struct Final {
pub a: f32,
pub b: f32,
pub foo: [Foo; 0],
}
#[rustc_layout(homogeneous_aggregate)]
pub type TestFinal = Final;
//~^ ERROR homogeneous_aggregate: Homogeneous
fn main() { }

View file

@ -0,0 +1,14 @@
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/homogeneous-aggr-zero-sized-c-struct.rs:22:1
|
LL | pub type TestMiddle = Middle;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/homogeneous-aggr-zero-sized-c-struct.rs:33:1
|
LL | pub type TestFinal = Final;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors

View file

@ -0,0 +1,73 @@
#![feature(rustc_attrs)]
// Regression test for #56877. We want to ensure that the presence of
// `PhantomData` does not prevent `Bar` from being considered a
// homogeneous aggregate.
#[repr(C)]
pub struct BaseCase {
pub a: f32,
pub b: f32,
}
#[repr(C)]
pub struct WithPhantomData {
pub a: f32,
pub b: f32,
pub _unit: std::marker::PhantomData<()>,
}
pub struct EmptyRustStruct {
}
#[repr(C)]
pub struct WithEmptyRustStruct {
pub a: f32,
pub b: f32,
pub _unit: EmptyRustStruct,
}
pub struct TransitivelyEmptyRustStruct {
field: EmptyRustStruct,
array: [u32; 0],
}
#[repr(C)]
pub struct WithTransitivelyEmptyRustStruct {
pub a: f32,
pub b: f32,
pub _unit: TransitivelyEmptyRustStruct,
}
pub enum EmptyRustEnum {
Dummy,
}
#[repr(C)]
pub struct WithEmptyRustEnum {
pub a: f32,
pub b: f32,
pub _unit: EmptyRustEnum,
}
#[rustc_layout(homogeneous_aggregate)]
pub type Test1 = BaseCase;
//~^ ERROR homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
#[rustc_layout(homogeneous_aggregate)]
pub type Test2 = WithPhantomData;
//~^ ERROR homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
#[rustc_layout(homogeneous_aggregate)]
pub type Test3 = WithEmptyRustStruct;
//~^ ERROR homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
#[rustc_layout(homogeneous_aggregate)]
pub type Test4 = WithTransitivelyEmptyRustStruct;
//~^ ERROR homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
#[rustc_layout(homogeneous_aggregate)]
pub type Test5 = WithEmptyRustEnum;
//~^ ERROR homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
fn main() { }

View file

@ -0,0 +1,32 @@
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/homogeneous-aggr-zero-sized-repr-rust.rs:54:1
|
LL | pub type Test1 = BaseCase;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/homogeneous-aggr-zero-sized-repr-rust.rs:58:1
|
LL | pub type Test2 = WithPhantomData;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/homogeneous-aggr-zero-sized-repr-rust.rs:62:1
|
LL | pub type Test3 = WithEmptyRustStruct;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/homogeneous-aggr-zero-sized-repr-rust.rs:66:1
|
LL | pub type Test4 = WithTransitivelyEmptyRustStruct;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/homogeneous-aggr-zero-sized-repr-rust.rs:70:1
|
LL | pub type Test5 = WithEmptyRustEnum;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 5 previous errors

View file

@ -0,0 +1,95 @@
#![feature(rustc_attrs)]
// Various tests around the behavior of zero-sized arrays and
// unions. This matches the behavior of modern C compilers, though
// older compilers (and sometimes clang) treat `T[0]` as a "flexible
// array member". See more
// details in #56877.
#[derive(Copy, Clone)]
#[repr(C)]
struct Empty { }
#[derive(Copy, Clone)]
#[repr(C)]
struct Empty2 {
e: Empty
}
#[derive(Copy, Clone)]
#[repr(C)]
struct Empty3 {
z: [f32; 0],
}
#[derive(Copy, Clone)]
#[repr(C)]
struct Empty4 {
e: Empty3
}
#[repr(C)]
union U1 {
s: Empty
}
#[repr(C)]
union U2 {
s: Empty2
}
#[repr(C)]
union U3 {
s: Empty3
}
#[repr(C)]
union U4 {
s: Empty4
}
#[repr(C)]
struct Baz1 {
x: f32,
y: f32,
u: U1,
}
#[rustc_layout(homogeneous_aggregate)]
type TestBaz1 = Baz1;
//~^ ERROR homogeneous_aggregate: Homogeneous
#[repr(C)]
struct Baz2 {
x: f32,
y: f32,
u: U2,
}
#[rustc_layout(homogeneous_aggregate)]
type TestBaz2 = Baz2;
//~^ ERROR homogeneous_aggregate: Homogeneous
#[repr(C)]
struct Baz3 {
x: f32,
y: f32,
u: U3,
}
#[rustc_layout(homogeneous_aggregate)]
type TestBaz3 = Baz3;
//~^ ERROR homogeneous_aggregate: Homogeneous
#[repr(C)]
struct Baz4 {
x: f32,
y: f32,
u: U4,
}
#[rustc_layout(homogeneous_aggregate)]
type TestBaz4 = Baz4;
//~^ ERROR homogeneous_aggregate: Homogeneous
fn main() { }

View file

@ -0,0 +1,26 @@
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/zero-sized-array-union.rs:59:1
|
LL | type TestBaz1 = Baz1;
| ^^^^^^^^^^^^^^^^^^^^^
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/zero-sized-array-union.rs:70:1
|
LL | type TestBaz2 = Baz2;
| ^^^^^^^^^^^^^^^^^^^^^
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/zero-sized-array-union.rs:81:1
|
LL | type TestBaz3 = Baz3;
| ^^^^^^^^^^^^^^^^^^^^^
error: homogeneous_aggregate: Homogeneous(Reg { kind: Float, size: Size { raw: 4 } })
--> $DIR/zero-sized-array-union.rs:92:1
|
LL | type TestBaz4 = Baz4;
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 4 previous errors

View file

@ -3,6 +3,10 @@ error: type parameters must be declared prior to associated type bindings
|
LL | pub fn test<W, I: Trait<Item=(), W> >() {}
| ^ must be declared prior to associated type bindings
help: move the type parameter prior to the first associated type binding
|
LL | pub fn test<W, I: Trait<W, Item=()> >() {}
| ^^ --
error: aborting due to previous error

View file

@ -54,7 +54,19 @@ error[E0493]: destructors cannot be evaluated at compile-time
LL | (x, ()).1
| ^^^^^^^ constant functions cannot evaluate destructors
error: aborting due to 8 previous errors
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:31:34
|
LL | const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
| ^^^^^^^^^^^^^^^^^^^ constants cannot evaluate destructors
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:36:43
|
LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
| ^^^^^^^^^^^ constants cannot evaluate destructors
error: aborting due to 10 previous errors
Some errors occurred: E0493, E0716.
For more information about an error, try `rustc --explain E0493`.

View file

@ -28,4 +28,12 @@ const fn const_drop2<T>(x: T) {
//~^ ERROR destructors cannot be evaluated at compile-time
}
const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
//~^ ERROR destructors cannot be evaluated at compile-time
const HELPER: Option<WithDtor> = Some(WithDtor);
const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
//~^ ERROR destructors cannot be evaluated at compile-time
fn main () {}

View file

@ -54,7 +54,19 @@ error[E0493]: destructors cannot be evaluated at compile-time
LL | (x, ()).1
| ^^^^^^^ constant functions cannot evaluate destructors
error: aborting due to 8 previous errors
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:31:34
|
LL | const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
| ^^^^^^^^^^^^^^^^^^^ constants cannot evaluate destructors
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/static-drop-scope.rs:36:43
|
LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
| ^^^^^^^^^^^ constants cannot evaluate destructors
error: aborting due to 10 previous errors
Some errors occurred: E0493, E0597.
For more information about an error, try `rustc --explain E0493`.

View file

@ -0,0 +1,85 @@
// ignore-tidy-linelength
#![allow(warnings)]
// This test verifies that the suggestion to move types before associated type bindings
// is correct.
trait One<T> {
type A;
}
trait OneWithLifetime<'a, T> {
type A;
}
trait Three<T, U, V> {
type A;
type B;
type C;
}
trait ThreeWithLifetime<'a, 'b, 'c, T, U, V> {
type A;
type B;
type C;
}
struct A<T, M: One<A=(), T>> { //~ ERROR type parameters must be declared
m: M,
t: T,
}
struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
//~^ ERROR generic arguments must declare lifetimes, types and associated type bindings in that order
m: M,
t: &'a T,
}
struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> { //~ ERROR type parameters must be declared
m: M,
t: T,
u: U,
v: V,
}
struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
//~^ ERROR generic arguments must declare lifetimes, types and associated type bindings in that order
m: M,
t: &'a T,
u: &'b U,
v: &'c V,
}
struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> { //~ ERROR type parameters must be declared
m: M,
t: T,
u: U,
v: V,
}
struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
//~^ ERROR generic arguments must declare lifetimes, types and associated type bindings in that order
m: M,
t: &'a T,
u: &'b U,
v: &'c V,
}
struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> { //~ ERROR type parameters must be declared
m: M,
t: T,
u: U,
v: V,
}
struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
//~^ ERROR generic arguments must declare lifetimes, types and associated type bindings in that order
m: M,
t: &'a T,
u: &'b U,
v: &'c V,
}
fn main() {}

View file

@ -0,0 +1,107 @@
error: type parameters must be declared prior to associated type bindings
--> $DIR/suggest-move-types.rs:28:26
|
LL | struct A<T, M: One<A=(), T>> { //~ ERROR type parameters must be declared
| ^ must be declared prior to associated type bindings
help: move the type parameter prior to the first associated type binding
|
LL | struct A<T, M: One<T, A=()>> { //~ ERROR type parameters must be declared
| ^^ --
error: generic arguments must declare lifetimes, types and associated type bindings in that order
--> $DIR/suggest-move-types.rs:34:46
|
LL | struct Al<'a, T, M: OneWithLifetime<A=(), T, 'a>> {
| ^ ^^ must be declared prior to type parameters
| |
| must be declared prior to associated type bindings
help: move the parameters
|
LL | struct Al<'a, T, M: OneWithLifetime<'a, T, A=()>> {
| ^^^ ^^ --
error: type parameters must be declared prior to associated type bindings
--> $DIR/suggest-move-types.rs:40:46
|
LL | struct B<T, U, V, M: Three<A=(), B=(), C=(), T, U, V>> { //~ ERROR type parameters must be declared
| ^ ^ ^ must be declared prior to associated type bindings
| | |
| | must be declared prior to associated type bindings
| must be declared prior to associated type bindings
help: move the type parameters prior to the first associated type binding
|
LL | struct B<T, U, V, M: Three<T, U, V, A=(), B=(), C=()>> { //~ ERROR type parameters must be declared
| ^^ ^^ ^^ --
error: generic arguments must declare lifetimes, types and associated type bindings in that order
--> $DIR/suggest-move-types.rs:47:80
|
LL | struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<A=(), B=(), C=(), T, U, V, 'a, 'b, 'c>> {
| ^ ^ ^ ^^ ^^ ^^ must be declared prior to type parameters
| | | | | |
| | | | | must be declared prior to type parameters
| | | | must be declared prior to type parameters
| | | must be declared prior to associated type bindings
| | must be declared prior to associated type bindings
| must be declared prior to associated type bindings
help: move the parameters
|
LL | struct Bl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<'a, 'b, 'c, T, U, V, A=(), B=(), C=()>> {
| ^^^ ^^^ ^^^ ^^ ^^ ^^ --
error: type parameters must be declared prior to associated type bindings
--> $DIR/suggest-move-types.rs:55:49
|
LL | struct C<T, U, V, M: Three<T, A=(), B=(), C=(), U, V>> { //~ ERROR type parameters must be declared
| ^ ^ must be declared prior to associated type bindings
| |
| must be declared prior to associated type bindings
help: move the type parameters prior to the first associated type binding
|
LL | struct C<T, U, V, M: Three<T, U, V, A=(), B=(), C=()>> { //~ ERROR type parameters must be declared
| ^^ ^^ --
error: generic arguments must declare lifetimes, types and associated type bindings in that order
--> $DIR/suggest-move-types.rs:62:56
|
LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
| ^^ ^ ^^ ^ ^^ must be declared prior to type parameters
| | | | |
| | | | must be declared prior to associated type bindings
| | | must be declared prior to type parameters
| | must be declared prior to associated type bindings
| must be declared prior to type parameters
help: move the parameters
|
LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<'a, 'b, 'c, T, U, V, A=(), B=(), C=()>> {
| ^^^ ^^^ ^^^ -- ^^ ^^ --
error: type parameters must be declared prior to associated type bindings
--> $DIR/suggest-move-types.rs:70:43
|
LL | struct D<T, U, V, M: Three<T, A=(), B=(), U, C=(), V>> { //~ ERROR type parameters must be declared
| ^ ^ must be declared prior to associated type bindings
| |
| must be declared prior to associated type bindings
help: move the type parameters prior to the first associated type binding
|
LL | struct D<T, U, V, M: Three<T, U, V, A=(), B=(), C=()>> { //~ ERROR type parameters must be declared
| ^^ ^^ -- --
error: generic arguments must declare lifetimes, types and associated type bindings in that order
--> $DIR/suggest-move-types.rs:77:56
|
LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
| ^^ ^ ^^ ^ ^^ must be declared prior to type parameters
| | | | |
| | | | must be declared prior to associated type bindings
| | | must be declared prior to type parameters
| | must be declared prior to associated type bindings
| must be declared prior to type parameters
help: move the parameters
|
LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<'a, 'b, 'c, T, U, V, A=(), B=(), C=()>> {
| ^^^ ^^^ ^^^ -- ^^ ^^ -- --
error: aborting due to 8 previous errors