Skip to content

Commit

Permalink
Include failed raw identifier in panic message
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 20, 2020
1 parent 9e9cae1 commit 6a67750
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/runtime.rs
Expand Up @@ -345,19 +345,15 @@ pub fn mk_ident(id: &str, span: Option<Span>) -> Ident {
//
// FIXME: When `Ident::new_raw` becomes stable, this method should be
// updated to call it when available.
match id.parse::<TokenStream>() {
Ok(ts) => {
let mut iter = ts.into_iter();
match (iter.next(), iter.next()) {
(Some(TokenTree::Ident(mut id)), None) => {
id.set_span(span);
id
}
_ => unreachable!("valid raw ident fails to parse"),
}
if let Ok(ts) = id.parse::<TokenStream>() {
let mut iter = ts.into_iter();
if let (Some(TokenTree::Ident(mut id)), None) = (iter.next(), iter.next()) {
id.set_span(span);
return id;
}
Err(_) => unreachable!("valid raw ident fails to parse"),
}

panic!("not allowed as a raw identifier: `{}`", id);
}

// Adapts from `IdentFragment` to `fmt::Display` for use by the `format_ident!`
Expand Down

0 comments on commit 6a67750

Please sign in to comment.