diff options
Diffstat (limited to '')
18 files changed, 241 insertions, 69 deletions
diff --git a/src/test/ui/structs-enums/align-struct.rs b/src/test/ui/structs-enums/align-struct.rs index 27ef990aa..f5418e754 100644 --- a/src/test/ui/structs-enums/align-struct.rs +++ b/src/test/ui/structs-enums/align-struct.rs @@ -1,6 +1,5 @@ // run-pass #![allow(dead_code)] -#![feature(box_syntax)] use std::mem; @@ -232,9 +231,9 @@ pub fn main() { assert_eq!(mem::size_of_val(&a), 32); assert!(is_aligned_to(&a, 16)); - let mut large = box AlignLarge { + let mut large = Box::new(AlignLarge { stuff: [0; 0x10000], - }; + }); large.stuff[0] = 132; *large.stuff.last_mut().unwrap() = 102; assert_eq!(large.stuff[0], 132); diff --git a/src/test/ui/issues/issue-2718-a.rs b/src/test/ui/structs-enums/issue-2718-a.rs index 6c4915845..6c4915845 100644 --- a/src/test/ui/issues/issue-2718-a.rs +++ b/src/test/ui/structs-enums/issue-2718-a.rs diff --git a/src/test/ui/structs-enums/issue-2718-a.stderr b/src/test/ui/structs-enums/issue-2718-a.stderr new file mode 100644 index 000000000..7ea620f38 --- /dev/null +++ b/src/test/ui/structs-enums/issue-2718-a.stderr @@ -0,0 +1,14 @@ +error[E0072]: recursive type `Pong` has infinite size + --> $DIR/issue-2718-a.rs:8:5 + | +LL | pub struct Pong(SendPacket<Ping>); + | ^^^^^^^^^^^^^^^ ---------------- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL | pub struct Pong(Box<SendPacket<Ping>>); + | ++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0072`. diff --git a/src/test/ui/structs-enums/rec-align-u32.rs b/src/test/ui/structs-enums/rec-align-u32.rs index 889294daa..ee704198d 100644 --- a/src/test/ui/structs-enums/rec-align-u32.rs +++ b/src/test/ui/structs-enums/rec-align-u32.rs @@ -10,6 +10,7 @@ use std::mem; mod rusti { extern "rust-intrinsic" { pub fn pref_align_of<T>() -> usize; + #[rustc_safe_intrinsic] pub fn min_align_of<T>() -> usize; } } diff --git a/src/test/ui/structs-enums/rec-align-u64.rs b/src/test/ui/structs-enums/rec-align-u64.rs index 3bc2d16cf..40ede9705 100644 --- a/src/test/ui/structs-enums/rec-align-u64.rs +++ b/src/test/ui/structs-enums/rec-align-u64.rs @@ -12,6 +12,7 @@ use std::mem; mod rusti { extern "rust-intrinsic" { pub fn pref_align_of<T>() -> usize; + #[rustc_safe_intrinsic] pub fn min_align_of<T>() -> usize; } } diff --git a/src/test/ui/structs-enums/struct-rec/issue-74224.stderr b/src/test/ui/structs-enums/struct-rec/issue-74224.stderr index 619917846..f1d50bc8a 100644 --- a/src/test/ui/structs-enums/struct-rec/issue-74224.stderr +++ b/src/test/ui/structs-enums/struct-rec/issue-74224.stderr @@ -2,12 +2,12 @@ error[E0072]: recursive type `A` has infinite size --> $DIR/issue-74224.rs:1:1 | LL | struct A<T> { - | ^^^^^^^^^^^ recursive type has infinite size + | ^^^^^^^^^^^ ... LL | y: A<A<T>>, | ------- recursive without indirection | -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `A` representable +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle | LL | y: Box<A<A<T>>>, | ++++ + diff --git a/src/test/ui/structs-enums/struct-rec/issue-84611.stderr b/src/test/ui/structs-enums/struct-rec/issue-84611.stderr index 2e99435e0..536f54e3e 100644 --- a/src/test/ui/structs-enums/struct-rec/issue-84611.stderr +++ b/src/test/ui/structs-enums/struct-rec/issue-84611.stderr @@ -2,12 +2,12 @@ error[E0072]: recursive type `Foo` has infinite size --> $DIR/issue-84611.rs:1:1 | LL | struct Foo<T> { - | ^^^^^^^^^^^^^ recursive type has infinite size + | ^^^^^^^^^^^^^ LL | LL | x: Foo<[T; 1]>, | ----------- recursive without indirection | -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle | LL | x: Box<Foo<[T; 1]>>, | ++++ + diff --git a/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.rs b/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.rs index cca97f43e..3bfce8b4f 100644 --- a/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.rs +++ b/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.rs @@ -1,22 +1,20 @@ struct A<T> { -//~^ ERROR recursive type `A` has infinite size +//~^ ERROR recursive types `A` and `B` have infinite size x: T, y: B<T>, } struct B<T> { -//~^ ERROR recursive type `B` has infinite size z: A<T> } struct C<T> { -//~^ ERROR recursive type `C` has infinite size +//~^ ERROR recursive types `C` and `D` have infinite size x: T, y: Option<Option<D<T>>>, } struct D<T> { -//~^ ERROR recursive type `D` has infinite size z: Option<Option<C<T>>>, } diff --git a/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr b/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr index 80a494f3f..881bc2819 100644 --- a/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr +++ b/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr @@ -1,59 +1,49 @@ -error[E0072]: recursive type `A` has infinite size +error[E0072]: recursive types `A` and `B` have infinite size --> $DIR/mutual-struct-recursion.rs:1:1 | LL | struct A<T> { - | ^^^^^^^^^^^ recursive type has infinite size + | ^^^^^^^^^^^ ... LL | y: B<T>, | ---- recursive without indirection - | -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `A` representable - | -LL | y: Box<B<T>>, - | ++++ + - -error[E0072]: recursive type `B` has infinite size - --> $DIR/mutual-struct-recursion.rs:7:1 - | +... LL | struct B<T> { - | ^^^^^^^^^^^ recursive type has infinite size -LL | + | ^^^^^^^^^^^ LL | z: A<T> | ---- recursive without indirection | -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `B` representable +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL ~ y: Box<B<T>>, +LL | } +LL | +LL | struct B<T> { +LL ~ z: Box<A<T>> | -LL | z: Box<A<T>> - | ++++ + -error[E0072]: recursive type `C` has infinite size - --> $DIR/mutual-struct-recursion.rs:12:1 +error[E0072]: recursive types `C` and `D` have infinite size + --> $DIR/mutual-struct-recursion.rs:11:1 | LL | struct C<T> { - | ^^^^^^^^^^^ recursive type has infinite size + | ^^^^^^^^^^^ ... LL | y: Option<Option<D<T>>>, - | -------------------- recursive without indirection - | -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `C` representable - | -LL | y: Option<Box<Option<D<T>>>>, - | ++++ + - -error[E0072]: recursive type `D` has infinite size - --> $DIR/mutual-struct-recursion.rs:18:1 - | + | ---- recursive without indirection +... LL | struct D<T> { - | ^^^^^^^^^^^ recursive type has infinite size -LL | + | ^^^^^^^^^^^ LL | z: Option<Option<C<T>>>, - | -------------------- recursive without indirection + | ---- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle | -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `D` representable +LL ~ y: Option<Option<Box<D<T>>>>, +LL | } +LL | +LL | struct D<T> { +LL ~ z: Option<Option<Box<C<T>>>>, | -LL | z: Option<Box<Option<C<T>>>>, - | ++++ + -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0072`. diff --git a/src/test/ui/structs-enums/type-sizes.rs b/src/test/ui/structs-enums/type-sizes.rs index 73a11a5e7..7a23f1363 100644 --- a/src/test/ui/structs-enums/type-sizes.rs +++ b/src/test/ui/structs-enums/type-sizes.rs @@ -120,6 +120,54 @@ pub enum AlwaysTaggedBecauseItHasNoNiche { B } +pub enum NicheFilledMultipleFields { + A(bool, u8), + B(u8), + C(u8), + D(bool), + E, + F, + G, +} + +struct BoolInTheMiddle(std::num::NonZeroU16, bool, u8); + +enum NicheWithData { + A, + B([u16; 5]), + Largest { a1: u32, a2: BoolInTheMiddle, a3: u32 }, + C, + D(u32, u32), +} + +// A type with almost 2^16 invalid values. +#[repr(u16)] +pub enum NicheU16 { + _0, +} + +pub enum EnumManyVariant<X> { + Dataful(u8, X), + + // 0x100 niche variants. + _00, _01, _02, _03, _04, _05, _06, _07, _08, _09, _0A, _0B, _0C, _0D, _0E, _0F, + _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _1A, _1B, _1C, _1D, _1E, _1F, + _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _2A, _2B, _2C, _2D, _2E, _2F, + _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _3A, _3B, _3C, _3D, _3E, _3F, + _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _4A, _4B, _4C, _4D, _4E, _4F, + _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _5A, _5B, _5C, _5D, _5E, _5F, + _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _6A, _6B, _6C, _6D, _6E, _6F, + _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _7A, _7B, _7C, _7D, _7E, _7F, + _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _8A, _8B, _8C, _8D, _8E, _8F, + _90, _91, _92, _93, _94, _95, _96, _97, _98, _99, _9A, _9B, _9C, _9D, _9E, _9F, + _A0, _A1, _A2, _A3, _A4, _A5, _A6, _A7, _A8, _A9, _AA, _AB, _AC, _AD, _AE, _AF, + _B0, _B1, _B2, _B3, _B4, _B5, _B6, _B7, _B8, _B9, _BA, _BB, _BC, _BD, _BE, _BF, + _C0, _C1, _C2, _C3, _C4, _C5, _C6, _C7, _C8, _C9, _CA, _CB, _CC, _CD, _CE, _CF, + _D0, _D1, _D2, _D3, _D4, _D5, _D6, _D7, _D8, _D9, _DA, _DB, _DC, _DD, _DE, _DF, + _E0, _E1, _E2, _E3, _E4, _E5, _E6, _E7, _E8, _E9, _EA, _EB, _EC, _ED, _EE, _EF, + _F0, _F1, _F2, _F3, _F4, _F5, _F6, _F7, _F8, _F9, _FA, _FB, _FC, _FD, _FE, _FF, +} + pub fn main() { assert_eq!(size_of::<u8>(), 1 as usize); assert_eq!(size_of::<u32>(), 4 as usize); @@ -170,4 +218,35 @@ pub fn main() { assert_eq!(size_of::<AlwaysTaggedBecauseItHasNoNiche>(), 8); assert_eq!(size_of::<Option<AlwaysTaggedBecauseItHasNoNiche>>(), 8); assert_eq!(size_of::<Option<Option<AlwaysTaggedBecauseItHasNoNiche>>>(), 8); + + assert_eq!(size_of::<NicheFilledMultipleFields>(), 2); + assert_eq!(size_of::<Option<NicheFilledMultipleFields>>(), 2); + assert_eq!(size_of::<Option<Option<NicheFilledMultipleFields>>>(), 2); + + struct S1{ a: u16, b: std::num::NonZeroU16, c: u16, d: u8, e: u32, f: u64, g:[u8;2] } + assert_eq!(size_of::<S1>(), 24); + assert_eq!(size_of::<Option<S1>>(), 24); + + assert_eq!(size_of::<NicheWithData>(), 12); + assert_eq!(size_of::<Option<NicheWithData>>(), 12); + assert_eq!(size_of::<Option<Option<NicheWithData>>>(), 12); + assert_eq!( + size_of::<Option<Option2<&(), Option<NicheWithData>>>>(), + size_of::<(&(), NicheWithData)>() + ); + + pub enum FillPadding { A(std::num::NonZeroU8, u32), B } + assert_eq!(size_of::<FillPadding>(), 8); + assert_eq!(size_of::<Option<FillPadding>>(), 8); + assert_eq!(size_of::<Option<Option<FillPadding>>>(), 8); + + assert_eq!(size_of::<Result<(std::num::NonZeroU8, u8, u8), u16>>(), 4); + assert_eq!(size_of::<Option<Result<(std::num::NonZeroU8, u8, u8), u16>>>(), 4); + assert_eq!(size_of::<Result<(std::num::NonZeroU8, u8, u8, u8), u16>>(), 4); + + assert_eq!(size_of::<EnumManyVariant<u16>>(), 6); + assert_eq!(size_of::<EnumManyVariant<NicheU16>>(), 4); + assert_eq!(size_of::<EnumManyVariant<Option<NicheU16>>>(), 4); + assert_eq!(size_of::<EnumManyVariant<Option2<NicheU16,u8>>>(), 6); + assert_eq!(size_of::<EnumManyVariant<Option<(NicheU16,u8)>>>(), 6); } diff --git a/src/test/ui/structs/incomplete-fn-in-struct-definition.rs b/src/test/ui/structs/incomplete-fn-in-struct-definition.rs new file mode 100644 index 000000000..cd8a79ba6 --- /dev/null +++ b/src/test/ui/structs/incomplete-fn-in-struct-definition.rs @@ -0,0 +1,5 @@ +fn main() {} + +struct S { + fn: u8 //~ ERROR expected identifier, found keyword `fn` +} diff --git a/src/test/ui/structs/incomplete-fn-in-struct-definition.stderr b/src/test/ui/structs/incomplete-fn-in-struct-definition.stderr new file mode 100644 index 000000000..0d12ba9c9 --- /dev/null +++ b/src/test/ui/structs/incomplete-fn-in-struct-definition.stderr @@ -0,0 +1,15 @@ +error: expected identifier, found keyword `fn` + --> $DIR/incomplete-fn-in-struct-definition.rs:4:5 + | +LL | struct S { + | - while parsing this struct +LL | fn: u8 + | ^^ expected identifier, found keyword + | +help: escape `fn` to use it as an identifier + | +LL | r#fn: u8 + | ++ + +error: aborting due to previous error + diff --git a/src/test/ui/structs/struct-fn-in-definition.stderr b/src/test/ui/structs/struct-fn-in-definition.stderr index 1d7cd5272..472365c6e 100644 --- a/src/test/ui/structs/struct-fn-in-definition.stderr +++ b/src/test/ui/structs/struct-fn-in-definition.stderr @@ -1,6 +1,9 @@ error: functions are not allowed in struct definitions --> $DIR/struct-fn-in-definition.rs:9:5 | +LL | struct S { + | - while parsing this struct +... LL | fn foo() {} | ^^^^^^^^^^^ | @@ -10,6 +13,9 @@ LL | fn foo() {} error: functions are not allowed in union definitions --> $DIR/struct-fn-in-definition.rs:18:5 | +LL | union U { + | - while parsing this union +... LL | fn foo() {} | ^^^^^^^^^^^ | @@ -19,6 +25,9 @@ LL | fn foo() {} error: functions are not allowed in enum definitions --> $DIR/struct-fn-in-definition.rs:27:5 | +LL | enum E { + | - while parsing this enum +... LL | fn foo() {} | ^^^^^^^^^^^ | diff --git a/src/test/ui/structs/struct-path-associated-type.rs b/src/test/ui/structs/struct-path-associated-type.rs index f88572f84..2dd7174a9 100644 --- a/src/test/ui/structs/struct-path-associated-type.rs +++ b/src/test/ui/structs/struct-path-associated-type.rs @@ -13,7 +13,7 @@ fn f<T: Tr>() { //~^ ERROR expected struct, variant or union type, found associated type let z = T::A::<u8> {}; //~^ ERROR expected struct, variant or union type, found associated type - //~| ERROR type arguments are not allowed on this type + //~| ERROR this associated type takes 0 generic arguments but 1 generic argument was supplied match S { T::A {} => {} //~^ ERROR expected struct, variant or union type, found associated type @@ -22,7 +22,7 @@ fn f<T: Tr>() { fn g<T: Tr<A = S>>() { let s = T::A {}; // OK - let z = T::A::<u8> {}; //~ ERROR type arguments are not allowed on this type + let z = T::A::<u8> {}; //~ ERROR this associated type takes 0 generic arguments but 1 generic argument was supplied match S { T::A {} => {} // OK } diff --git a/src/test/ui/structs/struct-path-associated-type.stderr b/src/test/ui/structs/struct-path-associated-type.stderr index bdce0e1b3..abb445214 100644 --- a/src/test/ui/structs/struct-path-associated-type.stderr +++ b/src/test/ui/structs/struct-path-associated-type.stderr @@ -4,13 +4,19 @@ error[E0071]: expected struct, variant or union type, found associated type LL | let s = T::A {}; | ^^^^ not a struct -error[E0109]: type arguments are not allowed on this type - --> $DIR/struct-path-associated-type.rs:14:20 +error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/struct-path-associated-type.rs:14:16 | LL | let z = T::A::<u8> {}; - | - ^^ type argument not allowed + | ^------ help: remove these generics | | - | not allowed on this type + | expected 0 generic arguments + | +note: associated type defined here, with 0 generic parameters + --> $DIR/struct-path-associated-type.rs:4:10 + | +LL | type A; + | ^ error[E0071]: expected struct, variant or union type, found associated type --> $DIR/struct-path-associated-type.rs:14:13 @@ -24,13 +30,19 @@ error[E0071]: expected struct, variant or union type, found associated type LL | T::A {} => {} | ^^^^ not a struct -error[E0109]: type arguments are not allowed on this type - --> $DIR/struct-path-associated-type.rs:25:20 +error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/struct-path-associated-type.rs:25:16 | LL | let z = T::A::<u8> {}; - | - ^^ type argument not allowed + | ^------ help: remove these generics | | - | not allowed on this type + | expected 0 generic arguments + | +note: associated type defined here, with 0 generic parameters + --> $DIR/struct-path-associated-type.rs:4:10 + | +LL | type A; + | ^ error[E0223]: ambiguous associated type --> $DIR/struct-path-associated-type.rs:32:13 @@ -52,5 +64,5 @@ LL | S::A {} => {} error: aborting due to 8 previous errors -Some errors have detailed explanations: E0071, E0109, E0223. +Some errors have detailed explanations: E0071, E0107, E0223. For more information about an error, try `rustc --explain E0071`. diff --git a/src/test/ui/structs/struct-record-suggestion.fixed b/src/test/ui/structs/struct-record-suggestion.fixed index 48144cd1c..49e38b196 100644 --- a/src/test/ui/structs/struct-record-suggestion.fixed +++ b/src/test/ui/structs/struct-record-suggestion.fixed @@ -6,11 +6,29 @@ struct A { d: usize, } -fn main() { - let q = A { c: 5, .. Default::default() }; +fn a() { + let q = A { c: 5,..Default::default() }; //~^ ERROR mismatched types //~| ERROR missing fields //~| HELP separate the last named field with a comma - let r = A { c: 5, .. Default::default() }; + let r = A { c: 5, ..Default::default() }; assert_eq!(q, r); } + +#[derive(Debug, Default, Eq, PartialEq)] +struct B { + b: u32, +} + +fn b() { + let q = B { b: 1,..Default::default() }; + //~^ ERROR mismatched types + //~| HELP separate the last named field with a comma + let r = B { b: 1 }; + assert_eq!(q, r); +} + +fn main() { + a(); + b(); +} diff --git a/src/test/ui/structs/struct-record-suggestion.rs b/src/test/ui/structs/struct-record-suggestion.rs index 6d169d5c6..901f310c8 100644 --- a/src/test/ui/structs/struct-record-suggestion.rs +++ b/src/test/ui/structs/struct-record-suggestion.rs @@ -6,11 +6,29 @@ struct A { d: usize, } -fn main() { - let q = A { c: 5 .. Default::default() }; +fn a() { + let q = A { c: 5..Default::default() }; //~^ ERROR mismatched types //~| ERROR missing fields //~| HELP separate the last named field with a comma - let r = A { c: 5, .. Default::default() }; + let r = A { c: 5, ..Default::default() }; assert_eq!(q, r); } + +#[derive(Debug, Default, Eq, PartialEq)] +struct B { + b: u32, +} + +fn b() { + let q = B { b: 1..Default::default() }; + //~^ ERROR mismatched types + //~| HELP separate the last named field with a comma + let r = B { b: 1 }; + assert_eq!(q, r); +} + +fn main() { + a(); + b(); +} diff --git a/src/test/ui/structs/struct-record-suggestion.stderr b/src/test/ui/structs/struct-record-suggestion.stderr index e5bd03117..66e9f021e 100644 --- a/src/test/ui/structs/struct-record-suggestion.stderr +++ b/src/test/ui/structs/struct-record-suggestion.stderr @@ -1,8 +1,8 @@ error[E0308]: mismatched types --> $DIR/struct-record-suggestion.rs:10:20 | -LL | let q = A { c: 5 .. Default::default() }; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found struct `std::ops::Range` +LL | let q = A { c: 5..Default::default() }; + | ^^^^^^^^^^^^^^^^^^^^^ expected `u64`, found struct `std::ops::Range` | = note: expected type `u64` found struct `std::ops::Range<{integer}>` @@ -10,15 +10,28 @@ LL | let q = A { c: 5 .. Default::default() }; error[E0063]: missing fields `b` and `d` in initializer of `A` --> $DIR/struct-record-suggestion.rs:10:13 | -LL | let q = A { c: 5 .. Default::default() }; +LL | let q = A { c: 5..Default::default() }; | ^ missing `b` and `d` | help: to set the remaining fields from `Default::default()`, separate the last named field with a comma | -LL | let q = A { c: 5, .. Default::default() }; +LL | let q = A { c: 5,..Default::default() }; | + -error: aborting due to 2 previous errors +error[E0308]: mismatched types + --> $DIR/struct-record-suggestion.rs:24:20 + | +LL | let q = B { b: 1..Default::default() }; + | ^^^^^^^^^^^^^^^^^^^^^ expected `u32`, found struct `std::ops::Range` + | + = note: expected type `u32` + found struct `std::ops::Range<{integer}>` +help: to set the remaining fields from `Default::default()`, separate the last named field with a comma + | +LL | let q = B { b: 1,..Default::default() }; + | + + +error: aborting due to 3 previous errors Some errors have detailed explanations: E0063, E0308. For more information about an error, try `rustc --explain E0063`. |