-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Library modernization blockers #19186
Comments
@japaric Thanks so much for putting this together! |
Added #18048 (ICE when cross-crate importing a trait that has associated output types) to the list, which blocks any work on associated types. |
I was exploring using unboxed closures in structs like
struct Map<A, B, I, F> where I: Iterator<A>, F: FnMut(A) -> B {
iter: I,
f: F,
}
// Self = str
fn bytes<'a>(&'a self) -> Bytes<'a> {
self.as_bytes().iter().map(|&b| b)
}
These are the suggestions (proposed in the other thread) to work around the issue:
My question here is: On what issue should we block "Using unboxed closures in structs field"?
I'll explore this last option, because I want to see if any other bug/ICE pops up in the process. |
Just found out that there are a lot of type aliases to Since libcollections has access to liballoc, I tried to use the I'll update the top comment to mention that issue, because we want it to get snapshot-ed. |
Don't functions implement the |
Yes! And it almost works: #![feature(unboxed_closures)]
use std::{iter, slice};
struct Map<A, B, I, F> where I: Iterator<A>, F: FnMut(A) -> B {
iter: I,
f: F,
}
fn bytes<'a>(s: &'a str) -> Map<&'a u8, u8, slice::Items<'a, u8>, fn(&u8) -> u8> {
//~^ error: the trait `core::ops::Fn<(&'a u8,), u8>` is not implemented for the type `fn(&u8) -> u8`
fn deref(&b: &u8) -> u8 { b }
Map {
iter: s.as_bytes().iter(),
f: deref,
}
}
fn this_works() -> Map<u8, uint, iter::Range<u8>, fn(u8) -> uint> {
fn cast(i: u8) -> uint { i as uint }
Map {
iter: range(0, 5),
f: cast,
}
}
fn main() {} Except that due to #19126, bare functions that have lifetimes in their arguments/return value currently don't implement the Fn traits. Still, it's a great idea, I'll add it the top comment. Thanks @sfackler! |
Can this be closed? |
Yes. There are still blockers (mainly for assoc types) but I'm working with @nikomatsakis in a tight feedback loop (on IRC) so this issue is not relevant anymore. |
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:
Fn<(&_,), &_>
is not implemented for the typefn(&'a u8) -> &'a u8
#19126 gets fixed, theOption
/Result
API can be updated to use unboxed closures.Unboxed closures
-> Move library code away from boxed closures (part of #14798)
In function arguments
Option
,Result
, etcBlockers
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
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.
Blockers
Fn<(&_,), &_>
is not implemented for the typefn(&'a u8) -> &'a u8
HRTB: the traitFn<(&_,), &_>
is not implemented for the typefn(&'a u8) -> &'a u8
#19126Use 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
, etcBlockers
Traits with only output types that are used for GP
AsSlice
,Hasher
, etcBlockers
Trait<Output=Type>
syntax Support theTrait<Output=Type>
syntax #18432Traits with input and output types
Add
,Mul
,Sub
, etcBlockers
It's likely that we'll find more blockers as we progress, so I'll try to keep this list up to date.
cc @alexcrichton @aturon @nick29581 @nikomatsakis
The text was updated successfully, but these errors were encountered: