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

Stabilize Ident::new_raw #59002

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ impl Ident {
}

/// Same as `Ident::new`, but creates a raw identifier (`r#ident`).
Copy link
Contributor

@petrochenkov petrochenkov Oct 26, 2019

Choose a reason for hiding this comment

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

One more line:

/// In addition to general identifier validity requirements, raw identifiers cannot be created for keywords usable in path segments (`self`, `super` and others).

Copy link
Contributor

Choose a reason for hiding this comment

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

That leaves me somewhat confused; what does "general identifier validity requirements" entail here? Surely Ident::new_raw has fewer restrictions than Ident::new_raw but your wording suggests it has more -- in particular, when will Ident::new_raw panic?

Copy link
Contributor

Choose a reason for hiding this comment

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

"general identifier validity requirements" -> "general identifier validity requirements inherited from Ident::new".
We can point to the reference or something that describes what is an identifier.

Surely Ident::new_raw has fewer restrictions than Ident::new_raw but your wording suggests it has more

It does have more restrictions.

in particular, when will Ident::new_raw panic?

"raw identifiers cannot be created for" -> "this function will panic on attempts to create"

Copy link
Contributor

Choose a reason for hiding this comment

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

It does have more restrictions.

Ah! $ident accepts keywords as well whereas it does not accept r#self -- that's pretty counter-intuitive. I think amending the documentation of fn new would be good as well to note the fact that keywords are allowed.

#[unstable(feature = "proc_macro_raw_ident", issue = "54723")]
#[stable(feature = "proc_macro_raw_ident", since = "1.34.0")]
pub fn new_raw(string: &str, span: Span) -> Ident {
Ident(bridge::client::Ident::new(string, span.0, true))
}
Expand Down