Skip to content
Permalink
Browse files

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

  • Loading branch information...
Centril committed Oct 5, 2019
1 parent 7870050 commit 5f94a53d1a4e03787886b8bca750566d80255f85
@@ -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};
@@ -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
@@ -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() {}
@@ -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 5f94a53

Please sign in to comment.
You can’t perform that action at this time.