Description
This is a list of the blockers (ICEs/bugs) that I found while attempting to modernize the standard library with features like unboxed closures and associated types. This list serves two purposes:
- It should signal which parts of the standard library become actionable. For example, after HRTB: the trait
Fn<(&_,), &_>
is not implemented for the typefn(&'a u8) -> &'a u8
#19126 gets fixed, theOption
/Result
API can be updated to use unboxed closures. - As a list of high priority FIXMEs.
Unboxed closures
-> Move library code away from boxed closures (part of #14798)
In function arguments
Option
, Result
, etc
// from
fn map<U>(self, f: |T| -> U) -> Option<U>;
// to
fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U>;
Blockers
- the trait
Fn<(&_,), &_>
is not implemented for the typefn(&'a u8) -> &'a u8
HRTB: the traitFn<(&_,), &_>
is not implemented for the typefn(&'a u8) -> &'a u8
#19126 (AFAIK, this will be a compiler change, and will need a snapshot)
In structs fields
core::iter::Map
struct Map<A, B, I, F> where I: Iterator<A>, F: FnMut(A) -> B {
iter: I,
f: F,
}
Main issue here is that closures have anonymous types, so they can't be part of the signature of functions, structs, etc. See #19186 (comment)
and/or #18101 (comment) for more details.
Use bare functions instead of closures that capture nothing
core::str::Bytes
, core::str::AnyLines
collections::btree::Keys
, collections::hash_map::Values
As pointed by @sfackler: If the closure captures nothing, we can use a bare function instead.
type Bytes<'a> = Map<&'a u8, u8, slice::Items<'a, u8>, fn(&u8) -> u8>;
// Self = str
fn bytes(&self) -> Bytes {
fn deref(&b: &u8) -> u8 { b }
self.as_bytes().iter().map(deref)
}
Blockers
- the trait
Fn<(&_,), &_>
is not implemented for the typefn(&'a u8) -> &'a u8
HRTB: the traitFn<(&_,), &_>
is not implemented for the typefn(&'a u8) -> &'a u8
#19126
Use boxed closures otherwise
Add examples here
Blockers
-
Box<Fn(int) -> int + 'static>
is not accepted: "explicit lifetime bound required"Box<Fn(int) -> int + 'static>
is not accepted: "explicit lifetime bound required" #18772 (Fixed in Correct parsing of the precedence of+
#19298, but needs to get snaptshot-ed)
Associated types
-> Update library code for associated output types #17826
There are several issues in this area, so I'll list the blockers in increasing complexity order:
Extension traits with only output types
AdditiveIterator
, MultiplicativeIterator
, etc
Blockers
- ICE: When cross-crate importing trait with associated output types ICE when using associated types in gfx-rs #18048 (comment) (this one blocks any work with associated types)
- rustdoc panics when dealing with associated types rustdoc panics when dealing with associated types #18594 (this one also blocks any work with associated types)
- Associated types Order can cause ICE Associated types Order can cause ICE #18611 (can be worked around by shuffling the code around, but fixing it should reduce the amount of code churn)
Traits with only output types that are used for GP
AsSlice
, Hasher
, etc
Blockers
- ICE: When using an associated type as the type parameter of a bound ICE: When using an associated type as the type parameter of a bound #19081
- Support the
Trait<Output=Type>
syntax Support theTrait<Output=Type>
syntax #18432
Traits with input and output types
Add
, Mul
, Sub
, etc
Blockers
- ICE: When implementing trait with a generic parameter and an associated output type ICE: When implementing trait with a generic parameter and an associated output type #19129
It's likely that we'll find more blockers as we progress, so I'll try to keep this list up to date.