Fix span placement on ForeignName parse error

This commit is contained in:
David Tolnay 2021-01-01 19:28:34 -08:00
parent 43d8e4295d
commit 1d5ffbb4c9
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -3,7 +3,7 @@ use crate::syntax::{Lifetimes, NamedType, Pair, Symbol};
use proc_macro2::{Ident, Span};
use std::fmt::{self, Display};
use std::iter;
use syn::parse::Result;
use syn::parse::{Error, Result};
use syn::punctuated::Punctuated;
#[derive(Clone)]
@ -53,9 +53,13 @@ impl ForeignName {
pub fn parse(text: &str, span: Span) -> Result<Self> {
// TODO: support C++ names containing whitespace (`unsigned int`) or
// non-alphanumeric characters (`operator++`).
let ident: Ident = syn::parse_str(text)?;
let text = ident.to_string();
Ok(ForeignName { text, span })
match syn::parse_str::<Ident>(text) {
Ok(ident) => {
let text = ident.to_string();
Ok(ForeignName { text, span })
}
Err(err) => Err(Error::new(span, err)),
}
}
}