Skip to content

rustc recommends a trait from a crate the current crate doesn't depend on #66562

Open
@joshtriplett

Description

@joshtriplett

I ran into this in a crate that depends directly on anyhow, and depends very indirectly on quick-error. When trying to use the context method, in a case that wouldn't work with anyhow because the error type didn't implement Error, rustc said:

help: the following trait is implemented but not in scope, perhaps add a `use` for it:
   |
1  | use quick_error::ResultExt;
   |

However, since the crate doesn't directly depend on quick-error, it can't add such a use.

Rough steps to reproduce:

  • Have a top-level binary crate that depends on library crates c1 and c2
  • Have crate c1 provide an extension trait with some requirements (such an extension trait on Result that places requirements on the error type).
  • Have crate c2 depend on crate c3.
  • Have crate c3 provide an extension trait that works on any type.
  • Have the top-level binary crate import the extension trait from c1, and attempt to use it, but not satisfy the required trait bounds.

This should result in rustc suggesting use c3::ExtensionTrait for use in the top-level binary crate, even though the top-level binary crate doesn't depend on c3.

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`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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