Methods behind a feature gate are still visible to the compiler even when the feature is not on #28126
Labels
A-stability
Area: `#[stable]`, `#[unstable]` etc.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
When a new trait method is found behind a feature gate (such as the
read_exact
method ofio::Read
, which is behind the correspondingly named feature)rustc
will see the method in scope even if the feature has not been explicitly turned on for the crate.This causes a problem when a different trait has a method with the same name as the newly added one. I would expect that
rustc
should not even "see" the method in scope if it has not been explicitly asked for by flipping the feature gate?The following code snippet demonstrates the issue on the current nightly (
rustc 1.4.0-nightly (fe9cef7da 2015-08-30)
).The compiler would say that there are multiple applicable items in scope for the
read_exact
method (the one fromMyExt
and the one fromio::Read
), but the method onio::Read
is not really applicable in this case -- it would require#![feature(read_exact)]
, which is not used here. It is also, in my opinion, slightly strange for the introduction of a trait method behind a feature gate to break a build when no one requested the feature be used... Therefore, I would expect the code given here to compile all right as long as#![feature(read_exact)]
is not used.Is it possible for the compiler to resolve names after considering the features that are used or is this inherently "working as intended"?
The text was updated successfully, but these errors were encountered: