Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMethods behind a feature gate are still visible to the compiler even when the feature is not on #28126
Comments
steveklabnik
added
the
A-stability
label
Nov 11, 2015
brson
added
I-wrong
T-compiler
and removed
I-wrong
labels
May 4, 2017
This comment has been minimized.
This comment has been minimized.
|
We discussed this back when feature-gate system was being first put into place. The decision was that it was better to have advance notice of upcoming method-name conflicts, and hence we decided not to alter the behavior. (In some cases, when the resulting problems are widespread, we have rolled back changes or renamed methods as a result, as well.) Therefore, I'm going to close this issue. Thanks though for the report. (That said, it seems to that the ideal might be to issue warnings, but that would be more complex to implement.) |
nikomatsakis
closed this
May 4, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mlalic commentedAug 31, 2015
When a new trait method is found behind a feature gate (such as the
read_exactmethod ofio::Read, which is behind the correspondingly named feature)rustcwill 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
rustcshould 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_exactmethod (the one fromMyExtand the one fromio::Read), but the method onio::Readis 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"?