diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2025-03-24 17:39:38 +0100 |
|---|---|---|
| committer | León Orell Valerian Liehr <me@fmease.dev> | 2025-03-25 15:16:16 +0100 |
| commit | b501e58c2e8aa42c0b6f4f568c90f70e34a11170 (patch) | |
| tree | ae6a854b9cfd3845af3583bd6166d482a6698a9a /tests/ui/parser | |
| parent | 598f8658744db0dc0215545d2193accd3a1ce8c8 (diff) | |
| download | rust-b501e58c2e8aa42c0b6f4f568c90f70e34a11170.tar.gz rust-b501e58c2e8aa42c0b6f4f568c90f70e34a11170.zip | |
Incorporate issue-111692.rs into the larger test file and add more test cases
Note that issue-111692.rs was incorrectly named: It's a regression test for issue [#]112278, not for [#]111692. That's been addressed, too.
Diffstat (limited to 'tests/ui/parser')
| -rw-r--r-- | tests/ui/parser/issues/issue-111692.rs | 34 | ||||
| -rw-r--r-- | tests/ui/parser/issues/issue-111692.stderr | 46 | ||||
| -rw-r--r-- | tests/ui/parser/struct-literals-in-invalid-places.rs | 20 | ||||
| -rw-r--r-- | tests/ui/parser/struct-literals-in-invalid-places.stderr | 49 |
4 files changed, 66 insertions, 83 deletions
diff --git a/tests/ui/parser/issues/issue-111692.rs b/tests/ui/parser/issues/issue-111692.rs deleted file mode 100644 index de6de222754..00000000000 --- a/tests/ui/parser/issues/issue-111692.rs +++ /dev/null @@ -1,34 +0,0 @@ -mod module { - #[derive(Eq, PartialEq)] - pub struct Type { - pub x: u8, - pub y: u8, - } - - pub const C: u8 = 32u8; -} - -fn test(x: module::Type) { - if x == module::Type { x: module::C, y: 1 } { //~ ERROR struct literals are not allowed here - } -} - -fn test2(x: module::Type) { - if x ==module::Type { x: module::C, y: 1 } { //~ ERROR struct literals are not allowed here - } -} - - -fn test3(x: module::Type) { - use module::Type; - if x == Type { x: module::C, y: 1 } { //~ ERROR struct literals are not allowed here - } -} - -fn test4(x: module::Type) { - use module as demo_module; - if x == demo_module::Type { x: module::C, y: 1 } { //~ ERROR struct literals are not allowed here - } -} - -fn main() { } diff --git a/tests/ui/parser/issues/issue-111692.stderr b/tests/ui/parser/issues/issue-111692.stderr deleted file mode 100644 index 979dfade1ba..00000000000 --- a/tests/ui/parser/issues/issue-111692.stderr +++ /dev/null @@ -1,46 +0,0 @@ -error: struct literals are not allowed here - --> $DIR/issue-111692.rs:12:13 - | -LL | if x == module::Type { x: module::C, y: 1 } { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: surround the struct literal with parentheses - | -LL | if x == (module::Type { x: module::C, y: 1 }) { - | + + - -error: struct literals are not allowed here - --> $DIR/issue-111692.rs:17:12 - | -LL | if x ==module::Type { x: module::C, y: 1 } { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: surround the struct literal with parentheses - | -LL | if x ==(module::Type { x: module::C, y: 1 }) { - | + + - -error: struct literals are not allowed here - --> $DIR/issue-111692.rs:24:13 - | -LL | if x == Type { x: module::C, y: 1 } { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: surround the struct literal with parentheses - | -LL | if x == (Type { x: module::C, y: 1 }) { - | + + - -error: struct literals are not allowed here - --> $DIR/issue-111692.rs:30:13 - | -LL | if x == demo_module::Type { x: module::C, y: 1 } { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: surround the struct literal with parentheses - | -LL | if x == (demo_module::Type { x: module::C, y: 1 }) { - | + + - -error: aborting due to 4 previous errors - diff --git a/tests/ui/parser/struct-literals-in-invalid-places.rs b/tests/ui/parser/struct-literals-in-invalid-places.rs index 89cdb30fc04..eed51b94583 100644 --- a/tests/ui/parser/struct-literals-in-invalid-places.rs +++ b/tests/ui/parser/struct-literals-in-invalid-places.rs @@ -45,12 +45,30 @@ fn main() { println!("yo"); } + // This uses `one()` over `1` as token `one` may begin a type and thus back when type ascription + // `$expr : $ty` still existed, `{ x: one` could've been the start of a block expr which used to + // make the compiler take a different execution path. Now it no longer makes a difference tho. + // Regression test for <https://github.com/rust-lang/rust/issues/82051>. if Foo { x: one(), }.hi() { //~ ERROR struct literals are not allowed here println!("Positive!"); } + + const FOO: Foo = Foo { x: 1 }; + // Below, test that we correctly parenthesize the struct literals. + + // Regression test for <https://github.com/rust-lang/rust/issues/112278>. + if FOO == self::Foo { x: one() } {} //~ ERROR struct literals are not allowed here + + if FOO == Foo::<> { x: one() } {} //~ ERROR struct literals are not allowed here + + fn env<T: Trait<Out = Foo>>() { + if FOO == <T as Trait>::Out { x: one() } {} //~ ERROR struct literals are not allowed here + //~^ ERROR usage of qualified paths in this context is experimental + } } +#[derive(PartialEq, Eq)] struct Foo { x: isize, } @@ -70,3 +88,5 @@ enum E { } fn one() -> isize { 1 } + +trait Trait { type Out; } diff --git a/tests/ui/parser/struct-literals-in-invalid-places.stderr b/tests/ui/parser/struct-literals-in-invalid-places.stderr index ed094fc3e15..39dc2d2efb7 100644 --- a/tests/ui/parser/struct-literals-in-invalid-places.stderr +++ b/tests/ui/parser/struct-literals-in-invalid-places.stderr @@ -120,7 +120,7 @@ LL | while || (Foo { x: 3 }).hi() { | + + error: struct literals are not allowed here - --> $DIR/struct-literals-in-invalid-places.rs:49:8 + --> $DIR/struct-literals-in-invalid-places.rs:53:8 | LL | if Foo { x: one(), }.hi() { | ^^^^^^^^^^^^^^^^^ @@ -130,6 +130,49 @@ help: surround the struct literal with parentheses LL | if (Foo { x: one(), }).hi() { | + + +error: struct literals are not allowed here + --> $DIR/struct-literals-in-invalid-places.rs:61:15 + | +LL | if FOO == self::Foo { x: one() } {} + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: surround the struct literal with parentheses + | +LL | if FOO == (self::Foo { x: one() }) {} + | + + + +error: struct literals are not allowed here + --> $DIR/struct-literals-in-invalid-places.rs:63:15 + | +LL | if FOO == Foo::<> { x: one() } {} + | ^^^^^^^^^^^^^^^^^^^^ + | +help: surround the struct literal with parentheses + | +LL | if FOO == (Foo::<> { x: one() }) {} + | + + + +error: struct literals are not allowed here + --> $DIR/struct-literals-in-invalid-places.rs:66:19 + | +LL | if FOO == <T as Trait>::Out { x: one() } {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: surround the struct literal with parentheses + | +LL | if FOO == (<T as Trait>::Out { x: one() }) {} + | + + + +error[E0658]: usage of qualified paths in this context is experimental + --> $DIR/struct-literals-in-invalid-places.rs:66:19 + | +LL | if FOO == <T as Trait>::Out { x: one() } {} + | ^^^^^^^^^^^^^^^^^ + | + = note: see issue #86935 <https://github.com/rust-lang/rust/issues/86935> for more information + = help: add `#![feature(more_qualified_paths)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + error[E0277]: `bool` is not an iterator --> $DIR/struct-literals-in-invalid-places.rs:9:14 | @@ -185,7 +228,7 @@ help: use parentheses to call this closure LL | while (|| Foo { x: 3 }.hi())() { | + +++ -error: aborting due to 17 previous errors +error: aborting due to 21 previous errors -Some errors have detailed explanations: E0277, E0308, E0533. +Some errors have detailed explanations: E0277, E0308, E0533, E0658. For more information about an error, try `rustc --explain E0277`. |
