Skip to content

print raw lifetime idents with r# #144897

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Aug 4, 2025

This replaces #143185 and fixes #143150

cc @fmease

@rustbot
Copy link
Collaborator

rustbot commented Aug 4, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 4, 2025

This PR modifies tests/ui/issues/. If this PR is adding new tests to tests/ui/issues/,
please refrain from doing so, and instead add it to more descriptive subdirectories.

Comment on lines 2508 to 2512
if let Some(ident) = self.as_raw_lifetime_name_without_apostrophe() {
write!(f, "'{}", IdentPrinter::new(ident.name, true, None))
} else {
fmt::Display::fmt(&IdentPrinter::new(self.name, self.is_raw_guess(), None), f)
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this not a change in IdentPrinter instead?

Copy link
Member Author

@fee1-dead fee1-dead Aug 4, 2025

Choose a reason for hiding this comment

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

How do you propose us to make the check in IdentPrinter? It doesn't know about editions because it only accepts the symbol. is_raw_guess and as_raw_lifetime_name_without_apostrophe both need the span edition to know whether some identifier is treated as a keyword or not.

Copy link
Member

Choose a reason for hiding this comment

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

I suppose it could accept edition as a parameter? otherwise I'm not sure what's even the point of it

Copy link
Member Author

Choose a reason for hiding this comment

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

otherwise I'm not sure what's even the point of it

Just looked at the code again. IdentPrinter is used from two general places. One where one has the token data (sorta at the parsing/ast/proc macro stage) in which rawness of idents are known and do not need to be guessed, and one at a later stage where they do. that's why rawness was originally passed as a bool. To improve the design as you highlighted I chose to change the original bool into an enum, but we still have to guess whether a raw lifetime should be printed here and not inside IdentPrinter.

@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead force-pushed the raw_lifetimes_printing branch 2 times, most recently from 5805f0a to 9705706 Compare August 4, 2025 13:35
|
help: consider introducing lifetime `'r#fn` here
|
LL | fn a<'fn>(_: dyn Trait + 'r#fn) {
Copy link
Member

@fmease fmease Aug 4, 2025

Choose a reason for hiding this comment

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

It doesn't actually sugg 'r#fn here and one and two below

Copy link
Member Author

@fee1-dead fee1-dead Aug 4, 2025

Choose a reason for hiding this comment

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

uh.... that must have changed between my blesses or smth. Will take a look

@fee1-dead fee1-dead force-pushed the raw_lifetimes_printing branch from 9705706 to b74a97e Compare August 4, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undeclared raw lifetime; "consider introducing non-raw lifetime"
6 participants