forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
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#122910 - compiler-errors:unit-struct-in-pat…
…h-pat-only, r=petrochenkov Validate that we're only matching on unit struct for path pattern Resolution doesn't validate that we only really take `CtorKind::Unit` in path patterns, since all it sees is `Res::SelfCtor(def_id)`. Check this instead during pattern typeck. r? petrochenkov Fixes rust-lang#122809
- Loading branch information
Showing
6 changed files
with
91 additions
and
8 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
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
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
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,37 @@ | ||
//@ revisions: tuple unit struct_ | ||
//@[unit] check-pass | ||
|
||
#[cfg(unit)] | ||
mod unit { | ||
struct S; | ||
impl S { | ||
fn foo() { | ||
let Self = S; | ||
} | ||
} | ||
} | ||
|
||
#[cfg(tuple)] | ||
mod tuple { | ||
struct S(()); | ||
impl S { | ||
fn foo() { | ||
let Self = S; | ||
//[tuple]~^ ERROR expected unit struct | ||
} | ||
} | ||
} | ||
|
||
#[cfg(struct_)] | ||
mod struct_ { | ||
struct S {} | ||
impl S { | ||
fn foo() { | ||
let Self = S; | ||
//[struct_]~^ ERROR expected value, found struct `S` | ||
//[struct_]~| ERROR expected unit struct, found self constructor `Self` | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
tests/ui/pattern/no-match-tuple-variant-self-ctor.struct_.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,19 @@ | ||
error[E0423]: expected value, found struct `S` | ||
--> $DIR/no-match-tuple-variant-self-ctor.rs:30:24 | ||
| | ||
LL | struct S {} | ||
| ----------- `S` defined here | ||
... | ||
LL | let Self = S; | ||
| ^ help: use struct literal syntax instead: `S {}` | ||
|
||
error[E0533]: expected unit struct, found self constructor `Self` | ||
--> $DIR/no-match-tuple-variant-self-ctor.rs:30:17 | ||
| | ||
LL | let Self = S; | ||
| ^^^^ not a unit struct | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0423, E0533. | ||
For more information about an error, try `rustc --explain E0423`. |
9 changes: 9 additions & 0 deletions
9
tests/ui/pattern/no-match-tuple-variant-self-ctor.tuple.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,9 @@ | ||
error[E0533]: expected unit struct, found self constructor `Self` | ||
--> $DIR/no-match-tuple-variant-self-ctor.rs:19:17 | ||
| | ||
LL | let Self = S; | ||
| ^^^^ not a unit struct | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0533`. |