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

Wildcard imports do not seem to propagate as expected for tuple-like struct types having at least one non-pub field #53140

Closed
yvt opened this issue Aug 7, 2018 · 6 comments
Assignees
Labels
A-resolve Area: Path resolution E-help-wanted Call for participation: Help is requested to fix this issue. P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@yvt
Copy link
Contributor

yvt commented Aug 7, 2018

In the following code, ::mod1::Item is expected to be imported as ::mod1::mod2::Item via the following route:

  1. ::mod1::Item (the original definition)
  2. ::Item (by use self::mod1::* in the crate root)
  3. ::mod1::mod2::Item (by use Item in ::mod1::mod2)

However, an “unresolved import” error is reported for the last use as shown below:

#![allow(unused_imports)]

mod mod1 {
    mod mod2 {
        use Item;            // <--- Causes an "unresolved import" error
        // use ::Item;       // <--- So does this too
        // use super::super::Item;  // <--- This, three
        
        // use super::Item;  // <--- But not this one
    }
    
    pub struct Item(usize);
    
    // The "unresolved import" error no longer occurs if the above definition
    // was replaced with any one of the following:
    
    // pub struct Item(pub usize);
    // pub struct Item();
    // pub struct Item { x: usize }
}

use self::mod1::*; // `Item` is supposed to re-exported here

// Replacing the above `use` with the following one makes the error disappear
// use self::mod1::Item;

fn main() {
    let _: Option<Item> = None;
}

(Playground)

Errors:

   Compiling playground v0.0.1 (file:///playground)
error[E0432]: unresolved import
 --> src/main.rs:5:13
  |
5 |         use Item;            // <--- Causes an "unresolved import" error
  |             ^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

This issue can be reproduced in:

  • 1.30.0-nightly (73c7873 2018-08-05).
  • 1.29.0-beta.2 (ea82e08 2018-08-05).

But not in:

  • 1.28.0.
@petrochenkov petrochenkov self-assigned this Aug 7, 2018
@petrochenkov petrochenkov added A-resolve Area: Path resolution regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Aug 7, 2018
@petrochenkov
Copy link
Contributor

Very interesting.
Tuple struct constructors do have unusual properties - they are as public as the most private field, so use self::mod1::*; should import only the type Item, but not constructor.
However, it still shouldn't make use Item; an error, the type can still be imported.

It's interesting that the error happens only if use Item; is located inside of mod1:

mod mod1 {
    pub struct Item(usize);
    
    use Item as Something; // ERROR
}

use mod1::*;

mod mod2 {
    use Item; // OK
}

Perhaps bisection can find what commit caused the regression?

@petrochenkov petrochenkov added the E-help-wanted Call for participation: Help is requested to fix this issue. label Aug 8, 2018
@petrochenkov
Copy link
Contributor

petrochenkov commented Aug 8, 2018

Applying bisect-rust would be of great help here.
I won't be able to look at this issue in the next few weeks, but at least this part of the work can be delegated and when the reason is found I could probably mentor for the fix as well.

@Mark-Simulacrum
Copy link
Member

Mark-Simulacrum commented Aug 9, 2018

ef97813 is where the regression occurs with the minimized example; this is #52555. I've not bisected within the PR itself.

@nikomatsakis nikomatsakis added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. P-high High priority labels Aug 9, 2018
@nikomatsakis
Copy link
Contributor

Visiting for triage. Marking as P-high as this is a regression. @petrochenkov has already assigned themselves.

@Mark-Simulacrum Mark-Simulacrum added this to the 1.29 milestone Aug 9, 2018
@petrochenkov
Copy link
Contributor

Fixed in #53509

bors added a commit that referenced this issue Aug 22, 2018
resolve: Reject some inaccessible candidates sooner during import resolution

This allows import resolution to progress in cases like #53140

Fixes #53140
bors pushed a commit that referenced this issue Aug 25, 2018
…olution

This allows import resolution to progress in cases like #53140
yvt added a commit to yvt/ngspades that referenced this issue Apr 25, 2020
"Wildcard imports do not seem to propagate as expected for tuple-like
struct types having at least one non-pub field"
<rust-lang/rust#53140>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Path resolution E-help-wanted Call for participation: Help is requested to fix this issue. P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants