-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
r? compiler-errors |
I have a try on it, and it works. |
compiler/rustc_resolve/src/late.rs
Outdated
// 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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;
}
There was a problem hiding this 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.
This comment has been minimized.
This comment has been minimized.
Signed-off-by: xizheyin <[email protected]>
Signed-off-by: xizheyin <[email protected]>
There was a problem hiding this 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
.dcx() | ||
.emit_err(errors::UnderscoreLifetimeIsReserved { span: param.ident.span }); | ||
.create_err(errors::UnderscoreLifetimeIsReserved { span: param.ident.span }) | ||
.emit_unless(is_raw_underscore_lifetime); |
There was a problem hiding this comment.
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.
@bors r+ rollup |
Remove duplicate error about raw underscore lifetime Fixes rust-lang#143152 r? `@fee1-dead`
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
Remove duplicate error about raw underscore lifetime Fixes rust-lang#143152 r? ``@fee1-dead``
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
Fixes #143152
r? @fee1-dead