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

Compile time lowercasing/etc of stringify!d idents. #16607

Closed
Manishearth opened this issue Aug 19, 2014 · 6 comments
Closed

Compile time lowercasing/etc of stringify!d idents. #16607

Manishearth opened this issue Aug 19, 2014 · 6 comments

Comments

@Manishearth
Copy link
Member

In this macro for Servo (PR), I'm taking in an ident, using it as a method name, and later stringify!ing it. Unfortunately, the method name needs to be title case, but the string version needs to be lowercase. I currently get around this by using stringify!($attr).to_ascii_lower().as_slice() but this executes at runtime which is slightly inefficient.

Could we have variants of stringify! that work at compile time?

@Manishearth Manishearth changed the title Compile time lowercasing of stringify!d idents. Compile time lowercasing/etc of stringify!d idents. Aug 19, 2014
@Manishearth
Copy link
Member Author

I'm willing to work on this myself, it should be easy enough to add a stringify_lower! and stringify_upper!, or whatever else we need here and here

@SimonSapin
Copy link
Contributor

Rather than special-purpose macros like stringify_lower!(), it may be preferable to have simpler but composable macros: to_ascii_lower!(stringify!()) so that we don’t have to anticipate all possible combinations.

@kmcallister
Copy link
Contributor

We would also use this in the compiler's lint_initializer! macro instead of calling to_ascii_lower.

@Manishearth
Copy link
Member Author

Ah, nice. I'll do that then.

to_ascii_lower!, to_ascii_upper! should be enough, right? Any other macros we may want? I'll try my hand at this tomorrow.

@steveklabnik
Copy link
Member

Adding macros would require an RFC nowadays, so I'm giving this a close.

@kmcallister
Copy link
Contributor

Yeah, I think this could be a plugin library.

bors added a commit to rust-lang-ci/rust that referenced this issue Feb 25, 2024
…cape-left-curly, r=Veykril

fix: Don't add `\` before `{`

Fixes rust-lang#16607 for `{`. The `}` case is already fixed by rust-lang#16475.

The [LSP snippet grammar](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#snippet_syntax) only specifies that `$`, `}`, and `\` can be escaped with backslashes, but not `{`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants