diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-07-14 09:35:26 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-14 09:35:26 +0900 |
| commit | d8943a7d5295e5176ef1cc18e176b2cfe57c4959 (patch) | |
| tree | d56c419de6e88ecee4e2fa8dd82c4f303f0a371f /src | |
| parent | 4ec7b489d674162e8c945129ca9f2facfb9eb4f8 (diff) | |
| parent | 23624504250058c36f42fe3eb76300da962e393b (diff) | |
| download | rust-d8943a7d5295e5176ef1cc18e176b2cfe57c4959.tar.gz rust-d8943a7d5295e5176ef1cc18e176b2cfe57c4959.zip | |
Rollup merge of #87101 - FabianWolff:issue-87086, r=estebank
Suggest a path separator if a stray colon is found in a match arm Attempts to fix #87086. r? `@estebank`
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/parser/issue-87086-colon-path-sep.rs | 66 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-87086-colon-path-sep.stderr | 68 |
2 files changed, 134 insertions, 0 deletions
diff --git a/src/test/ui/parser/issue-87086-colon-path-sep.rs b/src/test/ui/parser/issue-87086-colon-path-sep.rs new file mode 100644 index 00000000000..4ee0b2054ff --- /dev/null +++ b/src/test/ui/parser/issue-87086-colon-path-sep.rs @@ -0,0 +1,66 @@ +// Tests that a suggestion is issued if the user wrote a colon instead of +// a path separator in a match arm. + +enum Foo { + Bar, + Baz, +} + +fn f() -> Foo { Foo::Bar } + +fn g1() { + match f() { + Foo:Bar => {} + //~^ ERROR: expected one of + //~| HELP: maybe write a path separator here + _ => {} + } + match f() { + Foo::Bar:Baz => {} + //~^ ERROR: expected one of + //~| HELP: maybe write a path separator here + _ => {} + } + match f() { + Foo:Bar::Baz => {} + //~^ ERROR: expected one of + //~| HELP: maybe write a path separator here + _ => {} + } + match f() { + Foo: Bar::Baz if true => {} + //~^ ERROR: expected one of + //~| HELP: maybe write a path separator here + _ => {} + } + if let Bar:Baz = f() { + //~^ ERROR: expected one of + //~| HELP: maybe write a path separator here + } +} + +fn g1_neg() { + match f() { + ref Foo: Bar::Baz => {} + //~^ ERROR: expected one of + _ => {} + } +} + +fn g2_neg() { + match f() { + mut Foo: Bar::Baz => {} + //~^ ERROR: expected one of + _ => {} + } +} + +fn main() { + let myfoo = Foo::Bar; + match myfoo { + Foo::Bar => {} + Foo:Bar::Baz => {} + //~^ ERROR: expected one of + //~| HELP: maybe write a path separator here + } +} diff --git a/src/test/ui/parser/issue-87086-colon-path-sep.stderr b/src/test/ui/parser/issue-87086-colon-path-sep.stderr new file mode 100644 index 00000000000..8f93661a626 --- /dev/null +++ b/src/test/ui/parser/issue-87086-colon-path-sep.stderr @@ -0,0 +1,68 @@ +error: expected one of `@` or `|`, found `:` + --> $DIR/issue-87086-colon-path-sep.rs:13:12 + | +LL | Foo:Bar => {} + | ^ + | | + | expected one of `@` or `|` + | help: maybe write a path separator here: `::` + +error: expected one of `!`, `(`, `...`, `..=`, `..`, `::`, `{`, or `|`, found `:` + --> $DIR/issue-87086-colon-path-sep.rs:19:17 + | +LL | Foo::Bar:Baz => {} + | ^ + | | + | expected one of 8 possible tokens + | help: maybe write a path separator here: `::` + +error: expected one of `@` or `|`, found `:` + --> $DIR/issue-87086-colon-path-sep.rs:25:12 + | +LL | Foo:Bar::Baz => {} + | ^ + | | + | expected one of `@` or `|` + | help: maybe write a path separator here: `::` + +error: expected one of `@` or `|`, found `:` + --> $DIR/issue-87086-colon-path-sep.rs:31:12 + | +LL | Foo: Bar::Baz if true => {} + | ^ + | | + | expected one of `@` or `|` + | help: maybe write a path separator here: `::` + +error: expected one of `@` or `|`, found `:` + --> $DIR/issue-87086-colon-path-sep.rs:36:15 + | +LL | if let Bar:Baz = f() { + | ^ + | | + | expected one of `@` or `|` + | help: maybe write a path separator here: `::` + +error: expected one of `=>`, `@`, `if`, or `|`, found `:` + --> $DIR/issue-87086-colon-path-sep.rs:44:16 + | +LL | ref Foo: Bar::Baz => {} + | ^ expected one of `=>`, `@`, `if`, or `|` + +error: expected one of `=>`, `@`, `if`, or `|`, found `:` + --> $DIR/issue-87086-colon-path-sep.rs:52:16 + | +LL | mut Foo: Bar::Baz => {} + | ^ expected one of `=>`, `@`, `if`, or `|` + +error: expected one of `@` or `|`, found `:` + --> $DIR/issue-87086-colon-path-sep.rs:62:12 + | +LL | Foo:Bar::Baz => {} + | ^ + | | + | expected one of `@` or `|` + | help: maybe write a path separator here: `::` + +error: aborting due to 8 previous errors + |
