mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-21 12:13:12 +00:00
Rollup merge of #117990 - estebank:issue-100825-part-deux, r=Nilstrieb
Tweak error and move tests r? `@Nilstrieb` Split off #117565.
This commit is contained in:
commit
a5d7f8bcf2
@ -2278,9 +2278,8 @@ pub(crate) enum InvalidMutInPattern {
|
||||
#[note(parse_note_mut_pattern_usage)]
|
||||
NonIdent {
|
||||
#[primary_span]
|
||||
#[suggestion(code = "{pat}", applicability = "machine-applicable")]
|
||||
#[suggestion(code = "", applicability = "machine-applicable")]
|
||||
span: Span,
|
||||
pat: String,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -830,8 +830,8 @@ impl<'a> Parser<'a> {
|
||||
// https://github.com/rust-lang/rust/issues/72373
|
||||
if self.prev_token.is_ident() && self.token.kind == token::DotDot {
|
||||
let msg = format!(
|
||||
"if you meant to bind the contents of \
|
||||
the rest of the array pattern into `{}`, use `@`",
|
||||
"if you meant to bind the contents of the rest of the array \
|
||||
pattern into `{}`, use `@`",
|
||||
pprust::token_to_string(&self.prev_token)
|
||||
);
|
||||
expect_err
|
||||
|
@ -638,13 +638,13 @@ impl<'a> Parser<'a> {
|
||||
|
||||
/// Error on `mut $pat` where `$pat` is not an ident.
|
||||
fn ban_mut_general_pat(&self, lo: Span, pat: &Pat, changed_any_binding: bool) {
|
||||
let span = lo.to(pat.span);
|
||||
let pat = pprust::pat_to_string(&pat);
|
||||
|
||||
self.sess.emit_err(if changed_any_binding {
|
||||
InvalidMutInPattern::NestedIdent { span, pat }
|
||||
InvalidMutInPattern::NestedIdent {
|
||||
span: lo.to(pat.span),
|
||||
pat: pprust::pat_to_string(&pat),
|
||||
}
|
||||
} else {
|
||||
InvalidMutInPattern::NonIdent { span, pat }
|
||||
InvalidMutInPattern::NonIdent { span: lo.until(pat.span) }
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ error: `mut` must be followed by a named binding
|
||||
--> $DIR/issue-32501.rs:7:9
|
||||
|
|
||||
LL | let mut _ = 0;
|
||||
| ^^^^^ help: remove the `mut` prefix: `_`
|
||||
| ^^^^ help: remove the `mut` prefix
|
||||
|
|
||||
= note: `mut` may be followed by `variable` and `variable @ pattern`
|
||||
|
||||
|
@ -2,7 +2,7 @@ error: `mut` must be followed by a named binding
|
||||
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:6:13
|
||||
|
|
||||
LL | let mut $eval = ();
|
||||
| ^^^^^^^^^ help: remove the `mut` prefix: `does_not_exist!()`
|
||||
| ^^^^ help: remove the `mut` prefix
|
||||
...
|
||||
LL | mac1! { does_not_exist!() }
|
||||
| --------------------------- in this macro invocation
|
||||
@ -25,7 +25,7 @@ error: `mut` must be followed by a named binding
|
||||
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:13:13
|
||||
|
|
||||
LL | let mut $eval = ();
|
||||
| ^^^ help: remove the `mut` prefix: `does_not_exist!()`
|
||||
| ^^^ help: remove the `mut` prefix
|
||||
...
|
||||
LL | mac2! { does_not_exist!() }
|
||||
| --------------------------- in this macro invocation
|
||||
|
@ -2,7 +2,7 @@ error: `mut` must be followed by a named binding
|
||||
--> $DIR/mut-patterns.rs:9:9
|
||||
|
|
||||
LL | let mut _ = 0;
|
||||
| ^^^^^ help: remove the `mut` prefix: `_`
|
||||
| ^^^^ help: remove the `mut` prefix
|
||||
|
|
||||
= note: `mut` may be followed by `variable` and `variable @ pattern`
|
||||
|
||||
@ -10,7 +10,7 @@ error: `mut` must be followed by a named binding
|
||||
--> $DIR/mut-patterns.rs:10:9
|
||||
|
|
||||
LL | let mut (_, _) = (0, 0);
|
||||
| ^^^^^^^^^^ help: remove the `mut` prefix: `(_, _)`
|
||||
| ^^^^ help: remove the `mut` prefix
|
||||
|
|
||||
= note: `mut` may be followed by `variable` and `variable @ pattern`
|
||||
|
||||
|
@ -0,0 +1,14 @@
|
||||
fn main() {
|
||||
let val = 42;
|
||||
let x = match val {
|
||||
(0 if true) => {
|
||||
//~^ ERROR expected identifier, found keyword `if`
|
||||
//~| ERROR expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found keyword `if`
|
||||
//~| ERROR expected one of `)`, `,`, `@`, or `|`, found keyword `true`
|
||||
//~| ERROR mismatched types
|
||||
42u8
|
||||
}
|
||||
_ => 0u8,
|
||||
};
|
||||
let _y: u32 = x; //~ ERROR mismatched types
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
error: expected identifier, found keyword `if`
|
||||
--> $DIR/recover-parens-around-match-arm-head.rs:4:12
|
||||
|
|
||||
LL | (0 if true) => {
|
||||
| ^^ expected identifier, found keyword
|
||||
|
||||
error: expected one of `)`, `,`, `...`, `..=`, `..`, or `|`, found keyword `if`
|
||||
--> $DIR/recover-parens-around-match-arm-head.rs:4:12
|
||||
|
|
||||
LL | (0 if true) => {
|
||||
| -^^ expected one of `)`, `,`, `...`, `..=`, `..`, or `|`
|
||||
| |
|
||||
| help: missing `,`
|
||||
|
||||
error: expected one of `)`, `,`, `@`, or `|`, found keyword `true`
|
||||
--> $DIR/recover-parens-around-match-arm-head.rs:4:15
|
||||
|
|
||||
LL | (0 if true) => {
|
||||
| -^^^^ expected one of `)`, `,`, `@`, or `|`
|
||||
| |
|
||||
| help: missing `,`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/recover-parens-around-match-arm-head.rs:4:9
|
||||
|
|
||||
LL | let x = match val {
|
||||
| --- this expression has type `{integer}`
|
||||
LL | (0 if true) => {
|
||||
| ^^^^^^^^^^^ expected integer, found `(_, _, _)`
|
||||
|
|
||||
= note: expected type `{integer}`
|
||||
found tuple `(_, _, _)`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/recover-parens-around-match-arm-head.rs:13:19
|
||||
|
|
||||
LL | let _y: u32 = x;
|
||||
| --- ^ expected `u32`, found `u8`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
help: you can convert a `u8` to a `u32`
|
||||
|
|
||||
LL | let _y: u32 = x.into();
|
||||
| +++++++
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
@ -14,7 +14,7 @@ error: `mut` must be followed by a named binding
|
||||
--> $DIR/self_type_keyword.rs:16:9
|
||||
|
|
||||
LL | mut Self => (),
|
||||
| ^^^^^^^^ help: remove the `mut` prefix: `Self`
|
||||
| ^^^^ help: remove the `mut` prefix
|
||||
|
|
||||
= note: `mut` may be followed by `variable` and `variable @ pattern`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user