Warn that trait implementation is gated by a feature flag #87717
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given the following code: (Playground link not provided because this involves a crate not on playground)
The current output is:
Ideally the output should look like:
I was trying to call

par_iter()
on the following example, but was very confused with regards to the error message. Consider the following image, snapshotted from thedashmap::DashSet
docs:It looks like
Foo
satisfies all the trait bounds needed forDashSet<Foo>
to fufillInterParallelIterator
, yet the trait still isn't being satisfied! What's going on? The solution is a case of either confusing docs.rs or a perhaps unintuitive diagnostic: a missing feature flag (in this case,rayon
).As a quick concept, I would suggest a note indicating that the trait implementation does exist for a struct but isn't enabled because the feature isn't enabled. As a layman on the rustc internals, I'm not sure how feasible this would be, but something like the following might be viable:
Trait
,Foo
from cratecrate
implementsTrait
regardless of enabled features,Trait
implementation or its parent mods is enabled through a feature, and that feature isn't enabled,Trait
is not satisfied because the trait implementation is gated by a feature flag.I think this is worthwhile to implement, as I believe this is incredibly confusing to new Rust users. The compiler and docs make no indication that a trait implementation is gated, which means that a new user would be absolutely lost on next steps.
Heck, I would consider myself an intermediate or even an advanced user, and had to ask the community for help.
The text was updated successfully, but these errors were encountered: