Skip to content

Commit 86bf700

Browse files
authored
Rollup merge of rust-lang#65123 - Centril:mac-invoc-in-mut-pat, r=estebank
Account for macro invocation in `let mut $pat` diagnostic. Fixes rust-lang#65122. r? @estebank
2 parents 0fb7740 + 5f94a53 commit 86bf700

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

src/libsyntax/parse/parser/pat.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
44
use crate::ptr::P;
55
use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac};
66
use crate::ast::{BindingMode, Ident, Mutability, Path, QSelf, Expr, ExprKind};
7-
use crate::mut_visit::{noop_visit_pat, MutVisitor};
7+
use crate::mut_visit::{noop_visit_pat, noop_visit_mac, MutVisitor};
88
use crate::parse::token::{self};
99
use crate::print::pprust;
1010
use crate::source_map::{respan, Span, Spanned};
@@ -481,6 +481,10 @@ impl<'a> Parser<'a> {
481481
fn make_all_value_bindings_mutable(pat: &mut P<Pat>) -> bool {
482482
struct AddMut(bool);
483483
impl MutVisitor for AddMut {
484+
fn visit_mac(&mut self, mac: &mut Mac) {
485+
noop_visit_mac(mac, self);
486+
}
487+
484488
fn visit_pat(&mut self, pat: &mut P<Pat>) {
485489
if let PatKind::Ident(BindingMode::ByValue(ref mut m @ Mutability::Immutable), ..)
486490
= pat.kind
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Regression test; used to ICE with 'visit_mac disabled by default' due to a
2+
// `MutVisitor` in `fn make_all_value_bindings_mutable` (`parse/parser/pat.rs`).
3+
4+
macro_rules! mac1 {
5+
($eval:expr) => {
6+
let mut $eval = ();
7+
//~^ ERROR `mut` must be followed by a named binding
8+
};
9+
}
10+
11+
macro_rules! mac2 {
12+
($eval:pat) => {
13+
let mut $eval = ();
14+
//~^ ERROR `mut` must be followed by a named binding
15+
//~| ERROR expected identifier, found `does_not_exist!()`
16+
};
17+
}
18+
19+
fn foo() {
20+
mac1! { does_not_exist!() }
21+
//~^ ERROR cannot find macro `does_not_exist` in this scope
22+
mac2! { does_not_exist!() }
23+
//~^ ERROR cannot find macro `does_not_exist` in this scope
24+
}
25+
26+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: `mut` must be followed by a named binding
2+
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:6:13
3+
|
4+
LL | let mut $eval = ();
5+
| ^^^^^^^^^ help: remove the `mut` prefix: `does_not_exist!()`
6+
...
7+
LL | mac1! { does_not_exist!() }
8+
| --------------------------- in this macro invocation
9+
|
10+
= note: `mut` may be followed by `variable` and `variable @ pattern`
11+
12+
error: expected identifier, found `does_not_exist!()`
13+
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:13:17
14+
|
15+
LL | let mut $eval = ();
16+
| ^^^^^ expected identifier
17+
...
18+
LL | mac2! { does_not_exist!() }
19+
| --------------------------- in this macro invocation
20+
21+
error: `mut` must be followed by a named binding
22+
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:13:13
23+
|
24+
LL | let mut $eval = ();
25+
| ^^^ help: remove the `mut` prefix: `does_not_exist!()`
26+
...
27+
LL | mac2! { does_not_exist!() }
28+
| --------------------------- in this macro invocation
29+
|
30+
= note: `mut` may be followed by `variable` and `variable @ pattern`
31+
32+
error: cannot find macro `does_not_exist` in this scope
33+
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:20:13
34+
|
35+
LL | mac1! { does_not_exist!() }
36+
| ^^^^^^^^^^^^^^
37+
38+
error: cannot find macro `does_not_exist` in this scope
39+
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:22:13
40+
|
41+
LL | mac2! { does_not_exist!() }
42+
| ^^^^^^^^^^^^^^
43+
44+
error: aborting due to 5 previous errors
45+

0 commit comments

Comments
 (0)