From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/structs/auxiliary/struct_field_privacy.rs | 9 ++ .../ui/structs/auxiliary/struct_variant_privacy.rs | 3 + src/test/ui/structs/issue-80853.rs | 7 ++ src/test/ui/structs/issue-80853.stderr | 13 ++ src/test/ui/structs/large-records.rs | 38 ++++++ src/test/ui/structs/rhs-type.rs | 18 +++ src/test/ui/structs/struct-base-wrong-type.rs | 14 +++ src/test/ui/structs/struct-base-wrong-type.stderr | 27 ++++ src/test/ui/structs/struct-duplicate-comma.fixed | 15 +++ src/test/ui/structs/struct-duplicate-comma.rs | 15 +++ src/test/ui/structs/struct-duplicate-comma.stderr | 13 ++ src/test/ui/structs/struct-field-cfg.rs | 18 +++ src/test/ui/structs/struct-field-cfg.stderr | 39 ++++++ src/test/ui/structs/struct-field-init-syntax.rs | 20 +++ .../ui/structs/struct-field-init-syntax.stderr | 18 +++ src/test/ui/structs/struct-field-privacy.rs | 38 ++++++ src/test/ui/structs/struct-field-privacy.stderr | 33 +++++ src/test/ui/structs/struct-fields-decl-dupe.rs | 8 ++ src/test/ui/structs/struct-fields-decl-dupe.stderr | 11 ++ src/test/ui/structs/struct-fields-dupe.rs | 10 ++ src/test/ui/structs/struct-fields-dupe.stderr | 11 ++ src/test/ui/structs/struct-fields-hints-no-dupe.rs | 14 +++ .../ui/structs/struct-fields-hints-no-dupe.stderr | 9 ++ src/test/ui/structs/struct-fields-hints.rs | 13 ++ src/test/ui/structs/struct-fields-hints.stderr | 9 ++ src/test/ui/structs/struct-fields-missing.rs | 10 ++ src/test/ui/structs/struct-fields-missing.stderr | 9 ++ .../structs/struct-fields-shorthand-unresolved.rs | 12 ++ .../struct-fields-shorthand-unresolved.stderr | 9 ++ src/test/ui/structs/struct-fields-shorthand.rs | 11 ++ src/test/ui/structs/struct-fields-shorthand.stderr | 11 ++ src/test/ui/structs/struct-fields-too-many.rs | 11 ++ src/test/ui/structs/struct-fields-too-many.stderr | 11 ++ src/test/ui/structs/struct-fields-typo.rs | 15 +++ src/test/ui/structs/struct-fields-typo.stderr | 9 ++ src/test/ui/structs/struct-fn-in-definition.rs | 33 +++++ src/test/ui/structs/struct-fn-in-definition.stderr | 29 +++++ src/test/ui/structs/struct-missing-comma.fixed | 12 ++ src/test/ui/structs/struct-missing-comma.rs | 12 ++ src/test/ui/structs/struct-missing-comma.stderr | 8 ++ src/test/ui/structs/struct-pat-derived-error.rs | 14 +++ .../ui/structs/struct-pat-derived-error.stderr | 31 +++++ src/test/ui/structs/struct-path-alias-bounds.rs | 11 ++ .../ui/structs/struct-path-alias-bounds.stderr | 19 +++ src/test/ui/structs/struct-path-associated-type.rs | 37 ++++++ .../ui/structs/struct-path-associated-type.stderr | 56 +++++++++ .../ui/structs/struct-path-self-type-mismatch.rs | 21 ++++ .../structs/struct-path-self-type-mismatch.stderr | 46 +++++++ src/test/ui/structs/struct-path-self.rs | 37 ++++++ src/test/ui/structs/struct-path-self.stderr | 80 ++++++++++++ src/test/ui/structs/struct-record-suggestion.fixed | 16 +++ src/test/ui/structs/struct-record-suggestion.rs | 16 +++ .../ui/structs/struct-record-suggestion.stderr | 24 ++++ src/test/ui/structs/struct-tuple-field-names.rs | 15 +++ .../ui/structs/struct-tuple-field-names.stderr | 25 ++++ src/test/ui/structs/struct-variant-privacy-xc.rs | 11 ++ .../ui/structs/struct-variant-privacy-xc.stderr | 27 ++++ src/test/ui/structs/struct-variant-privacy.rs | 14 +++ src/test/ui/structs/struct-variant-privacy.stderr | 27 ++++ .../structs/structure-constructor-type-mismatch.rs | 73 +++++++++++ .../structure-constructor-type-mismatch.stderr | 137 +++++++++++++++++++++ src/test/ui/structs/suggest-private-fields.rs | 27 ++++ src/test/ui/structs/suggest-private-fields.stderr | 29 +++++ ...st-replacing-field-when-specifying-same-type.rs | 28 +++++ ...eplacing-field-when-specifying-same-type.stderr | 94 ++++++++++++++ 65 files changed, 1540 insertions(+) create mode 100644 src/test/ui/structs/auxiliary/struct_field_privacy.rs create mode 100644 src/test/ui/structs/auxiliary/struct_variant_privacy.rs create mode 100644 src/test/ui/structs/issue-80853.rs create mode 100644 src/test/ui/structs/issue-80853.stderr create mode 100644 src/test/ui/structs/large-records.rs create mode 100644 src/test/ui/structs/rhs-type.rs create mode 100644 src/test/ui/structs/struct-base-wrong-type.rs create mode 100644 src/test/ui/structs/struct-base-wrong-type.stderr create mode 100644 src/test/ui/structs/struct-duplicate-comma.fixed create mode 100644 src/test/ui/structs/struct-duplicate-comma.rs create mode 100644 src/test/ui/structs/struct-duplicate-comma.stderr create mode 100644 src/test/ui/structs/struct-field-cfg.rs create mode 100644 src/test/ui/structs/struct-field-cfg.stderr create mode 100644 src/test/ui/structs/struct-field-init-syntax.rs create mode 100644 src/test/ui/structs/struct-field-init-syntax.stderr create mode 100644 src/test/ui/structs/struct-field-privacy.rs create mode 100644 src/test/ui/structs/struct-field-privacy.stderr create mode 100644 src/test/ui/structs/struct-fields-decl-dupe.rs create mode 100644 src/test/ui/structs/struct-fields-decl-dupe.stderr create mode 100644 src/test/ui/structs/struct-fields-dupe.rs create mode 100644 src/test/ui/structs/struct-fields-dupe.stderr create mode 100644 src/test/ui/structs/struct-fields-hints-no-dupe.rs create mode 100644 src/test/ui/structs/struct-fields-hints-no-dupe.stderr create mode 100644 src/test/ui/structs/struct-fields-hints.rs create mode 100644 src/test/ui/structs/struct-fields-hints.stderr create mode 100644 src/test/ui/structs/struct-fields-missing.rs create mode 100644 src/test/ui/structs/struct-fields-missing.stderr create mode 100644 src/test/ui/structs/struct-fields-shorthand-unresolved.rs create mode 100644 src/test/ui/structs/struct-fields-shorthand-unresolved.stderr create mode 100644 src/test/ui/structs/struct-fields-shorthand.rs create mode 100644 src/test/ui/structs/struct-fields-shorthand.stderr create mode 100644 src/test/ui/structs/struct-fields-too-many.rs create mode 100644 src/test/ui/structs/struct-fields-too-many.stderr create mode 100644 src/test/ui/structs/struct-fields-typo.rs create mode 100644 src/test/ui/structs/struct-fields-typo.stderr create mode 100644 src/test/ui/structs/struct-fn-in-definition.rs create mode 100644 src/test/ui/structs/struct-fn-in-definition.stderr create mode 100644 src/test/ui/structs/struct-missing-comma.fixed create mode 100644 src/test/ui/structs/struct-missing-comma.rs create mode 100644 src/test/ui/structs/struct-missing-comma.stderr create mode 100644 src/test/ui/structs/struct-pat-derived-error.rs create mode 100644 src/test/ui/structs/struct-pat-derived-error.stderr create mode 100644 src/test/ui/structs/struct-path-alias-bounds.rs create mode 100644 src/test/ui/structs/struct-path-alias-bounds.stderr create mode 100644 src/test/ui/structs/struct-path-associated-type.rs create mode 100644 src/test/ui/structs/struct-path-associated-type.stderr create mode 100644 src/test/ui/structs/struct-path-self-type-mismatch.rs create mode 100644 src/test/ui/structs/struct-path-self-type-mismatch.stderr create mode 100644 src/test/ui/structs/struct-path-self.rs create mode 100644 src/test/ui/structs/struct-path-self.stderr create mode 100644 src/test/ui/structs/struct-record-suggestion.fixed create mode 100644 src/test/ui/structs/struct-record-suggestion.rs create mode 100644 src/test/ui/structs/struct-record-suggestion.stderr create mode 100644 src/test/ui/structs/struct-tuple-field-names.rs create mode 100644 src/test/ui/structs/struct-tuple-field-names.stderr create mode 100644 src/test/ui/structs/struct-variant-privacy-xc.rs create mode 100644 src/test/ui/structs/struct-variant-privacy-xc.stderr create mode 100644 src/test/ui/structs/struct-variant-privacy.rs create mode 100644 src/test/ui/structs/struct-variant-privacy.stderr create mode 100644 src/test/ui/structs/structure-constructor-type-mismatch.rs create mode 100644 src/test/ui/structs/structure-constructor-type-mismatch.stderr create mode 100644 src/test/ui/structs/suggest-private-fields.rs create mode 100644 src/test/ui/structs/suggest-private-fields.stderr create mode 100644 src/test/ui/structs/suggest-replacing-field-when-specifying-same-type.rs create mode 100644 src/test/ui/structs/suggest-replacing-field-when-specifying-same-type.stderr (limited to 'src/test/ui/structs') diff --git a/src/test/ui/structs/auxiliary/struct_field_privacy.rs b/src/test/ui/structs/auxiliary/struct_field_privacy.rs new file mode 100644 index 000000000..9765af1a7 --- /dev/null +++ b/src/test/ui/structs/auxiliary/struct_field_privacy.rs @@ -0,0 +1,9 @@ +pub struct A { + a: isize, + pub b: isize, +} + +pub struct B { + pub a: isize, + b: isize, +} diff --git a/src/test/ui/structs/auxiliary/struct_variant_privacy.rs b/src/test/ui/structs/auxiliary/struct_variant_privacy.rs new file mode 100644 index 000000000..425ec0e96 --- /dev/null +++ b/src/test/ui/structs/auxiliary/struct_variant_privacy.rs @@ -0,0 +1,3 @@ +enum Bar { + Baz { a: isize } +} diff --git a/src/test/ui/structs/issue-80853.rs b/src/test/ui/structs/issue-80853.rs new file mode 100644 index 000000000..242d0af95 --- /dev/null +++ b/src/test/ui/structs/issue-80853.rs @@ -0,0 +1,7 @@ +struct S; + +fn repro_ref(thing: S) { + thing(); //~ ERROR expected function, found `S` +} + +fn main() {} diff --git a/src/test/ui/structs/issue-80853.stderr b/src/test/ui/structs/issue-80853.stderr new file mode 100644 index 000000000..1c7d52b6d --- /dev/null +++ b/src/test/ui/structs/issue-80853.stderr @@ -0,0 +1,13 @@ +error[E0618]: expected function, found `S` + --> $DIR/issue-80853.rs:4:5 + | +LL | fn repro_ref(thing: S) { + | ----- `thing` has type `S` +LL | thing(); + | ^^^^^-- + | | + | call expression requires function + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0618`. diff --git a/src/test/ui/structs/large-records.rs b/src/test/ui/structs/large-records.rs new file mode 100644 index 000000000..7f850a94e --- /dev/null +++ b/src/test/ui/structs/large-records.rs @@ -0,0 +1,38 @@ +// run-pass + +#![allow(dead_code)] + + + + +// pretty-expanded FIXME #23616 + +struct Large {a: isize, + b: isize, + c: isize, + d: isize, + e: isize, + f: isize, + g: isize, + h: isize, + i: isize, + j: isize, + k: isize, + l: isize} +fn f() { + let _foo: Large = + Large {a: 0, + b: 0, + c: 0, + d: 0, + e: 0, + f: 0, + g: 0, + h: 0, + i: 0, + j: 0, + k: 0, + l: 0}; +} + +pub fn main() { f(); } diff --git a/src/test/ui/structs/rhs-type.rs b/src/test/ui/structs/rhs-type.rs new file mode 100644 index 000000000..c48e7c08e --- /dev/null +++ b/src/test/ui/structs/rhs-type.rs @@ -0,0 +1,18 @@ +// Tests that codegen treats the rhs of pth's decl +// as a _|_-typed thing, not a str-typed thing + +// run-fail +// error-pattern:bye +// ignore-emscripten no processes + +#![allow(unreachable_code)] +#![allow(unused_variables)] + +struct T { + t: String, +} + +fn main() { + let pth = panic!("bye"); + let _rs: T = T { t: pth }; +} diff --git a/src/test/ui/structs/struct-base-wrong-type.rs b/src/test/ui/structs/struct-base-wrong-type.rs new file mode 100644 index 000000000..b64c6b499 --- /dev/null +++ b/src/test/ui/structs/struct-base-wrong-type.rs @@ -0,0 +1,14 @@ +// Check that `base` in `Fru { field: expr, ..base }` must have right type. + +struct Foo { a: isize, b: isize } +struct Bar { x: isize } + +static bar: Bar = Bar { x: 5 }; +static foo: Foo = Foo { a: 2, ..bar }; //~ ERROR mismatched types +static foo_i: Foo = Foo { a: 2, ..4 }; //~ ERROR mismatched types + +fn main() { + let b = Bar { x: 5 }; + let f = Foo { a: 2, ..b }; //~ ERROR mismatched types + let f__isize = Foo { a: 2, ..4 }; //~ ERROR mismatched types +} diff --git a/src/test/ui/structs/struct-base-wrong-type.stderr b/src/test/ui/structs/struct-base-wrong-type.stderr new file mode 100644 index 000000000..b039ce2cc --- /dev/null +++ b/src/test/ui/structs/struct-base-wrong-type.stderr @@ -0,0 +1,27 @@ +error[E0308]: mismatched types + --> $DIR/struct-base-wrong-type.rs:7:33 + | +LL | static foo: Foo = Foo { a: 2, ..bar }; + | ^^^ expected struct `Foo`, found struct `Bar` + +error[E0308]: mismatched types + --> $DIR/struct-base-wrong-type.rs:8:35 + | +LL | static foo_i: Foo = Foo { a: 2, ..4 }; + | ^ expected struct `Foo`, found integer + +error[E0308]: mismatched types + --> $DIR/struct-base-wrong-type.rs:12:27 + | +LL | let f = Foo { a: 2, ..b }; + | ^ expected struct `Foo`, found struct `Bar` + +error[E0308]: mismatched types + --> $DIR/struct-base-wrong-type.rs:13:34 + | +LL | let f__isize = Foo { a: 2, ..4 }; + | ^ expected struct `Foo`, found integer + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/structs/struct-duplicate-comma.fixed b/src/test/ui/structs/struct-duplicate-comma.fixed new file mode 100644 index 000000000..c804cf57a --- /dev/null +++ b/src/test/ui/structs/struct-duplicate-comma.fixed @@ -0,0 +1,15 @@ +// run-rustfix +// Issue #50974 + +pub struct Foo { + pub a: u8, + pub b: u8 +} + +fn main() { + let _ = Foo { + a: 0, + //~^ ERROR expected identifier + b: 42 + }; +} diff --git a/src/test/ui/structs/struct-duplicate-comma.rs b/src/test/ui/structs/struct-duplicate-comma.rs new file mode 100644 index 000000000..db2e7cb3d --- /dev/null +++ b/src/test/ui/structs/struct-duplicate-comma.rs @@ -0,0 +1,15 @@ +// run-rustfix +// Issue #50974 + +pub struct Foo { + pub a: u8, + pub b: u8 +} + +fn main() { + let _ = Foo { + a: 0,, + //~^ ERROR expected identifier + b: 42 + }; +} diff --git a/src/test/ui/structs/struct-duplicate-comma.stderr b/src/test/ui/structs/struct-duplicate-comma.stderr new file mode 100644 index 000000000..834b3c5c1 --- /dev/null +++ b/src/test/ui/structs/struct-duplicate-comma.stderr @@ -0,0 +1,13 @@ +error: expected identifier, found `,` + --> $DIR/struct-duplicate-comma.rs:11:14 + | +LL | let _ = Foo { + | --- while parsing this struct +LL | a: 0,, + | ^ + | | + | expected identifier + | help: remove this comma + +error: aborting due to previous error + diff --git a/src/test/ui/structs/struct-field-cfg.rs b/src/test/ui/structs/struct-field-cfg.rs new file mode 100644 index 000000000..42cab8ab9 --- /dev/null +++ b/src/test/ui/structs/struct-field-cfg.rs @@ -0,0 +1,18 @@ +struct Foo { + present: (), +} + +fn main() { + let foo = Foo { #[cfg(all())] present: () }; + let _ = Foo { #[cfg(any())] present: () }; + //~^ ERROR missing field `present` in initializer of `Foo` + let _ = Foo { present: (), #[cfg(any())] absent: () }; + let _ = Foo { present: (), #[cfg(all())] absent: () }; + //~^ ERROR struct `Foo` has no field named `absent` + let Foo { #[cfg(all())] present: () } = foo; + let Foo { #[cfg(any())] present: () } = foo; + //~^ ERROR pattern does not mention field `present` + let Foo { present: (), #[cfg(any())] absent: () } = foo; + let Foo { present: (), #[cfg(all())] absent: () } = foo; + //~^ ERROR struct `Foo` does not have a field named `absent` +} diff --git a/src/test/ui/structs/struct-field-cfg.stderr b/src/test/ui/structs/struct-field-cfg.stderr new file mode 100644 index 000000000..5ec47c093 --- /dev/null +++ b/src/test/ui/structs/struct-field-cfg.stderr @@ -0,0 +1,39 @@ +error[E0063]: missing field `present` in initializer of `Foo` + --> $DIR/struct-field-cfg.rs:7:13 + | +LL | let _ = Foo { #[cfg(any())] present: () }; + | ^^^ missing `present` + +error[E0560]: struct `Foo` has no field named `absent` + --> $DIR/struct-field-cfg.rs:10:46 + | +LL | let _ = Foo { present: (), #[cfg(all())] absent: () }; + | ^^^^^^ `Foo` does not have this field + | + = note: available fields are: `present` + +error[E0027]: pattern does not mention field `present` + --> $DIR/struct-field-cfg.rs:13:9 + | +LL | let Foo { #[cfg(any())] present: () } = foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `present` + | +help: include the missing field in the pattern + | +LL | let Foo { present } = foo; + | ~~~~~~~~~~~ +help: if you don't care about this missing field, you can explicitly ignore it + | +LL | let Foo { .. } = foo; + | ~~~~~~ + +error[E0026]: struct `Foo` does not have a field named `absent` + --> $DIR/struct-field-cfg.rs:16:42 + | +LL | let Foo { present: (), #[cfg(all())] absent: () } = foo; + | ^^^^^^ struct `Foo` does not have this field + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0026, E0027, E0063, E0560. +For more information about an error, try `rustc --explain E0026`. diff --git a/src/test/ui/structs/struct-field-init-syntax.rs b/src/test/ui/structs/struct-field-init-syntax.rs new file mode 100644 index 000000000..161f7e93a --- /dev/null +++ b/src/test/ui/structs/struct-field-init-syntax.rs @@ -0,0 +1,20 @@ +// issue #41834 + +#[derive(Default)] +struct Foo { + one: u8, +} + +fn main() { + let foo = Foo { + one: 111, + ..Foo::default(), + //~^ ERROR cannot use a comma after the base struct + }; + + let foo = Foo { + ..Foo::default(), + //~^ ERROR cannot use a comma after the base struct + one: 111, + }; +} diff --git a/src/test/ui/structs/struct-field-init-syntax.stderr b/src/test/ui/structs/struct-field-init-syntax.stderr new file mode 100644 index 000000000..0b72c5cf7 --- /dev/null +++ b/src/test/ui/structs/struct-field-init-syntax.stderr @@ -0,0 +1,18 @@ +error: cannot use a comma after the base struct + --> $DIR/struct-field-init-syntax.rs:11:9 + | +LL | ..Foo::default(), + | ^^^^^^^^^^^^^^^^- help: remove this comma + | + = note: the base struct must always be the last field + +error: cannot use a comma after the base struct + --> $DIR/struct-field-init-syntax.rs:16:9 + | +LL | ..Foo::default(), + | ^^^^^^^^^^^^^^^^- help: remove this comma + | + = note: the base struct must always be the last field + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/structs/struct-field-privacy.rs b/src/test/ui/structs/struct-field-privacy.rs new file mode 100644 index 000000000..898ca475c --- /dev/null +++ b/src/test/ui/structs/struct-field-privacy.rs @@ -0,0 +1,38 @@ +// aux-build:struct_field_privacy.rs + +extern crate struct_field_privacy as xc; + +struct A { + a: isize, +} + +mod inner { + pub struct A { + a: isize, + pub b: isize, + } + pub struct B { + pub a: isize, + b: isize, + } + pub struct Z(pub isize, isize); +} + +fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B, z: inner::Z) { + a.a; + b.a; //~ ERROR: field `a` of struct `inner::A` is private + b.b; + c.a; + c.b; //~ ERROR: field `b` of struct `inner::B` is private + + d.a; //~ ERROR: field `a` of struct `xc::A` is private + d.b; + + e.a; + e.b; //~ ERROR: field `b` of struct `xc::B` is private + + z.0; + z.1; //~ ERROR: field `1` of struct `Z` is private +} + +fn main() {} diff --git a/src/test/ui/structs/struct-field-privacy.stderr b/src/test/ui/structs/struct-field-privacy.stderr new file mode 100644 index 000000000..ee83e0d6c --- /dev/null +++ b/src/test/ui/structs/struct-field-privacy.stderr @@ -0,0 +1,33 @@ +error[E0616]: field `a` of struct `inner::A` is private + --> $DIR/struct-field-privacy.rs:23:7 + | +LL | b.a; + | ^ private field + +error[E0616]: field `b` of struct `inner::B` is private + --> $DIR/struct-field-privacy.rs:26:7 + | +LL | c.b; + | ^ private field + +error[E0616]: field `a` of struct `xc::A` is private + --> $DIR/struct-field-privacy.rs:28:7 + | +LL | d.a; + | ^ private field + +error[E0616]: field `b` of struct `xc::B` is private + --> $DIR/struct-field-privacy.rs:32:7 + | +LL | e.b; + | ^ private field + +error[E0616]: field `1` of struct `Z` is private + --> $DIR/struct-field-privacy.rs:35:7 + | +LL | z.1; + | ^ private field + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0616`. diff --git a/src/test/ui/structs/struct-fields-decl-dupe.rs b/src/test/ui/structs/struct-fields-decl-dupe.rs new file mode 100644 index 000000000..6ddf3d976 --- /dev/null +++ b/src/test/ui/structs/struct-fields-decl-dupe.rs @@ -0,0 +1,8 @@ +struct BuildData { + foo: isize, + foo: isize, + //~^ ERROR field `foo` is already declared [E0124] +} + +fn main() { +} diff --git a/src/test/ui/structs/struct-fields-decl-dupe.stderr b/src/test/ui/structs/struct-fields-decl-dupe.stderr new file mode 100644 index 000000000..d7ce9bb89 --- /dev/null +++ b/src/test/ui/structs/struct-fields-decl-dupe.stderr @@ -0,0 +1,11 @@ +error[E0124]: field `foo` is already declared + --> $DIR/struct-fields-decl-dupe.rs:3:5 + | +LL | foo: isize, + | ---------- `foo` first declared here +LL | foo: isize, + | ^^^^^^^^^^ field already declared + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0124`. diff --git a/src/test/ui/structs/struct-fields-dupe.rs b/src/test/ui/structs/struct-fields-dupe.rs new file mode 100644 index 000000000..2fa25a335 --- /dev/null +++ b/src/test/ui/structs/struct-fields-dupe.rs @@ -0,0 +1,10 @@ +struct BuildData { + foo: isize, +} + +fn main() { + let foo = BuildData { + foo: 0, + foo: 0 //~ ERROR field `foo` specified more than once + }; +} diff --git a/src/test/ui/structs/struct-fields-dupe.stderr b/src/test/ui/structs/struct-fields-dupe.stderr new file mode 100644 index 000000000..aaf2533dc --- /dev/null +++ b/src/test/ui/structs/struct-fields-dupe.stderr @@ -0,0 +1,11 @@ +error[E0062]: field `foo` specified more than once + --> $DIR/struct-fields-dupe.rs:8:9 + | +LL | foo: 0, + | ------ first use of `foo` +LL | foo: 0 + | ^^^ used more than once + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0062`. diff --git a/src/test/ui/structs/struct-fields-hints-no-dupe.rs b/src/test/ui/structs/struct-fields-hints-no-dupe.rs new file mode 100644 index 000000000..987cf726f --- /dev/null +++ b/src/test/ui/structs/struct-fields-hints-no-dupe.rs @@ -0,0 +1,14 @@ +struct A { + foo : i32, + car : i32, + barr : i32 +} + +fn main() { + let a = A { + foo : 5, + bar : 42, + //~^ ERROR struct `A` has no field named `bar` + car : 9, + }; +} diff --git a/src/test/ui/structs/struct-fields-hints-no-dupe.stderr b/src/test/ui/structs/struct-fields-hints-no-dupe.stderr new file mode 100644 index 000000000..1a88f2693 --- /dev/null +++ b/src/test/ui/structs/struct-fields-hints-no-dupe.stderr @@ -0,0 +1,9 @@ +error[E0560]: struct `A` has no field named `bar` + --> $DIR/struct-fields-hints-no-dupe.rs:10:9 + | +LL | bar : 42, + | ^^^ help: a field with a similar name exists: `barr` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0560`. diff --git a/src/test/ui/structs/struct-fields-hints.rs b/src/test/ui/structs/struct-fields-hints.rs new file mode 100644 index 000000000..08df0930e --- /dev/null +++ b/src/test/ui/structs/struct-fields-hints.rs @@ -0,0 +1,13 @@ +struct A { + foo : i32, + car : i32, + barr : i32 +} + +fn main() { + let a = A { + foo : 5, + bar : 42, + //~^ ERROR struct `A` has no field named `bar` + }; +} diff --git a/src/test/ui/structs/struct-fields-hints.stderr b/src/test/ui/structs/struct-fields-hints.stderr new file mode 100644 index 000000000..3b8a2b5c7 --- /dev/null +++ b/src/test/ui/structs/struct-fields-hints.stderr @@ -0,0 +1,9 @@ +error[E0560]: struct `A` has no field named `bar` + --> $DIR/struct-fields-hints.rs:10:9 + | +LL | bar : 42, + | ^^^ help: a field with a similar name exists: `car` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0560`. diff --git a/src/test/ui/structs/struct-fields-missing.rs b/src/test/ui/structs/struct-fields-missing.rs new file mode 100644 index 000000000..0c7919d02 --- /dev/null +++ b/src/test/ui/structs/struct-fields-missing.rs @@ -0,0 +1,10 @@ +struct BuildData { + foo: isize, + bar: Box, +} + +fn main() { + let foo = BuildData { //~ ERROR missing field `bar` in initializer of `BuildData` + foo: 0 + }; +} diff --git a/src/test/ui/structs/struct-fields-missing.stderr b/src/test/ui/structs/struct-fields-missing.stderr new file mode 100644 index 000000000..b3e42a948 --- /dev/null +++ b/src/test/ui/structs/struct-fields-missing.stderr @@ -0,0 +1,9 @@ +error[E0063]: missing field `bar` in initializer of `BuildData` + --> $DIR/struct-fields-missing.rs:7:15 + | +LL | let foo = BuildData { + | ^^^^^^^^^ missing `bar` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0063`. diff --git a/src/test/ui/structs/struct-fields-shorthand-unresolved.rs b/src/test/ui/structs/struct-fields-shorthand-unresolved.rs new file mode 100644 index 000000000..caad14916 --- /dev/null +++ b/src/test/ui/structs/struct-fields-shorthand-unresolved.rs @@ -0,0 +1,12 @@ +struct Foo { + x: i32, + y: i32 +} + +fn main() { + let x = 0; + let foo = Foo { + x, + y //~ ERROR cannot find value `y` in this scope + }; +} diff --git a/src/test/ui/structs/struct-fields-shorthand-unresolved.stderr b/src/test/ui/structs/struct-fields-shorthand-unresolved.stderr new file mode 100644 index 000000000..09fc4f7ee --- /dev/null +++ b/src/test/ui/structs/struct-fields-shorthand-unresolved.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find value `y` in this scope + --> $DIR/struct-fields-shorthand-unresolved.rs:10:9 + | +LL | y + | ^ help: a local variable with a similar name exists: `x` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/structs/struct-fields-shorthand.rs b/src/test/ui/structs/struct-fields-shorthand.rs new file mode 100644 index 000000000..1bdcc8315 --- /dev/null +++ b/src/test/ui/structs/struct-fields-shorthand.rs @@ -0,0 +1,11 @@ +struct Foo { + x: i32, + y: i32 +} + +fn main() { + let (x, y, z) = (0, 1, 2); + let foo = Foo { + x, y, z //~ ERROR struct `Foo` has no field named `z` + }; +} diff --git a/src/test/ui/structs/struct-fields-shorthand.stderr b/src/test/ui/structs/struct-fields-shorthand.stderr new file mode 100644 index 000000000..a285a3921 --- /dev/null +++ b/src/test/ui/structs/struct-fields-shorthand.stderr @@ -0,0 +1,11 @@ +error[E0560]: struct `Foo` has no field named `z` + --> $DIR/struct-fields-shorthand.rs:9:15 + | +LL | x, y, z + | ^ `Foo` does not have this field + | + = note: available fields are: `x`, `y` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0560`. diff --git a/src/test/ui/structs/struct-fields-too-many.rs b/src/test/ui/structs/struct-fields-too-many.rs new file mode 100644 index 000000000..8be8dcbf1 --- /dev/null +++ b/src/test/ui/structs/struct-fields-too-many.rs @@ -0,0 +1,11 @@ +struct BuildData { + foo: isize, +} + +fn main() { + let foo = BuildData { + foo: 0, + bar: 0 + //~^ ERROR struct `BuildData` has no field named `bar` + }; +} diff --git a/src/test/ui/structs/struct-fields-too-many.stderr b/src/test/ui/structs/struct-fields-too-many.stderr new file mode 100644 index 000000000..a1b7a7a31 --- /dev/null +++ b/src/test/ui/structs/struct-fields-too-many.stderr @@ -0,0 +1,11 @@ +error[E0560]: struct `BuildData` has no field named `bar` + --> $DIR/struct-fields-too-many.rs:8:9 + | +LL | bar: 0 + | ^^^ `BuildData` does not have this field + | + = note: available fields are: `foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0560`. diff --git a/src/test/ui/structs/struct-fields-typo.rs b/src/test/ui/structs/struct-fields-typo.rs new file mode 100644 index 000000000..0e9b2ae51 --- /dev/null +++ b/src/test/ui/structs/struct-fields-typo.rs @@ -0,0 +1,15 @@ +struct BuildData { + foo: isize, + bar: f32 +} + +fn main() { + let foo = BuildData { + foo: 0, + bar: 0.5, + }; + let x = foo.baa; //~ ERROR no field `baa` on type `BuildData` + //~| HELP a field with a similar name exists + //~| SUGGESTION bar + println!("{}", x); +} diff --git a/src/test/ui/structs/struct-fields-typo.stderr b/src/test/ui/structs/struct-fields-typo.stderr new file mode 100644 index 000000000..6949a0a4a --- /dev/null +++ b/src/test/ui/structs/struct-fields-typo.stderr @@ -0,0 +1,9 @@ +error[E0609]: no field `baa` on type `BuildData` + --> $DIR/struct-fields-typo.rs:11:17 + | +LL | let x = foo.baa; + | ^^^ help: a field with a similar name exists: `bar` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0609`. diff --git a/src/test/ui/structs/struct-fn-in-definition.rs b/src/test/ui/structs/struct-fn-in-definition.rs new file mode 100644 index 000000000..5ae1b727d --- /dev/null +++ b/src/test/ui/structs/struct-fn-in-definition.rs @@ -0,0 +1,33 @@ +// It might be intuitive for a user coming from languages like Java +// to declare a method directly in a struct's definition. Make sure +// rustc can give a helpful suggestion. +// Suggested in issue #76421 + +struct S { + field: usize, + + fn foo() {} + //~^ ERROR functions are not allowed in struct definitions + //~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks + //~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information +} + +union U { + variant: usize, + + fn foo() {} + //~^ ERROR functions are not allowed in union definitions + //~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks + //~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information +} + +enum E { + Variant, + + fn foo() {} + //~^ ERROR functions are not allowed in enum definitions + //~| HELP unlike in C++, Java, and C#, functions are declared in `impl` blocks + //~| HELP see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information +} + +fn main() {} diff --git a/src/test/ui/structs/struct-fn-in-definition.stderr b/src/test/ui/structs/struct-fn-in-definition.stderr new file mode 100644 index 000000000..1d7cd5272 --- /dev/null +++ b/src/test/ui/structs/struct-fn-in-definition.stderr @@ -0,0 +1,29 @@ +error: functions are not allowed in struct definitions + --> $DIR/struct-fn-in-definition.rs:9:5 + | +LL | fn foo() {} + | ^^^^^^^^^^^ + | + = help: unlike in C++, Java, and C#, functions are declared in `impl` blocks + = help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information + +error: functions are not allowed in union definitions + --> $DIR/struct-fn-in-definition.rs:18:5 + | +LL | fn foo() {} + | ^^^^^^^^^^^ + | + = help: unlike in C++, Java, and C#, functions are declared in `impl` blocks + = help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information + +error: functions are not allowed in enum definitions + --> $DIR/struct-fn-in-definition.rs:27:5 + | +LL | fn foo() {} + | ^^^^^^^^^^^ + | + = help: unlike in C++, Java, and C#, functions are declared in `impl` blocks + = help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/structs/struct-missing-comma.fixed b/src/test/ui/structs/struct-missing-comma.fixed new file mode 100644 index 000000000..a28179ba2 --- /dev/null +++ b/src/test/ui/structs/struct-missing-comma.fixed @@ -0,0 +1,12 @@ +// Issue #50636 +// run-rustfix + +pub struct S { + pub foo: u32, //~ expected `,`, or `}`, found keyword `pub` + // ~^ HELP try adding a comma: ',' + pub bar: u32 +} + +fn main() { + let _ = S { foo: 5, bar: 6 }; +} diff --git a/src/test/ui/structs/struct-missing-comma.rs b/src/test/ui/structs/struct-missing-comma.rs new file mode 100644 index 000000000..b6d6c9b8f --- /dev/null +++ b/src/test/ui/structs/struct-missing-comma.rs @@ -0,0 +1,12 @@ +// Issue #50636 +// run-rustfix + +pub struct S { + pub foo: u32 //~ expected `,`, or `}`, found keyword `pub` + // ~^ HELP try adding a comma: ',' + pub bar: u32 +} + +fn main() { + let _ = S { foo: 5, bar: 6 }; +} diff --git a/src/test/ui/structs/struct-missing-comma.stderr b/src/test/ui/structs/struct-missing-comma.stderr new file mode 100644 index 000000000..eceec65e7 --- /dev/null +++ b/src/test/ui/structs/struct-missing-comma.stderr @@ -0,0 +1,8 @@ +error: expected `,`, or `}`, found keyword `pub` + --> $DIR/struct-missing-comma.rs:5:17 + | +LL | pub foo: u32 + | ^ help: try adding a comma: `,` + +error: aborting due to previous error + diff --git a/src/test/ui/structs/struct-pat-derived-error.rs b/src/test/ui/structs/struct-pat-derived-error.rs new file mode 100644 index 000000000..f49a8ff8b --- /dev/null +++ b/src/test/ui/structs/struct-pat-derived-error.rs @@ -0,0 +1,14 @@ +struct A { + b: usize, + c: usize +} + +impl A { + fn foo(&self) { + let A { x, y } = self.d; //~ ERROR no field `d` on type `&A` + //~^ ERROR struct `A` does not have fields named `x`, `y` + //~| ERROR pattern does not mention fields `b`, `c` + } +} + +fn main() {} diff --git a/src/test/ui/structs/struct-pat-derived-error.stderr b/src/test/ui/structs/struct-pat-derived-error.stderr new file mode 100644 index 000000000..a91e47657 --- /dev/null +++ b/src/test/ui/structs/struct-pat-derived-error.stderr @@ -0,0 +1,31 @@ +error[E0609]: no field `d` on type `&A` + --> $DIR/struct-pat-derived-error.rs:8:31 + | +LL | let A { x, y } = self.d; + | ^ help: a field with a similar name exists: `b` + +error[E0026]: struct `A` does not have fields named `x`, `y` + --> $DIR/struct-pat-derived-error.rs:8:17 + | +LL | let A { x, y } = self.d; + | ^ ^ struct `A` does not have these fields + +error[E0027]: pattern does not mention fields `b`, `c` + --> $DIR/struct-pat-derived-error.rs:8:13 + | +LL | let A { x, y } = self.d; + | ^^^^^^^^^^ missing fields `b`, `c` + | +help: include the missing fields in the pattern + | +LL | let A { x, y, b, c } = self.d; + | ~~~~~~~~ +help: if you don't care about these missing fields, you can explicitly ignore them + | +LL | let A { x, y, .. } = self.d; + | ~~~~~~ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0026, E0027, E0609. +For more information about an error, try `rustc --explain E0026`. diff --git a/src/test/ui/structs/struct-path-alias-bounds.rs b/src/test/ui/structs/struct-path-alias-bounds.rs new file mode 100644 index 000000000..1e2c4b836 --- /dev/null +++ b/src/test/ui/structs/struct-path-alias-bounds.rs @@ -0,0 +1,11 @@ +// issue #36286 + +struct S { a: T } + +struct NoClone; +type A = S; + +fn main() { + let s = A { a: NoClone }; + //~^ ERROR the trait bound `NoClone: Clone` is not satisfied +} diff --git a/src/test/ui/structs/struct-path-alias-bounds.stderr b/src/test/ui/structs/struct-path-alias-bounds.stderr new file mode 100644 index 000000000..266291f62 --- /dev/null +++ b/src/test/ui/structs/struct-path-alias-bounds.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `NoClone: Clone` is not satisfied + --> $DIR/struct-path-alias-bounds.rs:9:13 + | +LL | let s = A { a: NoClone }; + | ^ the trait `Clone` is not implemented for `NoClone` + | +note: required by a bound in `S` + --> $DIR/struct-path-alias-bounds.rs:3:13 + | +LL | struct S { a: T } + | ^^^^^ required by this bound in `S` +help: consider annotating `NoClone` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/structs/struct-path-associated-type.rs b/src/test/ui/structs/struct-path-associated-type.rs new file mode 100644 index 000000000..f88572f84 --- /dev/null +++ b/src/test/ui/structs/struct-path-associated-type.rs @@ -0,0 +1,37 @@ +struct S; + +trait Tr { + type A; +} + +impl Tr for S { + type A = S; +} + +fn f() { + let s = T::A {}; + //~^ ERROR expected struct, variant or union type, found associated type + let z = T::A:: {}; + //~^ ERROR expected struct, variant or union type, found associated type + //~| ERROR type arguments are not allowed on this type + match S { + T::A {} => {} + //~^ ERROR expected struct, variant or union type, found associated type + } +} + +fn g>() { + let s = T::A {}; // OK + let z = T::A:: {}; //~ ERROR type arguments are not allowed on this type + match S { + T::A {} => {} // OK + } +} + +fn main() { + let s = S::A {}; //~ ERROR ambiguous associated type + let z = S::A:: {}; //~ ERROR ambiguous associated type + match S { + S::A {} => {} //~ ERROR ambiguous associated type + } +} diff --git a/src/test/ui/structs/struct-path-associated-type.stderr b/src/test/ui/structs/struct-path-associated-type.stderr new file mode 100644 index 000000000..bdce0e1b3 --- /dev/null +++ b/src/test/ui/structs/struct-path-associated-type.stderr @@ -0,0 +1,56 @@ +error[E0071]: expected struct, variant or union type, found associated type + --> $DIR/struct-path-associated-type.rs:12:13 + | +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 + | +LL | let z = T::A:: {}; + | - ^^ type argument not allowed + | | + | not allowed on this type + +error[E0071]: expected struct, variant or union type, found associated type + --> $DIR/struct-path-associated-type.rs:14:13 + | +LL | let z = T::A:: {}; + | ^^^^ not a struct + +error[E0071]: expected struct, variant or union type, found associated type + --> $DIR/struct-path-associated-type.rs:18:9 + | +LL | T::A {} => {} + | ^^^^ not a struct + +error[E0109]: type arguments are not allowed on this type + --> $DIR/struct-path-associated-type.rs:25:20 + | +LL | let z = T::A:: {}; + | - ^^ type argument not allowed + | | + | not allowed on this type + +error[E0223]: ambiguous associated type + --> $DIR/struct-path-associated-type.rs:32:13 + | +LL | let s = S::A {}; + | ^^^^ help: use fully-qualified syntax: `::A` + +error[E0223]: ambiguous associated type + --> $DIR/struct-path-associated-type.rs:33:13 + | +LL | let z = S::A:: {}; + | ^^^^ help: use fully-qualified syntax: `::A` + +error[E0223]: ambiguous associated type + --> $DIR/struct-path-associated-type.rs:35:9 + | +LL | S::A {} => {} + | ^^^^ help: use fully-qualified syntax: `::A` + +error: aborting due to 8 previous errors + +Some errors have detailed explanations: E0071, E0109, E0223. +For more information about an error, try `rustc --explain E0071`. diff --git a/src/test/ui/structs/struct-path-self-type-mismatch.rs b/src/test/ui/structs/struct-path-self-type-mismatch.rs new file mode 100644 index 000000000..c0c557eca --- /dev/null +++ b/src/test/ui/structs/struct-path-self-type-mismatch.rs @@ -0,0 +1,21 @@ +struct Foo { inner: A } + +trait Bar { fn bar(); } + +impl Bar for Foo { + fn bar() { + Self { inner: 1.5f32 }; //~ ERROR mismatched types + } +} + +impl Foo { + fn new(u: U) -> Foo { + Self { + //~^ ERROR mismatched types + inner: u + //~^ ERROR mismatched types + } + } +} + +fn main() {} diff --git a/src/test/ui/structs/struct-path-self-type-mismatch.stderr b/src/test/ui/structs/struct-path-self-type-mismatch.stderr new file mode 100644 index 000000000..b55a2cbf7 --- /dev/null +++ b/src/test/ui/structs/struct-path-self-type-mismatch.stderr @@ -0,0 +1,46 @@ +error[E0308]: mismatched types + --> $DIR/struct-path-self-type-mismatch.rs:7:23 + | +LL | Self { inner: 1.5f32 }; + | ^^^^^^ expected `i32`, found `f32` + +error[E0308]: mismatched types + --> $DIR/struct-path-self-type-mismatch.rs:15:20 + | +LL | impl Foo { + | - expected type parameter +LL | fn new(u: U) -> Foo { + | - found type parameter +... +LL | inner: u + | ^ expected type parameter `T`, found type parameter `U` + | + = note: expected type parameter `T` + found type parameter `U` + = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound + = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters + +error[E0308]: mismatched types + --> $DIR/struct-path-self-type-mismatch.rs:13:9 + | +LL | impl Foo { + | - found type parameter +LL | fn new(u: U) -> Foo { + | - ------ expected `Foo` because of return type + | | + | expected type parameter +LL | / Self { +LL | | +LL | | inner: u +LL | | +LL | | } + | |_________^ expected type parameter `U`, found type parameter `T` + | + = note: expected struct `Foo` + found struct `Foo` + = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound + = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/structs/struct-path-self.rs b/src/test/ui/structs/struct-path-self.rs new file mode 100644 index 000000000..6e529c7ed --- /dev/null +++ b/src/test/ui/structs/struct-path-self.rs @@ -0,0 +1,37 @@ +struct S; + +trait Tr { + fn f() { + let s = Self {}; + //~^ ERROR expected struct, variant or union type, found type parameter + let z = Self:: {}; + //~^ ERROR expected struct, variant or union type, found type parameter + //~| ERROR type arguments are not allowed on self type + match s { + Self { .. } => {} + //~^ ERROR expected struct, variant or union type, found type parameter + } + } +} + +impl Tr for S { + fn f() { + let s = Self {}; // OK + let z = Self:: {}; //~ ERROR type arguments are not allowed on self type + match s { + Self { .. } => {} // OK + } + } +} + +impl S { + fn g() { + let s = Self {}; // OK + let z = Self:: {}; //~ ERROR type arguments are not allowed on self type + match s { + Self { .. } => {} // OK + } + } +} + +fn main() {} diff --git a/src/test/ui/structs/struct-path-self.stderr b/src/test/ui/structs/struct-path-self.stderr new file mode 100644 index 000000000..c2a8623f9 --- /dev/null +++ b/src/test/ui/structs/struct-path-self.stderr @@ -0,0 +1,80 @@ +error[E0071]: expected struct, variant or union type, found type parameter `Self` + --> $DIR/struct-path-self.rs:5:17 + | +LL | let s = Self {}; + | ^^^^ not a struct + +error[E0109]: type arguments are not allowed on self type + --> $DIR/struct-path-self.rs:7:24 + | +LL | let z = Self:: {}; + | ---- ^^ type argument not allowed + | | + | not allowed on self type + | +help: the `Self` type doesn't accept type parameters + | +LL - let z = Self:: {}; +LL + let z = Self {}; + | + +error[E0071]: expected struct, variant or union type, found type parameter `Self` + --> $DIR/struct-path-self.rs:7:17 + | +LL | let z = Self:: {}; + | ^^^^^^^^^^ not a struct + +error[E0071]: expected struct, variant or union type, found type parameter `Self` + --> $DIR/struct-path-self.rs:11:13 + | +LL | Self { .. } => {} + | ^^^^ not a struct + +error[E0109]: type arguments are not allowed on self type + --> $DIR/struct-path-self.rs:20:24 + | +LL | let z = Self:: {}; + | ---- ^^ type argument not allowed + | | + | not allowed on self type + | +note: `Self` is of type `S` + --> $DIR/struct-path-self.rs:1:8 + | +LL | struct S; + | ^ `Self` corresponds to this type, which doesn't have generic parameters +... +LL | impl Tr for S { + | ------------- `Self` is on type `S` in this `impl` +help: the `Self` type doesn't accept type parameters + | +LL - let z = Self:: {}; +LL + let z = Self {}; + | + +error[E0109]: type arguments are not allowed on self type + --> $DIR/struct-path-self.rs:30:24 + | +LL | let z = Self:: {}; + | ---- ^^ type argument not allowed + | | + | not allowed on self type + | +note: `Self` is of type `S` + --> $DIR/struct-path-self.rs:1:8 + | +LL | struct S; + | ^ `Self` corresponds to this type, which doesn't have generic parameters +... +LL | impl S { + | ------ `Self` is on type `S` in this `impl` +help: the `Self` type doesn't accept type parameters + | +LL - let z = Self:: {}; +LL + let z = Self {}; + | + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0071, E0109. +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 new file mode 100644 index 000000000..48144cd1c --- /dev/null +++ b/src/test/ui/structs/struct-record-suggestion.fixed @@ -0,0 +1,16 @@ +// run-rustfix +#[derive(Debug, Default, Eq, PartialEq)] +struct A { + b: u32, + c: u64, + d: usize, +} + +fn main() { + 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() }; + assert_eq!(q, r); +} diff --git a/src/test/ui/structs/struct-record-suggestion.rs b/src/test/ui/structs/struct-record-suggestion.rs new file mode 100644 index 000000000..6d169d5c6 --- /dev/null +++ b/src/test/ui/structs/struct-record-suggestion.rs @@ -0,0 +1,16 @@ +// run-rustfix +#[derive(Debug, Default, Eq, PartialEq)] +struct A { + b: u32, + c: u64, + d: usize, +} + +fn main() { + 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() }; + assert_eq!(q, r); +} diff --git a/src/test/ui/structs/struct-record-suggestion.stderr b/src/test/ui/structs/struct-record-suggestion.stderr new file mode 100644 index 000000000..e5bd03117 --- /dev/null +++ b/src/test/ui/structs/struct-record-suggestion.stderr @@ -0,0 +1,24 @@ +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` + | + = note: expected type `u64` + found struct `std::ops::Range<{integer}>` + +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() }; + | ^ 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() }; + | + + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0063, E0308. +For more information about an error, try `rustc --explain E0063`. diff --git a/src/test/ui/structs/struct-tuple-field-names.rs b/src/test/ui/structs/struct-tuple-field-names.rs new file mode 100644 index 000000000..7bd54af1d --- /dev/null +++ b/src/test/ui/structs/struct-tuple-field-names.rs @@ -0,0 +1,15 @@ +struct S(i32, f32); +enum E { + S(i32, f32), +} +fn main() { + let x = E::S(1, 2.2); + match x { + E::S { 0, 1 } => {} + //~^ ERROR tuple variant `E::S` written as struct variant [E0769] + } + let y = S(1, 2.2); + match y { + S { } => {} //~ ERROR: tuple variant `S` written as struct variant [E0769] + } +} diff --git a/src/test/ui/structs/struct-tuple-field-names.stderr b/src/test/ui/structs/struct-tuple-field-names.stderr new file mode 100644 index 000000000..5494c29a6 --- /dev/null +++ b/src/test/ui/structs/struct-tuple-field-names.stderr @@ -0,0 +1,25 @@ +error[E0769]: tuple variant `E::S` written as struct variant + --> $DIR/struct-tuple-field-names.rs:8:9 + | +LL | E::S { 0, 1 } => {} + | ^^^^^^^^^^^^^ + | +help: use the tuple variant pattern syntax instead + | +LL | E::S(_, _) => {} + | ~~~~~~ + +error[E0769]: tuple variant `S` written as struct variant + --> $DIR/struct-tuple-field-names.rs:13:9 + | +LL | S { } => {} + | ^^^^^ + | +help: use the tuple variant pattern syntax instead + | +LL | S(_, _) => {} + | ~~~~~~ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0769`. diff --git a/src/test/ui/structs/struct-variant-privacy-xc.rs b/src/test/ui/structs/struct-variant-privacy-xc.rs new file mode 100644 index 000000000..763ab9527 --- /dev/null +++ b/src/test/ui/structs/struct-variant-privacy-xc.rs @@ -0,0 +1,11 @@ +// aux-build:struct_variant_privacy.rs +extern crate struct_variant_privacy; + +fn f(b: struct_variant_privacy::Bar) { + //~^ ERROR enum `Bar` is private + match b { + struct_variant_privacy::Bar::Baz { a: _a } => {} //~ ERROR enum `Bar` is private + } +} + +fn main() {} diff --git a/src/test/ui/structs/struct-variant-privacy-xc.stderr b/src/test/ui/structs/struct-variant-privacy-xc.stderr new file mode 100644 index 000000000..1c1caaef8 --- /dev/null +++ b/src/test/ui/structs/struct-variant-privacy-xc.stderr @@ -0,0 +1,27 @@ +error[E0603]: enum `Bar` is private + --> $DIR/struct-variant-privacy-xc.rs:4:33 + | +LL | fn f(b: struct_variant_privacy::Bar) { + | ^^^ private enum + | +note: the enum `Bar` is defined here + --> $DIR/auxiliary/struct_variant_privacy.rs:1:1 + | +LL | enum Bar { + | ^^^^^^^^ + +error[E0603]: enum `Bar` is private + --> $DIR/struct-variant-privacy-xc.rs:7:33 + | +LL | struct_variant_privacy::Bar::Baz { a: _a } => {} + | ^^^ private enum + | +note: the enum `Bar` is defined here + --> $DIR/auxiliary/struct_variant_privacy.rs:1:1 + | +LL | enum Bar { + | ^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0603`. diff --git a/src/test/ui/structs/struct-variant-privacy.rs b/src/test/ui/structs/struct-variant-privacy.rs new file mode 100644 index 000000000..fcdf9a22b --- /dev/null +++ b/src/test/ui/structs/struct-variant-privacy.rs @@ -0,0 +1,14 @@ +mod foo { + enum Bar { + Baz { a: isize }, + } +} + +fn f(b: foo::Bar) { + //~^ ERROR enum `Bar` is private + match b { + foo::Bar::Baz { a: _a } => {} //~ ERROR enum `Bar` is private + } +} + +fn main() {} diff --git a/src/test/ui/structs/struct-variant-privacy.stderr b/src/test/ui/structs/struct-variant-privacy.stderr new file mode 100644 index 000000000..eafd26c71 --- /dev/null +++ b/src/test/ui/structs/struct-variant-privacy.stderr @@ -0,0 +1,27 @@ +error[E0603]: enum `Bar` is private + --> $DIR/struct-variant-privacy.rs:7:14 + | +LL | fn f(b: foo::Bar) { + | ^^^ private enum + | +note: the enum `Bar` is defined here + --> $DIR/struct-variant-privacy.rs:2:5 + | +LL | enum Bar { + | ^^^^^^^^ + +error[E0603]: enum `Bar` is private + --> $DIR/struct-variant-privacy.rs:10:14 + | +LL | foo::Bar::Baz { a: _a } => {} + | ^^^ private enum + | +note: the enum `Bar` is defined here + --> $DIR/struct-variant-privacy.rs:2:5 + | +LL | enum Bar { + | ^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0603`. diff --git a/src/test/ui/structs/structure-constructor-type-mismatch.rs b/src/test/ui/structs/structure-constructor-type-mismatch.rs new file mode 100644 index 000000000..a03ef590c --- /dev/null +++ b/src/test/ui/structs/structure-constructor-type-mismatch.rs @@ -0,0 +1,73 @@ +struct Point { + x: T, + y: T, +} + +type PointF = Point; + +struct Pair { + x: T, + y: U, +} + +type PairF = Pair; + +fn main() { + let pt = PointF { + x: 1, + //~^ ERROR mismatched types + //~| expected `f32`, found integer + y: 2, + //~^ ERROR mismatched types + //~| expected `f32`, found integer + }; + + let pt2 = Point:: { + x: 3, + //~^ ERROR mismatched types + //~| expected `f32`, found integer + y: 4, + //~^ ERROR mismatched types + //~| expected `f32`, found integer + }; + + let pair = PairF { + x: 5, + //~^ ERROR mismatched types + //~| expected `f32`, found integer + y: 6, + }; + + let pair2 = PairF:: { + x: 7, + //~^ ERROR mismatched types + //~| expected `f32`, found integer + y: 8, + }; + + let pt3 = PointF:: { //~ ERROR this type alias takes 0 generic arguments but 1 generic argument + x: 9, //~ ERROR mismatched types + y: 10, //~ ERROR mismatched types + }; + + match (Point { x: 1, y: 2 }) { + PointF:: { .. } => {} //~ ERROR this type alias takes 0 generic arguments but 1 generic argument + //~^ ERROR mismatched types + } + + match (Point { x: 1, y: 2 }) { + PointF { .. } => {} //~ ERROR mismatched types + } + + match (Point { x: 1.0, y: 2.0 }) { + PointF { .. } => {} // ok + } + + match (Pair { x: 1, y: 2 }) { + PairF:: { .. } => {} //~ ERROR mismatched types + } + + match (Pair { x: 1.0, y: 2 }) { + PairF:: { .. } => {} // ok + } +} diff --git a/src/test/ui/structs/structure-constructor-type-mismatch.stderr b/src/test/ui/structs/structure-constructor-type-mismatch.stderr new file mode 100644 index 000000000..3d64fc601 --- /dev/null +++ b/src/test/ui/structs/structure-constructor-type-mismatch.stderr @@ -0,0 +1,137 @@ +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:17:12 + | +LL | x: 1, + | ^ + | | + | expected `f32`, found integer + | help: use a float literal: `1.0` + +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:20:12 + | +LL | y: 2, + | ^ + | | + | expected `f32`, found integer + | help: use a float literal: `2.0` + +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:26:12 + | +LL | x: 3, + | ^ + | | + | expected `f32`, found integer + | help: use a float literal: `3.0` + +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:29:12 + | +LL | y: 4, + | ^ + | | + | expected `f32`, found integer + | help: use a float literal: `4.0` + +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:35:12 + | +LL | x: 5, + | ^ + | | + | expected `f32`, found integer + | help: use a float literal: `5.0` + +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:42:12 + | +LL | x: 7, + | ^ + | | + | expected `f32`, found integer + | help: use a float literal: `7.0` + +error[E0107]: this type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/structure-constructor-type-mismatch.rs:48:15 + | +LL | let pt3 = PointF:: { + | ^^^^^^------- help: remove these generics + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/structure-constructor-type-mismatch.rs:6:6 + | +LL | type PointF = Point; + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:49:12 + | +LL | x: 9, + | ^ + | | + | expected `f32`, found integer + | help: use a float literal: `9.0` + +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:50:12 + | +LL | y: 10, + | ^^ + | | + | expected `f32`, found integer + | help: use a float literal: `10.0` + +error[E0107]: this type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/structure-constructor-type-mismatch.rs:54:9 + | +LL | PointF:: { .. } => {} + | ^^^^^^------- help: remove these generics + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/structure-constructor-type-mismatch.rs:6:6 + | +LL | type PointF = Point; + | ^^^^^^ + +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:54:9 + | +LL | match (Point { x: 1, y: 2 }) { + | ---------------------- this expression has type `Point<{integer}>` +LL | PointF:: { .. } => {} + | ^^^^^^^^^^^^^^^^^^^^ expected integer, found `f32` + | + = note: expected struct `Point<{integer}>` + found struct `Point` + +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:59:9 + | +LL | match (Point { x: 1, y: 2 }) { + | ---------------------- this expression has type `Point<{integer}>` +LL | PointF { .. } => {} + | ^^^^^^^^^^^^^ expected integer, found `f32` + | + = note: expected struct `Point<{integer}>` + found struct `Point` + +error[E0308]: mismatched types + --> $DIR/structure-constructor-type-mismatch.rs:67:9 + | +LL | match (Pair { x: 1, y: 2 }) { + | --------------------- this expression has type `Pair<{integer}, {integer}>` +LL | PairF:: { .. } => {} + | ^^^^^^^^^^^^^^^^^^^ expected integer, found `f32` + | + = note: expected struct `Pair<{integer}, {integer}>` + found struct `Pair` + +error: aborting due to 13 previous errors + +Some errors have detailed explanations: E0107, E0308. +For more information about an error, try `rustc --explain E0107`. diff --git a/src/test/ui/structs/suggest-private-fields.rs b/src/test/ui/structs/suggest-private-fields.rs new file mode 100644 index 000000000..8267a82fe --- /dev/null +++ b/src/test/ui/structs/suggest-private-fields.rs @@ -0,0 +1,27 @@ +// aux-build:struct_field_privacy.rs + +extern crate struct_field_privacy as xc; + +use xc::B; + +struct A { + pub a: u32, + b: u32, +} + +fn main () { + // external crate struct + let k = B { + aa: 20, + //~^ ERROR struct `B` has no field named `aa` + bb: 20, + //~^ ERROR struct `B` has no field named `bb` + }; + // local crate struct + let l = A { + aa: 20, + //~^ ERROR struct `A` has no field named `aa` + bb: 20, + //~^ ERROR struct `A` has no field named `bb` + }; +} diff --git a/src/test/ui/structs/suggest-private-fields.stderr b/src/test/ui/structs/suggest-private-fields.stderr new file mode 100644 index 000000000..d628bd162 --- /dev/null +++ b/src/test/ui/structs/suggest-private-fields.stderr @@ -0,0 +1,29 @@ +error[E0560]: struct `B` has no field named `aa` + --> $DIR/suggest-private-fields.rs:15:9 + | +LL | aa: 20, + | ^^ help: a field with a similar name exists: `a` + +error[E0560]: struct `B` has no field named `bb` + --> $DIR/suggest-private-fields.rs:17:9 + | +LL | bb: 20, + | ^^ `B` does not have this field + | + = note: available fields are: `a` + +error[E0560]: struct `A` has no field named `aa` + --> $DIR/suggest-private-fields.rs:22:9 + | +LL | aa: 20, + | ^^ help: a field with a similar name exists: `a` + +error[E0560]: struct `A` has no field named `bb` + --> $DIR/suggest-private-fields.rs:24:9 + | +LL | bb: 20, + | ^^ help: a field with a similar name exists: `b` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0560`. diff --git a/src/test/ui/structs/suggest-replacing-field-when-specifying-same-type.rs b/src/test/ui/structs/suggest-replacing-field-when-specifying-same-type.rs new file mode 100644 index 000000000..dd2fe7973 --- /dev/null +++ b/src/test/ui/structs/suggest-replacing-field-when-specifying-same-type.rs @@ -0,0 +1,28 @@ +enum Foo { + Bar { a: u8, b: i8, c: u8 }, + Baz { a: f32 }, + None, +} + +fn main() { + let foo = Foo::None; + match foo { + Foo::Bar { a, aa: 1, c } => (), + //~^ ERROR variant `Foo::Bar` does not have a field named `aa` [E0026] + //~| ERROR pattern does not mention field `b` [E0027] + Foo::Baz { bb: 1.0 } => (), + //~^ ERROR variant `Foo::Baz` does not have a field named `bb` [E0026] + //~| ERROR pattern does not mention field `a` [E0027] + _ => (), + } + + match foo { + Foo::Bar { a, aa: "", c } => (), + //~^ ERROR variant `Foo::Bar` does not have a field named `aa` [E0026] + //~| ERROR pattern does not mention field `b` [E0027] + Foo::Baz { bb: "" } => (), + //~^ ERROR variant `Foo::Baz` does not have a field named `bb` [E0026] + //~| pattern does not mention field `a` [E0027] + _ => (), + } +} diff --git a/src/test/ui/structs/suggest-replacing-field-when-specifying-same-type.stderr b/src/test/ui/structs/suggest-replacing-field-when-specifying-same-type.stderr new file mode 100644 index 000000000..e8503f540 --- /dev/null +++ b/src/test/ui/structs/suggest-replacing-field-when-specifying-same-type.stderr @@ -0,0 +1,94 @@ +error[E0026]: variant `Foo::Bar` does not have a field named `aa` + --> $DIR/suggest-replacing-field-when-specifying-same-type.rs:10:23 + | +LL | Foo::Bar { a, aa: 1, c } => (), + | ^^ + | | + | variant `Foo::Bar` does not have this field + | help: `Foo::Bar` has a field named `b` + +error[E0027]: pattern does not mention field `b` + --> $DIR/suggest-replacing-field-when-specifying-same-type.rs:10:9 + | +LL | Foo::Bar { a, aa: 1, c } => (), + | ^^^^^^^^^^^^^^^^^^^^^^^^ missing field `b` + | +help: include the missing field in the pattern + | +LL | Foo::Bar { a, aa: 1, c, b } => (), + | ~~~~~ +help: if you don't care about this missing field, you can explicitly ignore it + | +LL | Foo::Bar { a, aa: 1, c, .. } => (), + | ~~~~~~ + +error[E0026]: variant `Foo::Baz` does not have a field named `bb` + --> $DIR/suggest-replacing-field-when-specifying-same-type.rs:13:20 + | +LL | Foo::Baz { bb: 1.0 } => (), + | ^^ + | | + | variant `Foo::Baz` does not have this field + | help: `Foo::Baz` has a field named `a` + +error[E0027]: pattern does not mention field `a` + --> $DIR/suggest-replacing-field-when-specifying-same-type.rs:13:9 + | +LL | Foo::Baz { bb: 1.0 } => (), + | ^^^^^^^^^^^^^^^^^^^^ missing field `a` + | +help: include the missing field in the pattern + | +LL | Foo::Baz { bb: 1.0, a } => (), + | ~~~~~ +help: if you don't care about this missing field, you can explicitly ignore it + | +LL | Foo::Baz { bb: 1.0, .. } => (), + | ~~~~~~ + +error[E0026]: variant `Foo::Bar` does not have a field named `aa` + --> $DIR/suggest-replacing-field-when-specifying-same-type.rs:20:23 + | +LL | Foo::Bar { a, aa: "", c } => (), + | ^^ variant `Foo::Bar` does not have this field + +error[E0027]: pattern does not mention field `b` + --> $DIR/suggest-replacing-field-when-specifying-same-type.rs:20:9 + | +LL | Foo::Bar { a, aa: "", c } => (), + | ^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `b` + | +help: include the missing field in the pattern + | +LL | Foo::Bar { a, aa: "", c, b } => (), + | ~~~~~ +help: if you don't care about this missing field, you can explicitly ignore it + | +LL | Foo::Bar { a, aa: "", c, .. } => (), + | ~~~~~~ + +error[E0026]: variant `Foo::Baz` does not have a field named `bb` + --> $DIR/suggest-replacing-field-when-specifying-same-type.rs:23:20 + | +LL | Foo::Baz { bb: "" } => (), + | ^^ variant `Foo::Baz` does not have this field + +error[E0027]: pattern does not mention field `a` + --> $DIR/suggest-replacing-field-when-specifying-same-type.rs:23:9 + | +LL | Foo::Baz { bb: "" } => (), + | ^^^^^^^^^^^^^^^^^^^ missing field `a` + | +help: include the missing field in the pattern + | +LL | Foo::Baz { bb: "", a } => (), + | ~~~~~ +help: if you don't care about this missing field, you can explicitly ignore it + | +LL | Foo::Baz { bb: "", .. } => (), + | ~~~~~~ + +error: aborting due to 8 previous errors + +Some errors have detailed explanations: E0026, E0027. +For more information about an error, try `rustc --explain E0026`. -- cgit v1.2.3