Skip to content

Library modernization blockers #19186

Closed
Closed
@japaric

Description

@japaric

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:

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

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

Use boxed closures otherwise

Add examples here

Blockers

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

Traits with only output types that are used for GP

AsSlice, Hasher, etc

Blockers

Traits with input and output types

Add, Mul, Sub, etc

Blockers


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

Metadata

Metadata

Assignees

No one assigned

    Labels

    metabugIssues about issues themselves ("bugs about bugs")

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions