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

Preserve original formatting when rending default expressions in docs with Span::source_text #187

Open
Veetaha opened this issue Nov 9, 2024 · 1 comment
Labels
blocked Progress on the issue is blocked by some external factors feature request A new feature is requested

Comments

@Veetaha
Copy link
Contributor

Veetaha commented Nov 9, 2024

A note for the community from the maintainers

Please vote on this issue by adding a 👍 reaction to help the maintainers with prioritizing it. You may add a comment describing your real use case related to this issue for us to better understand the problem domain.

@Veetaha Veetaha added the feature request A new feature is requested label Nov 10, 2024
@Veetaha
Copy link
Contributor Author

Veetaha commented Nov 10, 2024

I tried using Span::source_text() to get the original source code of the default expression, but it always returns the span of the first token instead. The span() implementation of syn::Expr does the following:

  1. Convert syn::Expr into a TokenStream
  2. Join all spans in the TokenStream with join_spans
  3. join_spans, in turn calls proc_macro2::Span::join(), but it only works on nightly.

So there is no good way to obtain the original source code with the original formatting currently on stable (rust-lang/rust#54725).

@Veetaha Veetaha added the blocked Progress on the issue is blocked by some external factors label Nov 10, 2024
@Veetaha Veetaha changed the title Use Span::source_text in docs rendering to preserve original formatting Preserve original formatting when rending default expressions in docs with Span::source_text Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Progress on the issue is blocked by some external factors feature request A new feature is requested
Projects
None yet
Development

No branches or pull requests

1 participant