Skip to content

Commit

Permalink
Rollup merge of rust-lang#65123 - Centril:mac-invoc-in-mut-pat, r=est…
Browse files Browse the repository at this point in the history
…ebank

Account for macro invocation in `let mut $pat` diagnostic.

Fixes rust-lang#65122.

r? @estebank
  • Loading branch information
tmandry authored Oct 5, 2019
2 parents 0fb7740 + 5f94a53 commit 86bf700
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libsyntax/parse/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
use crate::ptr::P;
use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac};
use crate::ast::{BindingMode, Ident, Mutability, Path, QSelf, Expr, ExprKind};
use crate::mut_visit::{noop_visit_pat, MutVisitor};
use crate::mut_visit::{noop_visit_pat, noop_visit_mac, MutVisitor};
use crate::parse::token::{self};
use crate::print::pprust;
use crate::source_map::{respan, Span, Spanned};
Expand Down Expand Up @@ -481,6 +481,10 @@ impl<'a> Parser<'a> {
fn make_all_value_bindings_mutable(pat: &mut P<Pat>) -> bool {
struct AddMut(bool);
impl MutVisitor for AddMut {
fn visit_mac(&mut self, mac: &mut Mac) {
noop_visit_mac(mac, self);
}

fn visit_pat(&mut self, pat: &mut P<Pat>) {
if let PatKind::Ident(BindingMode::ByValue(ref mut m @ Mutability::Immutable), ..)
= pat.kind
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/parser/issue-65122-mac-invoc-in-mut-patterns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Regression test; used to ICE with 'visit_mac disabled by default' due to a
// `MutVisitor` in `fn make_all_value_bindings_mutable` (`parse/parser/pat.rs`).

macro_rules! mac1 {
($eval:expr) => {
let mut $eval = ();
//~^ ERROR `mut` must be followed by a named binding
};
}

macro_rules! mac2 {
($eval:pat) => {
let mut $eval = ();
//~^ ERROR `mut` must be followed by a named binding
//~| ERROR expected identifier, found `does_not_exist!()`
};
}

fn foo() {
mac1! { does_not_exist!() }
//~^ ERROR cannot find macro `does_not_exist` in this scope
mac2! { does_not_exist!() }
//~^ ERROR cannot find macro `does_not_exist` in this scope
}

fn main() {}
45 changes: 45 additions & 0 deletions src/test/ui/parser/issue-65122-mac-invoc-in-mut-patterns.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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!()`
...
LL | mac1! { does_not_exist!() }
| --------------------------- in this macro invocation
|
= note: `mut` may be followed by `variable` and `variable @ pattern`

error: expected identifier, found `does_not_exist!()`
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:13:17
|
LL | let mut $eval = ();
| ^^^^^ expected identifier
...
LL | mac2! { does_not_exist!() }
| --------------------------- in this macro invocation

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!()`
...
LL | mac2! { does_not_exist!() }
| --------------------------- in this macro invocation
|
= note: `mut` may be followed by `variable` and `variable @ pattern`

error: cannot find macro `does_not_exist` in this scope
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:20:13
|
LL | mac1! { does_not_exist!() }
| ^^^^^^^^^^^^^^

error: cannot find macro `does_not_exist` in this scope
--> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:22:13
|
LL | mac2! { does_not_exist!() }
| ^^^^^^^^^^^^^^

error: aborting due to 5 previous errors

0 comments on commit 86bf700

Please sign in to comment.