-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
proc_macro support for reading files/strings to spanned TokenStream #55904
Comments
Agreed this would be a good idea to have! I don't know quite the shape that it should take, but it's something we'll want eventually |
I think that implementing a #[proc_macro_include]
fn include_file(path: &Path) -> TokenStream Erros (for example, file not existing) would be handled by panicking in the same way as they are handled for standard I'm fairly new to this repo, but as far as I have understood there should be nothing significant holding this back. |
Is there any progress done on this one? |
Hi @oddcoder, sorry for the late answer but lately my work kept me fairly busy and pretty far from Rust, unfortunately. Feel fre to pick up this issue if you want to, I did never manage to reach anything useful. |
@rustbot claim |
Triage: Hi, are you still working on this issue @oddcoder? |
ops sorry, I got stuck at some point, then got carried away with my still ongoing exams. |
No worries, good luck with the exams. Please claim the issue again if you want to work on it in the future @rustbot release-assignment |
It would be great if it's possible to create a spanned Would this be something worth to contribute or are there other experimental concepts which will make this obsolete? fn lex_file(path: &Path) -> io::Result<TokenStream>; |
rust-lang/rfcs#3200 aims to address this, and as the author of the RFC I obviously believe that API to be a near-optimal shape. (The RFC isn't crosslinked yet, so adding such.) |
Currently, as far as I am aware, there is no way to get spans for tokens parsed from a source other than the macro's callsite, and no good way to tell rustc & cargo a procedural macro depends on another file. It would be nice for macros which want to load other files to enable this.
It'd be nice to support some mechanism for loading a file as a
TokenStream
. Ideally this would take the form of a method in the crate directly parsing a file / string to aTokenStream
. For example:A function to load a file as a
TokenStream
with accurate span info etc, e.g.A function to parse a string with a given filename. This might need an additional mechanism to register the source file as a dependency, e.g.
To make it generally useful & able to implement something like
include!()
we'd probably also want/need something like #54725 to get the file to load relative to.The text was updated successfully, but these errors were encountered: