Skip to content

Remove duplicate error about raw underscore lifetime #143280

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

xizheyin
Copy link
Contributor

@xizheyin xizheyin commented Jul 1, 2025

Fixes #143152

r? @fee1-dead

@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 Jul 1, 2025
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Can you instead use tcx.sess.psess.raw_identifier_spans to look for the raw lifetime span? I think we populate raw_identifier_spans with raw lifetimes too.

If not, then I don't think this hack should land. Using span_to_snippet here seems fragile.

@compiler-errors
Copy link
Member

r? compiler-errors

@rustbot rustbot assigned compiler-errors and unassigned fee1-dead Jul 1, 2025
@xizheyin
Copy link
Contributor Author

xizheyin commented Jul 1, 2025

Can you instead use tcx.sess.psess.raw_identifier_spans to look for the raw lifetime span? I think we populate raw_identifier_spans with raw lifetimes too.

I have a try on it, and it works.

Comment on lines 2905 to 2914
// To avoid emitting two duplicate errors, we need to check if the span is a raw underscore lifetime, see issue #143152
let is_raw_underscore = self
.r
.tcx
.sess
.psess
.raw_identifier_spans
.iter()
.any(|span| span == param.span());
if param.ident.name == kw::UnderscoreLifetime && !is_raw_underscore {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm wondering if I should split it into 2 parts, as this doesn't seem very aesthetically pleasing taking up so many lines. However it seems to give the wrong impression that the variable in the middle will be used multiple times.

Copy link
Contributor Author

@xizheyin xizheyin left a comment

Choose a reason for hiding this comment

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

We may not be able to use emit_unless, because there are other logic in the if block.

                if param.ident.name == kw::UnderscoreLifetime && !is_raw_underscore {
                    self.r
                        .dcx()
                        .emit_err(errors::UnderscoreLifetimeIsReserved { span: param.ident.span });
                    // Record lifetime res, so lowering knows there is something fishy.
                    self.record_lifetime_param(param.id, LifetimeRes::Error);
                    continue;
                }

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

We may not be able to use emit_unless, because there are other logic in the if block.

Did you try it?

Just try calling self.record_lifetime_param(param.id, LifetimeRes::Error); unconditionally, it should be fine. We should definitely be delaying a bug.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 16, 2025
@rustbot

This comment has been minimized.

Copy link
Contributor Author

@xizheyin xizheyin left a comment

Choose a reason for hiding this comment

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

By the way, emit_unless doesn't seem intuitive and is very misleading, is it possible to give it a new name, e.g. emit_or_delay_as_bug

@rustbot ready

Comment on lines 2914 to +2916
.dcx()
.emit_err(errors::UnderscoreLifetimeIsReserved { span: param.ident.span });
.create_err(errors::UnderscoreLifetimeIsReserved { span: param.ident.span })
.emit_unless(is_raw_underscore_lifetime);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh my bad, the code now doesn't affect the original logic.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 17, 2025
@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 17, 2025

📌 Commit 848d4a5 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 17, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 18, 2025
Remove duplicate error about raw underscore lifetime

Fixes rust-lang#143152

r? `@fee1-dead`
bors added a commit that referenced this pull request Jul 18, 2025
Rollup of 12 pull requests

Successful merges:

 - #142300 (Disable `tests/run-make/mte-ffi` because no CI runners have MTE extensions enabled)
 - #143271 (Store the type of each GVN value)
 - #143280 (Remove duplicate error about raw underscore lifetime)
 - #143649 (Add test for `default_field_values` and `const_default`)
 - #143699 (Make `AsyncDrop` check that it's being implemented on a local ADT)
 - #143719 (Emit warning when there is no space between `-o` and arg)
 - #143833 (Ban projecting into SIMD types [MCP838])
 - #143891 (Port `#[coverage]` to the new attribute system)
 - #143908 (`tests/ui`: A New Order [0/28] )
 - #143909 (docs(alloc::fmt): Make type optional, instead of matching empty string)
 - #143925 (Make slice comparisons const)
 - #143997 (Use $crate in macros for rustc_public (aka stable_mir))

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 18, 2025
Remove duplicate error about raw underscore lifetime

Fixes rust-lang#143152

r? ``@fee1-dead``
bors added a commit that referenced this pull request Jul 18, 2025
Rollup of 12 pull requests

Successful merges:

 - #143280 (Remove duplicate error about raw underscore lifetime)
 - #143649 (Add test for `default_field_values` and `const_default`)
 - #143699 (Make `AsyncDrop` check that it's being implemented on a local ADT)
 - #143704 (Be a bit more careful around exotic cycles in in the inliner)
 - #143908 (`tests/ui`: A New Order [0/28] )
 - #143909 (docs(alloc::fmt): Make type optional, instead of matching empty string)
 - #143925 (Make slice comparisons const)
 - #143997 (Use $crate in macros for rustc_public (aka stable_mir))
 - #144013 (resolve: Make disambiguators for underscore bindings module-local)
 - #144029 (Fix wrong messages from methods with the same name from different traits)
 - #144063 (Add myself to the `infra-ci` reviewer group and adjust some infra auto-labels)
 - #144069 (ci: use windows 22 for all free runners)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

'r#_ gives two confusingly similar errors
5 participants