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

Use of private traits or types that would have been imported returns wrong error message #43261

Closed
mqudsi opened this issue Jul 16, 2017 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@mqudsi
Copy link
Contributor

mqudsi commented Jul 16, 2017

When using a trait that would have been imported via * except it is not declared pub, the suggestion from rustc is to import the type.

testcase.rs:

fn main() {
    use testmodule::*;

    let foo = Foo {};
    foo.hello();
}

pub mod testmodule {
    struct Foo {
    }

    trait Bar {
        fn hello() -> &'static str;
    }

    impl Bar for Foo {
        fn hello() -> &'static str {
            return "Hiya, stranger!";
        }
    }
}

Compiling returns this error:

error[E0422]: cannot find struct, variant or union type `Foo` in this scope
 --> testcase.rs:4:15
  |
4 |     let foo = Foo {};
  |               ^^^ not found in this scope
  |
  = help: possible candidate is found in another module, you can import it into scope:
            `use testmodule::Foo;`

error: aborting due to previous error

But the type can't be imported because it's private (and if it weren't, it would have already been imported).

The same error exists when calling a trait that is defined in a private type.

@Mark-Simulacrum Mark-Simulacrum added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 19, 2017
@Mark-Simulacrum
Copy link
Member

Closing in favor of #6477.

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
Projects
None yet
Development

No branches or pull requests

2 participants