2013-10-22 23:51:45 -04:00
|
|
|
// Can't put mut in non-ident pattern
|
|
|
|
|
2019-08-27 13:04:48 +02:00
|
|
|
//@ edition:2018
|
|
|
|
|
|
|
|
#![feature(box_patterns)]
|
|
|
|
#![allow(warnings)]
|
|
|
|
|
2013-10-22 23:51:45 -04:00
|
|
|
pub fn main() {
|
2019-08-27 23:44:44 +02:00
|
|
|
let mut _ = 0; //~ ERROR `mut` must be followed by a named binding
|
|
|
|
let mut (_, _) = (0, 0); //~ ERROR `mut` must be followed by a named binding
|
|
|
|
|
2020-02-17 16:03:07 +01:00
|
|
|
let mut (x @ y) = 0; //~ ERROR `mut` must be attached to each individual binding
|
|
|
|
|
2019-08-27 13:04:48 +02:00
|
|
|
let mut mut x = 0;
|
|
|
|
//~^ ERROR `mut` on a binding may not be repeated
|
|
|
|
//~| remove the additional `mut`s
|
|
|
|
|
2024-11-28 01:35:36 +00:00
|
|
|
let mut mut mut mut mut x = 0;
|
|
|
|
//~^ ERROR `mut` on a binding may not be repeated
|
|
|
|
//~| remove the additional `mut`s
|
|
|
|
|
2015-01-08 21:54:35 +11:00
|
|
|
struct Foo { x: isize }
|
2019-08-18 22:54:07 +02:00
|
|
|
let mut Foo { x: x } = Foo { x: 3 };
|
2019-08-27 13:04:48 +02:00
|
|
|
//~^ ERROR `mut` must be attached to each individual binding
|
|
|
|
//~| add `mut` to each binding
|
|
|
|
|
|
|
|
let mut Foo { x } = Foo { x: 3 };
|
|
|
|
//~^ ERROR `mut` must be attached to each individual binding
|
|
|
|
//~| add `mut` to each binding
|
|
|
|
|
|
|
|
struct r#yield(u8, u8);
|
|
|
|
let mut mut yield(become, await) = r#yield(0, 0);
|
|
|
|
//~^ ERROR `mut` on a binding may not be repeated
|
2023-11-06 21:06:20 +00:00
|
|
|
//~| ERROR `mut` must be followed by a named binding
|
2019-08-27 13:04:48 +02:00
|
|
|
//~| ERROR expected identifier, found reserved keyword `yield`
|
|
|
|
//~| ERROR expected identifier, found reserved keyword `become`
|
2019-09-28 09:15:06 -07:00
|
|
|
//~| ERROR expected identifier, found keyword `await`
|
2019-08-27 13:04:48 +02:00
|
|
|
|
|
|
|
struct W<T, U>(T, U);
|
|
|
|
struct B { f: Box<u8> }
|
|
|
|
let mut W(mut a, W(b, W(ref c, W(d, B { box f }))))
|
|
|
|
//~^ ERROR `mut` must be attached to each individual binding
|
|
|
|
= W(0, W(1, W(2, W(3, B { f: Box::new(4u8) }))));
|
2019-08-27 19:51:21 +02:00
|
|
|
|
|
|
|
// Make sure we don't accidentally allow `mut $p` where `$p:pat`.
|
|
|
|
macro_rules! foo {
|
|
|
|
($p:pat) => {
|
Remove `NtPat`.
The one notable test change is `tests/ui/macros/trace_faulty_macros.rs`.
This commit removes the complicated `Interpolated` handling in
`expected_expression_found` that results in a longer error message. But
I think the new, shorter message is actually an improvement.
The original complaint was in #71039, when the error message started
with "error: expected expression, found `1 + 1`". That was confusing
because `1 + 1` is an expression. Other than that, the reporter said
"the whole error message is not too bad if you ignore the first line".
Subsequently, extra complexity and wording was added to the error
message. But I don't think the extra wording actually helps all that
much. In particular, it still says of the `1+1` that "this is expected
to be expression". This repeats the problem from the original complaint!
This commit removes the extra complexity, reverting to a simpler error
message. This is primarily because the traversal is a pain without
`Interpolated` tokens. Nonetheless, I think the error message is
*improved*. It now starts with "expected expression, found `pat`
metavariable", which is much clearer and the real problem. It also
doesn't say anything specific about `1+1`, which is good, because the
`1+1` isn't really relevant to the error -- it's the `$e:pat` that's
important.
2024-04-18 12:44:11 +10:00
|
|
|
let mut $p = 0; //~ ERROR expected identifier, found metavariable
|
2019-08-27 19:51:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
foo!(x);
|
2013-10-22 23:51:45 -04:00
|
|
|
}
|