diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:42 +0000 |
commit | cec1877e180393eba0f6ddb0cf97bf3a791631c7 (patch) | |
tree | 47b4dac2a9dd9a40c30c251b4d4a72d7ccf77e9f /tests/ui/parser/assoc | |
parent | Adding debian version 1.74.1+dfsg1-1. (diff) | |
download | rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.tar.xz rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/parser/assoc')
15 files changed, 532 insertions, 0 deletions
diff --git a/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.rs b/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.rs new file mode 100644 index 000000000..d37ce06c5 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.rs @@ -0,0 +1,17 @@ +// Semantically, an associated constant cannot use `_` as a name. + +fn main() {} + +const _: () = { + pub trait A { + const _: () = (); //~ ERROR `const` items in this context need a name + } + impl A for () { + const _: () = (); //~ ERROR `const` items in this context need a name + //~^ ERROR const `_` is not a member of trait `A` + } + struct B; + impl B { + const _: () = (); //~ ERROR `const` items in this context need a name + } +}; diff --git a/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.stderr b/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.stderr new file mode 100644 index 000000000..538bf0ec1 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-const-underscore-semantic-fail.stderr @@ -0,0 +1,27 @@ +error: `const` items in this context need a name + --> $DIR/assoc-const-underscore-semantic-fail.rs:7:15 + | +LL | const _: () = (); + | ^ `_` is not a valid name for this `const` item + +error: `const` items in this context need a name + --> $DIR/assoc-const-underscore-semantic-fail.rs:10:15 + | +LL | const _: () = (); + | ^ `_` is not a valid name for this `const` item + +error: `const` items in this context need a name + --> $DIR/assoc-const-underscore-semantic-fail.rs:15:15 + | +LL | const _: () = (); + | ^ `_` is not a valid name for this `const` item + +error[E0438]: const `_` is not a member of trait `A` + --> $DIR/assoc-const-underscore-semantic-fail.rs:10:9 + | +LL | const _: () = (); + | ^^^^^^^^^^^^^^^^^ not a member of trait `A` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0438`. diff --git a/tests/ui/parser/assoc/assoc-const-underscore-syntactic-pass.rs b/tests/ui/parser/assoc/assoc-const-underscore-syntactic-pass.rs new file mode 100644 index 000000000..60da408c8 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-const-underscore-syntactic-pass.rs @@ -0,0 +1,18 @@ +// All constant items (associated or otherwise) may syntactically use `_` as a name. + +// check-pass + +fn main() {} + +#[cfg(FALSE)] +const _: () = { + pub trait A { + const _: () = (); + } + impl A for () { + const _: () = (); + } + impl dyn A { + const _: () = (); + } +}; diff --git a/tests/ui/parser/assoc/assoc-oddities-1.rs b/tests/ui/parser/assoc/assoc-oddities-1.rs new file mode 100644 index 000000000..5914805e5 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-oddities-1.rs @@ -0,0 +1,11 @@ +// compile-flags: -Z parse-only + +fn main() { + // following lines below parse and must not fail + x = if c { a } else { b }(); + x = if true { 1 } else { 0 } as *mut _; + // however this does not parse and probably should fail to retain compat? + // N.B., `..` here is arbitrary, failure happens/should happen ∀ops that aren’t `=` + // see assoc-oddities-2 and assoc-oddities-3 + ..if c { a } else { b }[n]; //~ ERROR expected one of +} diff --git a/tests/ui/parser/assoc/assoc-oddities-1.stderr b/tests/ui/parser/assoc/assoc-oddities-1.stderr new file mode 100644 index 000000000..acf71b489 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-oddities-1.stderr @@ -0,0 +1,8 @@ +error: expected one of `.`, `;`, `?`, or `}`, found `[` + --> $DIR/assoc-oddities-1.rs:10:28 + | +LL | ..if c { a } else { b }[n]; + | ^ expected one of `.`, `;`, `?`, or `}` + +error: aborting due to previous error + diff --git a/tests/ui/parser/assoc/assoc-oddities-2.rs b/tests/ui/parser/assoc/assoc-oddities-2.rs new file mode 100644 index 000000000..3d35aad74 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-oddities-2.rs @@ -0,0 +1,6 @@ +// compile-flags: -Z parse-only + +fn main() { + // see assoc-oddities-1 for explanation + x..if c { a } else { b }[n]; //~ ERROR expected one of +} diff --git a/tests/ui/parser/assoc/assoc-oddities-2.stderr b/tests/ui/parser/assoc/assoc-oddities-2.stderr new file mode 100644 index 000000000..d3b90c34c --- /dev/null +++ b/tests/ui/parser/assoc/assoc-oddities-2.stderr @@ -0,0 +1,8 @@ +error: expected one of `.`, `;`, `?`, or `}`, found `[` + --> $DIR/assoc-oddities-2.rs:5:29 + | +LL | x..if c { a } else { b }[n]; + | ^ expected one of `.`, `;`, `?`, or `}` + +error: aborting due to previous error + diff --git a/tests/ui/parser/assoc/assoc-static-semantic-fail.rs b/tests/ui/parser/assoc/assoc-static-semantic-fail.rs new file mode 100644 index 000000000..403160f12 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-static-semantic-fail.rs @@ -0,0 +1,52 @@ +// Semantically, we do not allow e.g., `static X: u8 = 0;` as an associated item. + +#![feature(specialization)] +//~^ WARN the feature `specialization` is incomplete + +fn main() {} + +struct S; +impl S { + static IA: u8 = 0; + //~^ ERROR associated `static` items are not allowed + static IB: u8; + //~^ ERROR associated `static` items are not allowed + //~| ERROR associated constant in `impl` without body + default static IC: u8 = 0; + //~^ ERROR associated `static` items are not allowed + //~| ERROR a static item cannot be `default` + pub(crate) default static ID: u8; + //~^ ERROR associated `static` items are not allowed + //~| ERROR associated constant in `impl` without body + //~| ERROR a static item cannot be `default` +} + +trait T { + static TA: u8 = 0; + //~^ ERROR associated `static` items are not allowed + static TB: u8; + //~^ ERROR associated `static` items are not allowed + default static TC: u8 = 0; + //~^ ERROR associated `static` items are not allowed + //~| ERROR a static item cannot be `default` + pub(crate) default static TD: u8; + //~^ ERROR associated `static` items are not allowed + //~| ERROR visibility qualifiers are not permitted here + //~| ERROR a static item cannot be `default` +} + +impl T for S { + static TA: u8 = 0; + //~^ ERROR associated `static` items are not allowed + static TB: u8; + //~^ ERROR associated `static` items are not allowed + //~| ERROR associated constant in `impl` without body + default static TC: u8 = 0; + //~^ ERROR associated `static` items are not allowed + //~| ERROR a static item cannot be `default` + pub default static TD: u8; + //~^ ERROR associated `static` items are not allowed + //~| ERROR associated constant in `impl` without body + //~| ERROR visibility qualifiers are not permitted here + //~| ERROR a static item cannot be `default` +} diff --git a/tests/ui/parser/assoc/assoc-static-semantic-fail.stderr b/tests/ui/parser/assoc/assoc-static-semantic-fail.stderr new file mode 100644 index 000000000..8178bd223 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-static-semantic-fail.stderr @@ -0,0 +1,181 @@ +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:10:5 + | +LL | static IA: u8 = 0; + | ^^^^^^^^^^^^^^^^^^ + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:12:5 + | +LL | static IB: u8; + | ^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-semantic-fail.rs:15:5 + | +LL | default static IC: u8 = 0; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:15:5 + | +LL | default static IC: u8 = 0; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-semantic-fail.rs:18:16 + | +LL | pub(crate) default static ID: u8; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:18:5 + | +LL | pub(crate) default static ID: u8; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:25:5 + | +LL | static TA: u8 = 0; + | ^^^^^^^^^^^^^^^^^^ + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:27:5 + | +LL | static TB: u8; + | ^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-semantic-fail.rs:29:5 + | +LL | default static TC: u8 = 0; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:29:5 + | +LL | default static TC: u8 = 0; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-semantic-fail.rs:32:16 + | +LL | pub(crate) default static TD: u8; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:32:5 + | +LL | pub(crate) default static TD: u8; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:39:5 + | +LL | static TA: u8 = 0; + | ^^^^^^^^^^^^^^^^^^ + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:41:5 + | +LL | static TB: u8; + | ^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-semantic-fail.rs:44:5 + | +LL | default static TC: u8 = 0; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:44:5 + | +LL | default static TC: u8 = 0; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-semantic-fail.rs:47:9 + | +LL | pub default static TD: u8; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-semantic-fail.rs:47:5 + | +LL | pub default static TD: u8; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: associated constant in `impl` without body + --> $DIR/assoc-static-semantic-fail.rs:12:5 + | +LL | static IB: u8; + | ^^^^^^^^^^^^^- + | | + | help: provide a definition for the constant: `= <expr>;` + +error: associated constant in `impl` without body + --> $DIR/assoc-static-semantic-fail.rs:18:5 + | +LL | pub(crate) default static ID: u8; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- + | | + | help: provide a definition for the constant: `= <expr>;` + +error[E0449]: visibility qualifiers are not permitted here + --> $DIR/assoc-static-semantic-fail.rs:32:5 + | +LL | pub(crate) default static TD: u8; + | ^^^^^^^^^^ + | + = note: trait items always share the visibility of their trait + +error: associated constant in `impl` without body + --> $DIR/assoc-static-semantic-fail.rs:41:5 + | +LL | static TB: u8; + | ^^^^^^^^^^^^^- + | | + | help: provide a definition for the constant: `= <expr>;` + +error: associated constant in `impl` without body + --> $DIR/assoc-static-semantic-fail.rs:47:5 + | +LL | pub default static TD: u8; + | ^^^^^^^^^^^^^^^^^^^^^^^^^- + | | + | help: provide a definition for the constant: `= <expr>;` + +error[E0449]: visibility qualifiers are not permitted here + --> $DIR/assoc-static-semantic-fail.rs:47:5 + | +LL | pub default static TD: u8; + | ^^^ + | + = note: trait items always share the visibility of their trait + +warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/assoc-static-semantic-fail.rs:3:12 + | +LL | #![feature(specialization)] + | ^^^^^^^^^^^^^^ + | + = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information + = help: consider using `min_specialization` instead, which is more stable and complete + = note: `#[warn(incomplete_features)]` on by default + +error: aborting due to 24 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0449`. diff --git a/tests/ui/parser/assoc/assoc-static-syntactic-fail.rs b/tests/ui/parser/assoc/assoc-static-syntactic-fail.rs new file mode 100644 index 000000000..492f2ea16 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-static-syntactic-fail.rs @@ -0,0 +1,33 @@ +// Syntactically, we do allow e.g., `static X: u8 = 0;` as an associated item. + +fn main() {} + +#[cfg(FALSE)] +impl S { + static IA: u8 = 0; //~ ERROR associated `static` items are not allowed + static IB: u8; //~ ERROR associated `static` items are not allowed + default static IC: u8 = 0; //~ ERROR associated `static` items are not allowed + //~^ ERROR a static item cannot be `default` + pub(crate) default static ID: u8; //~ ERROR associated `static` items are not allowed + //~^ ERROR a static item cannot be `default` +} + +#[cfg(FALSE)] +trait T { + static TA: u8 = 0; //~ ERROR associated `static` items are not allowed + static TB: u8; //~ ERROR associated `static` items are not allowed + default static TC: u8 = 0; //~ ERROR associated `static` items are not allowed + //~^ ERROR a static item cannot be `default` + pub(crate) default static TD: u8; //~ ERROR associated `static` items are not allowed + //~^ ERROR a static item cannot be `default` +} + +#[cfg(FALSE)] +impl T for S { + static TA: u8 = 0; //~ ERROR associated `static` items are not allowed + static TB: u8; //~ ERROR associated `static` items are not allowed + default static TC: u8 = 0; //~ ERROR associated `static` items are not allowed + //~^ ERROR a static item cannot be `default` + pub default static TD: u8; //~ ERROR associated `static` items are not allowed + //~^ ERROR a static item cannot be `default` +} diff --git a/tests/ui/parser/assoc/assoc-static-syntactic-fail.stderr b/tests/ui/parser/assoc/assoc-static-syntactic-fail.stderr new file mode 100644 index 000000000..e97236145 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-static-syntactic-fail.stderr @@ -0,0 +1,122 @@ +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:7:5 + | +LL | static IA: u8 = 0; + | ^^^^^^^^^^^^^^^^^^ + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:8:5 + | +LL | static IB: u8; + | ^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-syntactic-fail.rs:9:5 + | +LL | default static IC: u8 = 0; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:9:5 + | +LL | default static IC: u8 = 0; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-syntactic-fail.rs:11:16 + | +LL | pub(crate) default static ID: u8; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:11:5 + | +LL | pub(crate) default static ID: u8; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:17:5 + | +LL | static TA: u8 = 0; + | ^^^^^^^^^^^^^^^^^^ + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:18:5 + | +LL | static TB: u8; + | ^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-syntactic-fail.rs:19:5 + | +LL | default static TC: u8 = 0; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:19:5 + | +LL | default static TC: u8 = 0; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-syntactic-fail.rs:21:16 + | +LL | pub(crate) default static TD: u8; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:21:5 + | +LL | pub(crate) default static TD: u8; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:27:5 + | +LL | static TA: u8 = 0; + | ^^^^^^^^^^^^^^^^^^ + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:28:5 + | +LL | static TB: u8; + | ^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-syntactic-fail.rs:29:5 + | +LL | default static TC: u8 = 0; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:29:5 + | +LL | default static TC: u8 = 0; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: a static item cannot be `default` + --> $DIR/assoc-static-syntactic-fail.rs:31:9 + | +LL | pub default static TD: u8; + | ^^^^^^^ `default` because of this + | + = note: only associated `fn`, `const`, and `type` items can be `default` + +error: associated `static` items are not allowed + --> $DIR/assoc-static-syntactic-fail.rs:31:5 + | +LL | pub default static TD: u8; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 18 previous errors + diff --git a/tests/ui/parser/assoc/assoc-type-in-type-arg.rs b/tests/ui/parser/assoc/assoc-type-in-type-arg.rs new file mode 100644 index 000000000..000956ea2 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-type-in-type-arg.rs @@ -0,0 +1,11 @@ +trait Tr { + type TrSubtype; +} + +struct Bar<'a, Item: Tr, <Item as Tr>::TrSubtype: 'a> { + //~^ ERROR bounds on associated types do not belong here + item: Item, + item_sub: &'a <Item as Tr>::TrSubtype, +} + +fn main() {} diff --git a/tests/ui/parser/assoc/assoc-type-in-type-arg.stderr b/tests/ui/parser/assoc/assoc-type-in-type-arg.stderr new file mode 100644 index 000000000..b637702f2 --- /dev/null +++ b/tests/ui/parser/assoc/assoc-type-in-type-arg.stderr @@ -0,0 +1,8 @@ +error: bounds on associated types do not belong here + --> $DIR/assoc-type-in-type-arg.rs:5:26 + | +LL | struct Bar<'a, Item: Tr, <Item as Tr>::TrSubtype: 'a> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ belongs in `where` clause + +error: aborting due to previous error + diff --git a/tests/ui/parser/assoc/associated-types-project-from-hrtb-explicit.rs b/tests/ui/parser/assoc/associated-types-project-from-hrtb-explicit.rs new file mode 100644 index 000000000..b238a9ca2 --- /dev/null +++ b/tests/ui/parser/assoc/associated-types-project-from-hrtb-explicit.rs @@ -0,0 +1,16 @@ +// Test you can't use a higher-ranked trait bound inside of a qualified +// path (just won't parse). + +pub trait Foo<T> { + type A; + + fn get(&self, t: T) -> Self::A; +} + +fn foo2<I>(x: <I as for<'x> Foo<&'x isize>>::A) + //~^ ERROR expected identifier, found keyword `for` + //~| ERROR expected one of `::` or `>` +{ +} + +pub fn main() {} diff --git a/tests/ui/parser/assoc/associated-types-project-from-hrtb-explicit.stderr b/tests/ui/parser/assoc/associated-types-project-from-hrtb-explicit.stderr new file mode 100644 index 000000000..aa0fa0e3c --- /dev/null +++ b/tests/ui/parser/assoc/associated-types-project-from-hrtb-explicit.stderr @@ -0,0 +1,14 @@ +error: expected identifier, found keyword `for` + --> $DIR/associated-types-project-from-hrtb-explicit.rs:10:21 + | +LL | fn foo2<I>(x: <I as for<'x> Foo<&'x isize>>::A) + | ^^^ expected identifier, found keyword + +error: expected one of `::` or `>`, found `Foo` + --> $DIR/associated-types-project-from-hrtb-explicit.rs:10:29 + | +LL | fn foo2<I>(x: <I as for<'x> Foo<&'x isize>>::A) + | ^^^ expected one of `::` or `>` + +error: aborting due to 2 previous errors + |