udoprog / genco

A whitespace-aware quasiquoter for beautiful code generation.
Apache License 2.0
176 stars 11 forks source link

support behaving like stable in nightly #45

Open ajwerner opened 9 months ago

ajwerner commented 9 months ago

The documentation makes clear that nightly and stable behave differently because of functionality offered in nightly that is not in stable. This is a pain if you want to deterministically produce the same output in both and are getting by in stable by sprinkling $['\n'] where needed.

It'd be nice if there was some way to tell the crate to pretend it doesn't have access to this functionality. This probably is not a perfect fit for features because they are supposed to be additive. Another option might be to release another copy of the crate which always behaves like the stable via some config attr; I don't think this would be too hard. In particular you could just have a slightly different cargo toml.

To make the problem concrete, the challenge I currently am having is that when I have comments inside quote macro, they become a single newline in nightly that doesn't exist in stable.

I do get the pain of not having the API you need. Thank you for working around it in the ways that you have.

udoprog commented 9 months ago

I'm not entirely sure how to design this either, but I'll mark it as an enhancement for now.

Thanks for the input!

tamird commented 9 months ago

One way to do this is to invert the detection behavior and use a feature instead of a cfg. In other words have a feature that gets enabled on stable unconditionally but also allow users to enable it explicitly.

udoprog commented 9 months ago

I suppose that begs the question, do you want it to be a runtime or compile-time opt-in?

I imagined it would be something you might want to opt in for at runtime, for which the feature might look something like:

let mut tokens = Tokens::without_spans();
quote_in! { tokens => hello world };