|
| 1 | +- Feature Name: N/A |
| 2 | +- Start Date: 2015-10-14 |
| 3 | +- RFC PR: (leave this empty) |
| 4 | +- Rust Issue: (leave this empty) |
| 5 | + |
| 6 | + |
| 7 | +# Summary |
| 8 | + |
| 9 | +Unstable items and methods are considered for resolution even when the |
| 10 | +feature isn't available to client code - whether on stable channels or |
| 11 | +unstable when the relevant `#![feature(...)]` crate attribute isn't in use. |
| 12 | +This particularly causes problems when user extension traits provide methods |
| 13 | +that may conflict with newly added methods from the standard library. |
| 14 | + |
| 15 | + |
| 16 | +# Motivation |
| 17 | + |
| 18 | +In the current Rust 1.4 beta, the `std::io::Read::read_exact` method is provided, |
| 19 | +which was previously a common extension method provided by libraries on `crates.io`. |
| 20 | +Any downstream crates that were previously using it must use UFCS syntax to invoke |
| 21 | +the method now, as `read_exact` is unstable and cannot be used without opting in to |
| 22 | +the feature on unstable Rust. |
| 23 | + |
| 24 | +The dilemma is as follows: crates that provide extension methods must rename them |
| 25 | +in order to be ergonomic, or otherwise expect downstream crates to use the obtuse |
| 26 | +UFCS syntx. They cannot defer to the standard library version until it becomes |
| 27 | +stable after a couple release cycles - and once that happens, another adoption |
| 28 | +step must be taken by removing the method and suggesting users move to the |
| 29 | +`libstd` version. |
| 30 | + |
| 31 | +This is prone to happen any time a common library extension becomes popular |
| 32 | +enough for inclusion in the standard library. The language should provide a |
| 33 | +smooth migration path for everyone involved. |
| 34 | + |
| 35 | + |
| 36 | +# Detailed design |
| 37 | + |
| 38 | +This RFC proposes that any unstable items (structs, traits, functions, etc.) |
| 39 | +must not be considered as valid candidates for name resolution unless its |
| 40 | +related feature gate has been opted in to via the `#![feature(...)]` crate |
| 41 | +attribute. Attempts to use unstable features will result in an appropriate |
| 42 | +"item not found" error message, along with a suggestion note that it may be |
| 43 | +available if they enable the appropriate feature. Stable builds of `rustc` |
| 44 | +will use slightly modified wording explaining that the feature isn't available |
| 45 | +as is done now. |
| 46 | + |
| 47 | +Note that is not only an issue in stable rust, as long as one expects to retain |
| 48 | +the ability to use their code on unstable/nightly as well. |
| 49 | + |
| 50 | + |
| 51 | +# Drawbacks |
| 52 | + |
| 53 | +Extra complexity in `rustc` for new features is always a drawback. Some might |
| 54 | +argue some form of migration will have to be done anyway once the feature |
| 55 | +becomes stable. At that time moving to the stable version is a valid upgrade |
| 56 | +path, but not currently possible for as long as the feature is unstable, and |
| 57 | +so it forces two migration points months apart. |
| 58 | + |
| 59 | + |
| 60 | +# Alternatives |
| 61 | + |
| 62 | +- Unstable items could instead be considered "weak", where external items |
| 63 | + can override them when there are conflicts, but would otherwise behave as |
| 64 | + they currently do. |
| 65 | +- "Fast-track" the offending methods to stability considering that they've |
| 66 | + already had time to mature in the greater `crates.io` ecosystem and have |
| 67 | + proven their use and design. |
| 68 | +- Not doing anything. Some may consider renaming, moving to UFCS syntax, or |
| 69 | + standalone methods to be good enough as an interim migration step. |
| 70 | + |
| 71 | + |
| 72 | +# Unresolved questions |
| 73 | + |
| 74 | +Exactly what type of items are affected? Trait methods are the most obvious. |
| 75 | +Structures and traits themselves may also affect those using glob imports, |
| 76 | +whether or not they are added to library prelude modules. |
| 77 | + |
| 78 | +Are there concerns or implementation issues here around interactions with |
| 79 | +macros and `#[allow_internal_unstable]`? |
| 80 | + |
| 81 | +Should we go one step further and remove any mention of unstable items from |
| 82 | +rustdoc's output, except when building unstable docs for nightly? I believe |
| 83 | +this topic has come up occasionally in previous discussions. |
0 commit comments