forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#135222 - estebank:issue-135209, r=compiler-errors Ensure that we don't try to access fields on a non-struct pattern type Fix rust-lang#135209.
- Loading branch information
Showing
5 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/ui/pattern/struct-pattern-on-non-struct-resolve-error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Regression test for #135209. | ||
// We ensure that we don't try to access fields on a non-struct pattern type. | ||
fn main() { | ||
if let <Vec<()> as Iterator>::Item { .. } = 1 { | ||
//~^ ERROR E0658 | ||
//~| ERROR E0071 | ||
//~| ERROR E0277 | ||
x //~ ERROR E0425 | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/ui/pattern/struct-pattern-on-non-struct-resolve-error.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
error[E0425]: cannot find value `x` in this scope | ||
--> $DIR/struct-pattern-on-non-struct-resolve-error.rs:8:9 | ||
| | ||
LL | x | ||
| ^ not found in this scope | ||
|
||
error[E0658]: usage of qualified paths in this context is experimental | ||
--> $DIR/struct-pattern-on-non-struct-resolve-error.rs:4:12 | ||
| | ||
LL | if let <Vec<()> as Iterator>::Item { .. } = 1 { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= 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[E0071]: expected struct, variant or union type, found inferred type | ||
--> $DIR/struct-pattern-on-non-struct-resolve-error.rs:4:12 | ||
| | ||
LL | if let <Vec<()> as Iterator>::Item { .. } = 1 { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a struct | ||
|
||
error[E0277]: `Vec<()>` is not an iterator | ||
--> $DIR/struct-pattern-on-non-struct-resolve-error.rs:4:12 | ||
| | ||
LL | if let <Vec<()> as Iterator>::Item { .. } = 1 { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Vec<()>` is not an iterator | ||
| | ||
= help: the trait `Iterator` is not implemented for `Vec<()>` | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0071, E0277, E0425, E0658. | ||
For more information about an error, try `rustc --explain E0071`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14
tests/ui/pattern/struct-pattern-with-missing-fields-resolve-error.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
error: expected `,` | ||
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:12:31 | ||
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:16:31 | ||
| | ||
LL | if let Website { url, Some(title) } = website { | ||
| ------- ^ | ||
| | | ||
| while parsing the fields for this pattern | ||
|
||
error[E0425]: cannot find value `title` in this scope | ||
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:18:30 | ||
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:22:30 | ||
| | ||
LL | if let Website { url, .. } = website { | ||
| ------------------- this pattern doesn't include `title`, which is available in `Website` | ||
LL | println!("[{}]({})", title, url); | ||
| ^^^^^ not found in this scope | ||
|
||
error: aborting due to 2 previous errors | ||
error[E0425]: cannot find value `a` in this scope | ||
--> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:28:20 | ||
| | ||
LL | if let Foo::Bar { .. } = x { | ||
| --------------- this pattern doesn't include `a`, which is available in `Bar` | ||
LL | println!("{a}"); | ||
| ^ help: a local variable with a similar name exists: `x` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0425`. |