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

Support non-string-literal wrapped paths #2862

Open
Nemo157 opened this issue Nov 27, 2024 · 3 comments
Open

Support non-string-literal wrapped paths #2862

Nemo157 opened this issue Nov 27, 2024 · 3 comments

Comments

@Nemo157
Copy link

Nemo157 commented Nov 27, 2024

The current path-taking attributes like #[serde(crate = ...)] require the path to be wrapped in a string literal. I believe this is due to a limitation in older versions of the compiler, but it's possible to pass paths in directly now.

This causes issues when trying to use paths like #[serde(crate = $crate::reexports::serde)], the $crate token cannot be serialized through a string.

I think it would be backwards compatible to extend these attributes to parse either a string literal or a directly passed path to support these kinds of usecases.

@Nemo157
Copy link
Author

Nemo157 commented Nov 27, 2024

Looking back at the original implementation (#1499) I see there was some discussion about workarounds like:

use $crate::reexports::serde as _serde;
...
#[serde(crate = "_serde")]

But it would be nice if these weren't needed.

@oli-obk
Copy link
Member

oli-obk commented Nov 27, 2024

Hmm... would this require serde_derive to be compiler-version dependent, too? We can either have a one-time cost of a build script, or a cost at every invocation, but if we can just accept paths without first needing to check the rust version, that would be ok.

@Nemo157
Copy link
Author

Nemo157 commented Nov 27, 2024

I have the feeling that it shouldn't require any version dependence (but I've not tried this sort of code on old compilers). For old compilers it's just not possible to have non-literal tokens in this position, so attempting to parse as a path will always fail, but there's nothing stopping you from trying that parse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants