Skip to content
Merged
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
30 changes: 15 additions & 15 deletions src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ fn check_matcher_core(sess: &ParseSess,
continue 'each_last;
}
IsInFollow::Yes => {}
IsInFollow::No(ref possible) => {
IsInFollow::No(possible) => {
let may_be = if last.tokens.len() == 1 &&
suffix_first.tokens.len() == 1
{
Expand All @@ -933,7 +933,7 @@ fn check_matcher_core(sess: &ParseSess,
format!("not allowed after `{}` fragments", frag_spec),
);
let msg = "allowed there are: ";
match &possible[..] {
match possible {
&[] => {}
&[t] => {
err.note(&format!(
Expand Down Expand Up @@ -997,7 +997,7 @@ fn frag_can_be_followed_by_any(frag: &str) -> bool {

enum IsInFollow {
Yes,
No(Vec<&'static str>),
No(&'static [&'static str]),
Invalid(String, &'static str),
}

Expand Down Expand Up @@ -1029,28 +1029,28 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> IsInFollow {
IsInFollow::Yes
},
"stmt" | "expr" => {
let tokens = vec!["`=>`", "`,`", "`;`"];
const TOKENS: &[&str] = &["`=>`", "`,`", "`;`"];
match tok {
TokenTree::Token(token) => match token.kind {
FatArrow | Comma | Semi => IsInFollow::Yes,
_ => IsInFollow::No(tokens),
_ => IsInFollow::No(TOKENS),
},
_ => IsInFollow::No(tokens),
_ => IsInFollow::No(TOKENS),
}
},
"pat" => {
let tokens = vec!["`=>`", "`,`", "`=`", "`|`", "`if`", "`in`"];
const TOKENS: &[&str] = &["`=>`", "`,`", "`=`", "`|`", "`if`", "`in`"];
match tok {
TokenTree::Token(token) => match token.kind {
FatArrow | Comma | Eq | BinOp(token::Or) => IsInFollow::Yes,
Ident(name, false) if name == kw::If || name == kw::In => IsInFollow::Yes,
_ => IsInFollow::No(tokens),
_ => IsInFollow::No(TOKENS),
},
_ => IsInFollow::No(tokens),
_ => IsInFollow::No(TOKENS),
}
},
"path" | "ty" => {
let tokens = vec![
const TOKENS: &[&str] = &[
"`{`", "`[`", "`=>`", "`,`", "`>`","`=`", "`:`", "`;`", "`|`", "`as`",
"`where`",
];
Expand All @@ -1062,11 +1062,11 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> IsInFollow {
BinOp(token::Or) => IsInFollow::Yes,
Ident(name, false) if name == kw::As ||
name == kw::Where => IsInFollow::Yes,
_ => IsInFollow::No(tokens),
_ => IsInFollow::No(TOKENS),
},
TokenTree::MetaVarDecl(_, _, frag) if frag.name == sym::block =>
IsInFollow::Yes,
_ => IsInFollow::No(tokens),
_ => IsInFollow::No(TOKENS),
}
},
"ident" | "lifetime" => {
Expand All @@ -1084,22 +1084,22 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> IsInFollow {
},
"vis" => {
// Explicitly disallow `priv`, on the off chance it comes back.
let tokens = vec!["`,`", "an ident", "a type"];
const TOKENS: &[&str] = &["`,`", "an ident", "a type"];
match tok {
TokenTree::Token(token) => match token.kind {
Comma => IsInFollow::Yes,
Ident(name, is_raw) if is_raw || name != kw::Priv => IsInFollow::Yes,
_ => if token.can_begin_type() {
IsInFollow::Yes
} else {
IsInFollow::No(tokens)
IsInFollow::No(TOKENS)
}
},
TokenTree::MetaVarDecl(_, _, frag) if frag.name == sym::ident
|| frag.name == sym::ty
|| frag.name == sym::path =>
IsInFollow::Yes,
_ => IsInFollow::No(tokens),
_ => IsInFollow::No(TOKENS),
}
},
"" => IsInFollow::Yes, // kw::Invalid
Expand Down