Skip to content

compiler suggests use of private trait; fails to suggest the public one. #26454

Closed
@pnkfelix

Description

@pnkfelix

When I do try!(file.metadata()).mtime() without MetadataExt in scope, the compiler suggests that I import std::sys::ext::fs::MetadataExt. It does not suggest any other candidates:

<anon>:17:15: 17:22 help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
<anon>:17:15: 17:22 help: candidate #1: use `std::sys::ext::fs::MetadataExt`
error: aborting due to previous error

But that trait is private, so a use of it will not work.

It turns out that I can do use std::os::unix::fs::MetadataExt; (which I assume is an alternative path to the same trait), and that path is publicly accessible.

playpen demo: https://play.rust-lang.org/?gist=557a8c49fbf072db1033&version=nightly

(This is related to #25358 but is not a dupe of it; that bug is about the suggestion of traits to implement, while this bug is about the suggestion of traits to pull into scope via use)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.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