Skip to content

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

Closed
@obi1kenobi

Description

@obi1kenobi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions