mirror of
https://gitee.com/openharmony/third_party_rust_quote
synced 2024-11-23 15:19:40 +00:00
Merge pull request #175 from dtolnay/ident
Include failed raw identifier in panic message
This commit is contained in:
commit
df96ce81d6
@ -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!`
|
||||
|
Loading…
Reference in New Issue
Block a user