Skip to content

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

Closed
@mqudsi

Description

@mqudsi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions