]> git.lizzy.rs Git - rust.git/commitdiff
Emit fewer errors on patterns with possible type ascription
authorEsteban Küber <esteban@kuber.com.ar>
Tue, 17 Jan 2023 01:50:45 +0000 (01:50 +0000)
committerEsteban Küber <esteban@kuber.com.ar>
Tue, 17 Jan 2023 01:58:37 +0000 (01:58 +0000)
compiler/rustc_parse/src/parser/diagnostics.rs
tests/ui/parser/anon-enums.rs
tests/ui/parser/anon-enums.stderr
tests/ui/parser/issues/issue-87086-colon-path-sep.rs
tests/ui/parser/issues/issue-87086-colon-path-sep.stderr

index 07bd76dc39ba9fee87694b885a0ed2ea207c785b..eda7046c748e5f52121854349a3fa6f903e502d2 100644 (file)
@@ -2500,6 +2500,8 @@ pub(crate) fn maybe_recover_colon_colon_in_pat_typo_or_anon_enum(
                     Ok(ty) => {
                         err.span_label(ty.span, "specifying the type of a pattern isn't supported");
                         self.restore_snapshot(snapshot_type);
+                        let new_span = first_pat.span.to(ty.span);
+                        first_pat = self.mk_pat(new_span, PatKind::Wild);
                     }
                 }
                 err.emit();
index a8b5e8359d99612f0b5deb817236b6f9ec5523e7..56b8a3d43bedf674eb4a879fea8252e8f2f9273e 100644 (file)
@@ -3,7 +3,6 @@ fn foo(x: bool | i32) -> i32 | f64 {
 //~| ERROR anonymous enums are not supported
     match x {
         x: i32 => x, //~ ERROR expected
-        //~^ ERROR failed to resolve
         true => 42.,
         false => 0.333,
     }
@@ -14,6 +13,5 @@ fn main() {
         42: i32 => (), //~ ERROR expected
         _: f64 => (), //~ ERROR expected
         x: i32 => (), //~ ERROR expected
-        //~^ ERROR failed to resolve
     }
 }
index 4febf2df0dc72a967ab661ebb4abd67cd8b5e05a..841582256609121d41403607a0fe2d2a1b43c65c 100644 (file)
@@ -36,7 +36,7 @@ LL |         x::i32 => x,
    |          ~~
 
 error: expected one of `...`, `..=`, `..`, or `|`, found `:`
-  --> $DIR/anon-enums.rs:14:11
+  --> $DIR/anon-enums.rs:13:11
    |
 LL |         42: i32 => (),
    |           ^ --- specifying the type of a pattern isn't supported
@@ -44,7 +44,7 @@ LL |         42: i32 => (),
    |           expected one of `...`, `..=`, `..`, or `|`
 
 error: expected `|`, found `:`
-  --> $DIR/anon-enums.rs:15:10
+  --> $DIR/anon-enums.rs:14:10
    |
 LL |         _: f64 => (),
    |          ^ --- specifying the type of a pattern isn't supported
@@ -52,7 +52,7 @@ LL |         _: f64 => (),
    |          expected `|`
 
 error: expected one of `@` or `|`, found `:`
-  --> $DIR/anon-enums.rs:16:10
+  --> $DIR/anon-enums.rs:15:10
    |
 LL |         x: i32 => (),
    |          ^ --- specifying the type of a pattern isn't supported
@@ -64,18 +64,5 @@ help: maybe write a path separator here
 LL |         x::i32 => (),
    |          ~~
 
-error[E0433]: failed to resolve: use of undeclared crate or module `x`
-  --> $DIR/anon-enums.rs:5:9
-   |
-LL |         x: i32 => x,
-   |         ^ use of undeclared crate or module `x`
-
-error[E0433]: failed to resolve: use of undeclared crate or module `x`
-  --> $DIR/anon-enums.rs:16:9
-   |
-LL |         x: i32 => (),
-   |         ^ use of undeclared crate or module `x`
-
-error: aborting due to 8 previous errors
+error: aborting due to 6 previous errors
 
-For more information about this error, try `rustc --explain E0433`.
index 0b7b67496d6f32df39107feb43e1c957a029ae21..e1ea38f2795df698983f335bbf6b77f13d29dad1 100644 (file)
@@ -68,7 +68,6 @@ fn main() {
         Foo:Bar::Baz => {}
         //~^ ERROR: expected one of
         //~| HELP: maybe write a path separator here
-        //~| ERROR: failed to resolve: `Bar` is a variant, not a module
     }
     match myfoo {
         Foo::Bar => {}
index ed05bfe8b0a32cc804dc51b59d056405dcc9e7c6..63b072ac4cdc68c6c4f9ec8734f49945c45de38e 100644 (file)
@@ -103,7 +103,7 @@ LL |         Foo::Bar::Baz => {}
    |            ~~
 
 error: expected one of `@` or `|`, found `:`
-  --> $DIR/issue-87086-colon-path-sep.rs:75:12
+  --> $DIR/issue-87086-colon-path-sep.rs:74:12
    |
 LL |         Foo:Bar => {}
    |            ^--- specifying the type of a pattern isn't supported
@@ -115,12 +115,5 @@ help: maybe write a path separator here
 LL |         Foo::Bar => {}
    |            ~~
 
-error[E0433]: failed to resolve: `Bar` is a variant, not a module
-  --> $DIR/issue-87086-colon-path-sep.rs:68:13
-   |
-LL |         Foo:Bar::Baz => {}
-   |             ^^^ `Bar` is a variant, not a module
-
-error: aborting due to 10 previous errors
+error: aborting due to 9 previous errors
 
-For more information about this error, try `rustc --explain E0433`.