-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Emit a single error when importing a path with _
#142805
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
Conversation
rustbot has assigned @petrochenkov. Use |
@@ -711,6 +711,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { | |||
|
|||
let mut diag = struct_span_code_err!(self.dcx(), span, E0432, "{msg}"); | |||
|
|||
if errors.iter().all(|(_, err)| err.segment == Some(kw::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.
This leads to inconsistent behavior in code like use {_, a}
. I'd rather we filter out the errors mentioning _
like we're doing with that errors.retain
call above.
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.
And while we're at it, we probably should delay a bug in the:
if errors.is_empty() {
return;
}
on 691.
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.
Since this pr touches this test, could we also rename it with some more descriptive name and put a small comment with a link on an issue related to this instead?
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
0967071
to
7493828
Compare
_ => true, | ||
// If we've encountered something like `use _;`, we've already emitted an error stating | ||
// that `_` is not a valid identifier, so we silence the resolve error. | ||
_ => err.segment != Some(kw::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.
Could you split this out into two retain
calls? This is on the error path after all, and I think it's easier to understand since these two match arms have nothing to do with each other.
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.
ping
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.
Ah, you meant two retain calls, not two branches in the same match, gotcha
7493828
to
d944f9e
Compare
Please add a test for the case that I asked for:
|
When encountering `use _;`, `use _::*'` or similar, do not emit two errors for that single mistake. This also side-steps the issue of resolve errors suggesting adding a crate named `_` to `Cargo.toml`.
d944f9e
to
d82fb1e
Compare
@rustbot ready |
@bors r+ rollup |
…iler-errors Emit a single error when importing a path with `_` When encountering `use _;`, `use _::*'` or similar, do not emit two errors for that single mistake. This also side-steps the issue of resolve errors suggesting adding a crate named `_` to `Cargo.toml`. Fix rust-lang#142662.
Rollup of 9 pull requests Successful merges: - #142645 (Also emit suggestions for usages in the `non_upper_case_globals` lint) - #142657 (mbe: Clean up code with non-optional `NonterminalKind`) - #142799 (rustc_session: Add a structure for keeping both explicit and default sysroots) - #142805 (Emit a single error when importing a path with `_`) - #142882 (Lazy init diagnostics-only local_names in borrowck) - #142883 (Add impl_trait_in_bindings tests from #61773) - #142943 (Don't include current rustc version string in feature removed help) - #142965 ([RTE-497] Ignore `c-link-to-rust-va-list-fn` test on SGX platform) - #142972 (Add a missing mailmap entry) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #142805 - estebank:underscore-import, r=compiler-errors Emit a single error when importing a path with `_` When encountering `use _;`, `use _::*'` or similar, do not emit two errors for that single mistake. This also side-steps the issue of resolve errors suggesting adding a crate named `_` to `Cargo.toml`. Fix #142662.
When encountering
use _;
,use _::*'
or similar, do not emit two errors for that single mistake. This also side-steps the issue of resolve errors suggesting adding a crate named_
toCargo.toml
.Fix #142662.