Skip to content

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

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

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Jun 20, 2025

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.

estebank added 2 commits June 20, 2025 19:21
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`.
@rustbot
Copy link
Collaborator

rustbot commented Jun 20, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
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 Jun 20, 2025
@@ -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)) {
Copy link
Member

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.

Copy link
Member

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.

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.

Leading underscore in path makes rust suggest to add a crate named _ with edition >= 2018
4 participants