Skip to content
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

Suggestion to import item via pub use X as _ re-export, which doesn't work #116164

Closed
obi1kenobi opened this issue Sep 26, 2023 · 0 comments · Fixed by #116228
Closed

Suggestion to import item via pub use X as _ re-export, which doesn't work #116164

obi1kenobi opened this issue Sep 26, 2023 · 0 comments · Fixed by #116228
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@obi1kenobi
Copy link
Member

obi1kenobi commented Sep 26, 2023

Code

#![allow(unused_imports)]

mod inner {
    pub enum Example {
        ExOne,
        ExTwo,
    }
}

mod reexports {
    pub use crate::inner::{
        Example as _,
    };
}

use crate::reexports::*;

fn check() {
    ExOne;
}

Current output

error[E0425]: cannot find value `ExOne` in this scope
  --> src/lib.rs:19:5
   |
19 |     ExOne;
   |     ^^^^^ not found in this scope
   |
help: consider importing this unit variant
   |
16 + use crate::_::ExOne;
   |

For more information about this error, try `rustc --explain E0425`.

Desired output

error[E0425]: cannot find value `ExOne` in this scope
  --> src/lib.rs:19:5
   |
19 |     ExOne;
   |     ^^^^^ not found in this scope
   |
help: consider importing this unit variant
   |
16 + use crate::inner::ExOne;
   |

For more information about this error, try `rustc --explain E0425`.

Rationale and extra context

The suggested fix doesn't work, since _ is a reserved identifier and items may not be imported through it:

error: expected identifier, found reserved identifier `_`
 --> src/lib.rs:1:12
  |
1 | use crate::_::ExOne;
  |            ^ expected identifier, found reserved identifier

The appropriate suggestion is to import the item via a valid path.

Other cases

No response

Anything else?

Playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=013d5f59846dad0ae3add3c12d24c755

Came up as a result of triaging: obi1kenobi/cargo-semver-checks#536

@obi1kenobi obi1kenobi added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 26, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 26, 2023
@estebank estebank added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 26, 2023
@bors bors closed this as completed in 16b7b39 Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants