diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-03-25 17:05:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-25 17:05:33 +0100 |
| commit | e9ec44251c32dfe2a8e0b82a72b402df615bbd8b (patch) | |
| tree | c405692cef9241f9742b3889bcc00d2c6f48c78c /tests/ui/pattern | |
| parent | ccc5310922807e168d3be5c22b77cf3d76ce4f09 (diff) | |
| parent | 08235b1603f77f39468e7b2e552945501c0cc048 (diff) | |
| download | rust-e9ec44251c32dfe2a8e0b82a72b402df615bbd8b.tar.gz rust-e9ec44251c32dfe2a8e0b82a72b402df615bbd8b.zip | |
Rollup merge of #122910 - compiler-errors:unit-struct-in-path-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 #122809
Diffstat (limited to 'tests/ui/pattern')
3 files changed, 65 insertions, 0 deletions
diff --git a/tests/ui/pattern/no-match-tuple-variant-self-ctor.rs b/tests/ui/pattern/no-match-tuple-variant-self-ctor.rs new file mode 100644 index 00000000000..7c2821e77ab --- /dev/null +++ b/tests/ui/pattern/no-match-tuple-variant-self-ctor.rs @@ -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() {} diff --git a/tests/ui/pattern/no-match-tuple-variant-self-ctor.struct_.stderr b/tests/ui/pattern/no-match-tuple-variant-self-ctor.struct_.stderr new file mode 100644 index 00000000000..5ed3979feb8 --- /dev/null +++ b/tests/ui/pattern/no-match-tuple-variant-self-ctor.struct_.stderr @@ -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`. diff --git a/tests/ui/pattern/no-match-tuple-variant-self-ctor.tuple.stderr b/tests/ui/pattern/no-match-tuple-variant-self-ctor.tuple.stderr new file mode 100644 index 00000000000..d31a4a79189 --- /dev/null +++ b/tests/ui/pattern/no-match-tuple-variant-self-ctor.tuple.stderr @@ -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`. |
