Skip to content
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

See if Node::start_position and Node::end_position can be turned from Option<T> to just T #36

Open
Kampfkarren opened this issue Aug 22, 2019 · 5 comments
Labels
enhancement New feature or request

Comments

@Kampfkarren
Copy link
Owner

It feels really unergonomic to be unwrapping every single call.

@Kampfkarren Kampfkarren added the enhancement New feature or request label Aug 22, 2019
@Kampfkarren
Copy link
Owner Author

Trying to resolve this gives issues when dealing with Vec<T>--should it have a Node implementation in the first place?

Should Node be split in the same way PartialOrd/Ord are?

@Kampfkarren Kampfkarren added this to the 0.4.0 milestone Aug 29, 2019
@Kampfkarren
Copy link
Owner Author

The way syn does it (#23) is it exposes a Spanned trait which is implemented for everything that implements ToTokens.

While ToTokens is not implemented on Vec<T>, it is implemented on Option<T>. Not sure what it reports as its position when its None.

@tomprince
Copy link
Contributor

Looking at the implementation in proc_macro2, it looks like they have a dummy file, that is used for spans that aren't tied to a specific place.

@Kampfkarren
Copy link
Owner Author

That's strange, I wonder if that's actually better than Option! It's more ergonomic, but it feels like it would have the same problems as something like null.

@tomprince
Copy link
Contributor

I've not used it just looked at the code[1], but it gets represented as something like <unspecifed>:0:0. In syn`, one of the things spans gets used for is things like macro expansion, and saying where textually names are resolved, so it isn't entirely about tracking position information, so the tradeoffs might be different there.

That said, if you are doing code transforms, it might be useful to have a way to track in the ast whether a token came from user code, or was synthesized by the tool.

[1] I've only looked at the code when not being used as a proc-macro (i.e. the fallback code in proc-macro2), so the representation in the compile might be different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants