-
Notifications
You must be signed in to change notification settings - Fork 115
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
Improve location of some compiler errors #257
Conversation
fn parse_assign_from_str<T>(input: ParseStream) -> Result<T> where T: Parse { | ||
input.parse::<Token![=]>()?; | ||
match Lit::parse(input)? { | ||
Lit::Str(string) => string.parse(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of failure, this will point inside the string, rather than after it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use crate::utils::{parse_attrs, parse_docs}; | ||
|
||
#[derive(Default)] | ||
pub struct FieldAttr { | ||
pub type_as: Option<String>, | ||
pub type_as: Option<Path>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This enables checking if the string contains valid syntax for a path
macros/src/types/named.rs
Outdated
@@ -93,11 +93,11 @@ fn format_field( | |||
} | |||
|
|||
if type_as.is_some() && type_override.is_some() { | |||
syn_err!("`type` is not compatible with `as`") | |||
syn_err!(field.ident.span(); "`type` is not compatible with `as`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite where I'd like the error to show up, but it's the best I could do, at least pointing the user at the correct field
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, love it! |
This PR improves where the compiler error points when there is an attribute error.
This errors now point at the exact location they should
#[ts(as = "...")]
attribute would point at the token after the string when receiving invalid path syntax#[ts(optional = nullable)]
would do the same when receiving anything other thannullable
Errors about incompatible attributes point at the entire field definition