Skip to content

Make Name hold escaped name #12993

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

Merged
merged 5 commits into from
Aug 12, 2022

Conversation

lowr
Copy link
Contributor

@lowr lowr commented Aug 10, 2022

Resolves #12787
Resolves rust-lang/rust#99361

This PR effectively swaps Name and EscapedName in hir. In other words, it makes Name hold and print escaped raw identifiers and introduces another struct UnescapedName for cases where you need to print names without "r#" prefix.

My rationale is that it makes it easier for us to format an escaped name into string, which is what we want when we serialize names in general. This is because we format a name into string usually when we are presenting it to the users and arguably they expect its escaped form as that's what they see and write in the source code.

I split the change for Name into 3 commits to make it easier to follow but it also made some tests fail in the intermediate commits. I can squash them into a commit after the review if desired. I've also made similar changes for ModPath and EscapedModPath as it makes them consistent with Name.

For reference, there was a brief discussion on this in a zulip thread.

Comment on lines +2235 to +2267
mod r#mod {
#[test]
fn r#fn() {}

/// ```
/// ```
fn r#for() {}

/// ```
/// ```
struct r#struct<r#type>(r#type);

/// ```
/// ```
impl<r#type> r#struct<r#type> {
/// ```
/// ```
fn r#fn() {}
}

enum r#enum {}
impl r#struct<r#enum> {
/// ```
/// ```
fn r#fn() {}
}

trait r#trait {}

/// ```
/// ```
impl<T> r#trait for r#struct<T> {}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is by far the best Rust code I've ever written.

@Veykril
Copy link
Member

Veykril commented Aug 12, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Aug 12, 2022

📌 Commit ba6db3e has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 12, 2022

⌛ Testing commit ba6db3e with merge cee1e15...

@bors
Copy link
Contributor

bors commented Aug 12, 2022

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing cee1e15 to master...

@bors bors merged commit cee1e15 into rust-lang:master Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants