Combine several test files into one

This makes it a lot easier to add smaller regression tests
related to "incorrectly placed" struct literals.
This commit is contained in:
León Orell Valerian Liehr 2025-03-24 17:16:26 +01:00
parent 9f336ce2eb
commit 598f865874
No known key found for this signature in database
GPG key ID: D17A07215F68E713
16 changed files with 263 additions and 372 deletions

View file

@ -1,13 +0,0 @@
pub struct Example { a: i32 }
impl Example {
fn is_pos(&self) -> bool { self.a > 0 }
}
fn one() -> i32 { 1 }
fn main() {
if Example { a: one(), }.is_pos() { //~ ERROR struct literals are not allowed here
println!("Positive!");
}
}

View file

@ -1,13 +0,0 @@
error: struct literals are not allowed here
--> $DIR/method-call-on-struct-literal-in-if-condition.rs:10:8
|
LL | if Example { a: one(), }.is_pos() {
| ^^^^^^^^^^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if (Example { a: one(), }).is_pos() {
| + +
error: aborting due to 1 previous error

View file

@ -1,17 +0,0 @@
struct Foo {
x: isize,
}
impl Foo {
fn hi(&self) -> bool {
true
}
}
fn main() {
for x in Foo { //~ ERROR struct literals are not allowed here
x: 3 //~^ ERROR `bool` is not an iterator
}.hi() {
println!("yo");
}
}

View file

@ -1,31 +0,0 @@
error: struct literals are not allowed here
--> $DIR/struct-literal-in-for.rs:12:14
|
LL | for x in Foo {
| ______________^
LL | | x: 3
LL | | }.hi() {
| |_____^
|
help: surround the struct literal with parentheses
|
LL ~ for x in (Foo {
LL | x: 3
LL ~ }).hi() {
|
error[E0277]: `bool` is not an iterator
--> $DIR/struct-literal-in-for.rs:12:14
|
LL | for x in Foo {
| ______________^
LL | | x: 3
LL | | }.hi() {
| |__________^ `bool` is not an iterator
|
= help: the trait `Iterator` is not implemented for `bool`
= note: required for `bool` to implement `IntoIterator`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,22 +0,0 @@
struct Foo {
x: isize,
}
impl Foo {
fn hi(&self) -> bool {
true
}
}
fn main() {
if Foo { //~ ERROR struct literals are not allowed here
x: 3
}.hi() {
println!("yo");
}
if let true = Foo { //~ ERROR struct literals are not allowed here
x: 3
}.hi() {
println!("yo");
}
}

View file

@ -1,34 +0,0 @@
error: struct literals are not allowed here
--> $DIR/struct-literal-in-if.rs:12:8
|
LL | if Foo {
| ________^
LL | | x: 3
LL | | }.hi() {
| |_____^
|
help: surround the struct literal with parentheses
|
LL ~ if (Foo {
LL | x: 3
LL ~ }).hi() {
|
error: struct literals are not allowed here
--> $DIR/struct-literal-in-if.rs:17:19
|
LL | if let true = Foo {
| ___________________^
LL | | x: 3
LL | | }.hi() {
| |_____^
|
help: surround the struct literal with parentheses
|
LL ~ if let true = (Foo {
LL | x: 3
LL ~ }).hi() {
|
error: aborting due to 2 previous errors

View file

@ -1,13 +0,0 @@
struct Foo {
x: isize,
}
fn main() {
match Foo { //~ ERROR struct literals are not allowed here
x: 3
} {
Foo {
x: x
} => {}
}
}

View file

@ -1,18 +0,0 @@
error: struct literals are not allowed here
--> $DIR/struct-literal-in-match-discriminant.rs:6:11
|
LL | match Foo {
| ___________^
LL | | x: 3
LL | | } {
| |_____^
|
help: surround the struct literal with parentheses
|
LL ~ match (Foo {
LL | x: 3
LL ~ }) {
|
error: aborting due to 1 previous error

View file

@ -1,22 +0,0 @@
struct Foo {
x: isize,
}
impl Foo {
fn hi(&self) -> bool {
true
}
}
fn main() {
while Foo { //~ ERROR struct literals are not allowed here
x: 3
}.hi() {
println!("yo");
}
while let true = Foo { //~ ERROR struct literals are not allowed here
x: 3
}.hi() {
println!("yo");
}
}

View file

@ -1,34 +0,0 @@
error: struct literals are not allowed here
--> $DIR/struct-literal-in-while.rs:12:11
|
LL | while Foo {
| ___________^
LL | | x: 3
LL | | }.hi() {
| |_____^
|
help: surround the struct literal with parentheses
|
LL ~ while (Foo {
LL | x: 3
LL ~ }).hi() {
|
error: struct literals are not allowed here
--> $DIR/struct-literal-in-while.rs:17:22
|
LL | while let true = Foo {
| ______________________^
LL | | x: 3
LL | | }.hi() {
| |_____^
|
help: surround the struct literal with parentheses
|
LL ~ while let true = (Foo {
LL | x: 3
LL ~ }).hi() {
|
error: aborting due to 2 previous errors

View file

@ -1,17 +0,0 @@
struct Foo {
x: isize,
}
impl Foo {
fn hi(&self) -> bool {
true
}
}
fn main() {
while || Foo { //~ ERROR struct literals are not allowed here
x: 3 //~^ ERROR mismatched types
}.hi() {
println!("yo");
}
}

View file

@ -1,37 +0,0 @@
error: struct literals are not allowed here
--> $DIR/struct-literal-restrictions-in-lamda.rs:12:14
|
LL | while || Foo {
| ______________^
LL | | x: 3
LL | | }.hi() {
| |_____^
|
help: surround the struct literal with parentheses
|
LL ~ while || (Foo {
LL | x: 3
LL ~ }).hi() {
|
error[E0308]: mismatched types
--> $DIR/struct-literal-restrictions-in-lamda.rs:12:11
|
LL | while || Foo {
| ___________^
LL | | x: 3
LL | | }.hi() {
| |__________^ expected `bool`, found closure
|
= note: expected type `bool`
found closure `{closure@$DIR/struct-literal-restrictions-in-lamda.rs:12:11: 12:13}`
help: use parentheses to call this closure
|
LL ~ while (|| Foo {
LL | x: 3
LL ~ }.hi())() {
|
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.

View file

@ -1,25 +0,0 @@
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
enum E {
V { field: bool },
I { field1: bool, field2: usize },
J { field: isize },
K { field: &'static str},
}
fn test_E(x: E) {
let field = true;
if x == E::V { field } {}
//~^ ERROR expected value, found struct variant `E::V`
//~| ERROR mismatched types
if x == E::I { field1: true, field2: 42 } {}
//~^ ERROR struct literals are not allowed here
if x == E::V { field: false } {}
//~^ ERROR struct literals are not allowed here
if x == E::J { field: -42 } {}
//~^ ERROR struct literals are not allowed here
if x == E::K { field: "" } {}
//~^ ERROR struct literals are not allowed here
let y: usize = ();
//~^ ERROR mismatched types
}
fn main() {}

View file

@ -1,76 +0,0 @@
error: struct literals are not allowed here
--> $DIR/struct-literal-variant-in-if.rs:13:13
|
LL | if x == E::I { field1: true, field2: 42 } {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if x == (E::I { field1: true, field2: 42 }) {}
| + +
error: struct literals are not allowed here
--> $DIR/struct-literal-variant-in-if.rs:15:13
|
LL | if x == E::V { field: false } {}
| ^^^^^^^^^^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if x == (E::V { field: false }) {}
| + +
error: struct literals are not allowed here
--> $DIR/struct-literal-variant-in-if.rs:17:13
|
LL | if x == E::J { field: -42 } {}
| ^^^^^^^^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if x == (E::J { field: -42 }) {}
| + +
error: struct literals are not allowed here
--> $DIR/struct-literal-variant-in-if.rs:19:13
|
LL | if x == E::K { field: "" } {}
| ^^^^^^^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if x == (E::K { field: "" }) {}
| + +
error[E0533]: expected value, found struct variant `E::V`
--> $DIR/struct-literal-variant-in-if.rs:10:13
|
LL | if x == E::V { field } {}
| ^^^^ not a value
|
help: you might have meant to create a new value of the struct
|
LL | if x == (E::V { field }) {}
| + +
error[E0308]: mismatched types
--> $DIR/struct-literal-variant-in-if.rs:10:20
|
LL | if x == E::V { field } {}
| ---------------^^^^^--
| | |
| | expected `()`, found `bool`
| expected this to be `()`
error[E0308]: mismatched types
--> $DIR/struct-literal-variant-in-if.rs:21:20
|
LL | let y: usize = ();
| ----- ^^ expected `usize`, found `()`
| |
| expected due to this
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0308, E0533.
For more information about an error, try `rustc --explain E0308`.

View file

@ -0,0 +1,72 @@
fn main() {
if Foo { x: 3 }.hi() { //~ ERROR struct literals are not allowed here
println!("yo");
}
if let true = Foo { x: 3 }.hi() { //~ ERROR struct literals are not allowed here
println!("yo");
}
for x in Foo { x: 3 }.hi() { //~ ERROR struct literals are not allowed here
//~^ ERROR `bool` is not an iterator
println!("yo");
}
while Foo { x: 3 }.hi() { //~ ERROR struct literals are not allowed here
println!("yo");
}
while let true = Foo { x: 3 }.hi() { //~ ERROR struct literals are not allowed here
println!("yo");
}
match Foo { x: 3 } { //~ ERROR struct literals are not allowed here
Foo { x: x } => {}
}
let _ = |x: E| {
let field = true;
if x == E::V { field } {}
//~^ ERROR expected value, found struct variant `E::V`
//~| ERROR mismatched types
if x == E::I { field1: true, field2: 42 } {}
//~^ ERROR struct literals are not allowed here
if x == E::V { field: false } {}
//~^ ERROR struct literals are not allowed here
if x == E::J { field: -42 } {}
//~^ ERROR struct literals are not allowed here
if x == E::K { field: "" } {}
//~^ ERROR struct literals are not allowed here
let y: usize = ();
//~^ ERROR mismatched types
};
// Regression test for <https://github.com/rust-lang/rust/issues/43412>.
while || Foo { x: 3 }.hi() { //~ ERROR struct literals are not allowed here
//~^ ERROR mismatched types
println!("yo");
}
// 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!");
}
}
struct Foo {
x: isize,
}
impl Foo {
fn hi(&self) -> bool {
true
}
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
enum E {
V { field: bool },
I { field1: bool, field2: usize },
J { field: isize },
K { field: &'static str},
}
fn one() -> isize { 1 }

View file

@ -0,0 +1,191 @@
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:2:8
|
LL | if Foo { x: 3 }.hi() {
| ^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if (Foo { x: 3 }).hi() {
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:5:19
|
LL | if let true = Foo { x: 3 }.hi() {
| ^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if let true = (Foo { x: 3 }).hi() {
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:9:14
|
LL | for x in Foo { x: 3 }.hi() {
| ^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | for x in (Foo { x: 3 }).hi() {
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:14:11
|
LL | while Foo { x: 3 }.hi() {
| ^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | while (Foo { x: 3 }).hi() {
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:17:22
|
LL | while let true = Foo { x: 3 }.hi() {
| ^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | while let true = (Foo { x: 3 }).hi() {
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:21:11
|
LL | match Foo { x: 3 } {
| ^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | match (Foo { x: 3 }) {
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:30:17
|
LL | if x == E::I { field1: true, field2: 42 } {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if x == (E::I { field1: true, field2: 42 }) {}
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:32:17
|
LL | if x == E::V { field: false } {}
| ^^^^^^^^^^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if x == (E::V { field: false }) {}
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:34:17
|
LL | if x == E::J { field: -42 } {}
| ^^^^^^^^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if x == (E::J { field: -42 }) {}
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:36:17
|
LL | if x == E::K { field: "" } {}
| ^^^^^^^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if x == (E::K { field: "" }) {}
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:43:14
|
LL | while || Foo { x: 3 }.hi() {
| ^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | while || (Foo { x: 3 }).hi() {
| + +
error: struct literals are not allowed here
--> $DIR/struct-literals-in-invalid-places.rs:49:8
|
LL | if Foo { x: one(), }.hi() {
| ^^^^^^^^^^^^^^^^^
|
help: surround the struct literal with parentheses
|
LL | if (Foo { x: one(), }).hi() {
| + +
error[E0277]: `bool` is not an iterator
--> $DIR/struct-literals-in-invalid-places.rs:9:14
|
LL | for x in Foo { x: 3 }.hi() {
| ^^^^^^^^^^^^^^^^^ `bool` is not an iterator
|
= help: the trait `Iterator` is not implemented for `bool`
= note: required for `bool` to implement `IntoIterator`
error[E0533]: expected value, found struct variant `E::V`
--> $DIR/struct-literals-in-invalid-places.rs:27:17
|
LL | if x == E::V { field } {}
| ^^^^ not a value
|
help: you might have meant to create a new value of the struct
|
LL | if x == (E::V { field }) {}
| + +
error[E0308]: mismatched types
--> $DIR/struct-literals-in-invalid-places.rs:27:24
|
LL | if x == E::V { field } {}
| ---------------^^^^^--
| | |
| | expected `()`, found `bool`
| expected this to be `()`
|
help: you might have meant to return this value
|
LL | if x == E::V { return field; } {}
| ++++++ +
error[E0308]: mismatched types
--> $DIR/struct-literals-in-invalid-places.rs:38:24
|
LL | let y: usize = ();
| ----- ^^ expected `usize`, found `()`
| |
| expected due to this
error[E0308]: mismatched types
--> $DIR/struct-literals-in-invalid-places.rs:43:11
|
LL | while || Foo { x: 3 }.hi() {
| ^^^^^^^^^^^^^^^^^^^^ expected `bool`, found closure
|
= note: expected type `bool`
found closure `{closure@$DIR/struct-literals-in-invalid-places.rs:43:11: 43:13}`
help: use parentheses to call this closure
|
LL | while (|| Foo { x: 3 }.hi())() {
| + +++
error: aborting due to 17 previous errors
Some errors have detailed explanations: E0277, E0308, E0533.
For more information about an error, try `rustc --explain E0277`.