Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for macro invocation in let mut $pat diagnostic. #65123

Merged
merged 1 commit into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Centril marked this conversation as resolved.
Show resolved Hide resolved
// `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