-
-
Notifications
You must be signed in to change notification settings - Fork 318
Inherited visibility has a misleading location #780
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
Comments
Rust associates spans only with tokens; every token has a span. If there isn't a token somewhere, there isn't a span that can represent the place where the token isn't. |
I'll close this because I don't expect to diverge from the proc macro model on this. For calculating the span without attributes, you should be able to use: |
Thanks 👍 I will try some workaround.
Hm, OK, but by introducing an |
|
Sure, but even if there is no span for Anyway, after looking a bit how it is implemented under the hood, I realize now what you're saying. There's no easy way to have a custom, fake |
More generally, whether or not ToTokens is involved in the current implementation, it's that there isn't any token to identify the place where the token isn't. pub enum Visibility {
...
Inherited,
}
impl Visibility {
pub fn span(&self) -> Span {
match self {
...
Visibility::Inherited => ???
}
}
} |
Out of curiosity, what's the reason to have an empty variant instead of |
Because it's always what you want. I don't know of any syntax that would want to parse a visibility but not allow the empty visibility. |
By the way, compiler explicitly claims to parse |
Not sure if this is a bug or a feature, but it surprised me while trying to calculate the "real span" of some items (as in "the span of this item ignoring its attributes").
Test case
Output:
I would expect... maybe an empty span just before the
extern_token
?The text was updated successfully, but these errors were encountered: