Skip to content
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

Map methods on constant sized arrays return dynamically sized arrays. #6562

Closed
mstewartgallus opened this issue May 17, 2013 · 3 comments
Closed

Comments

@mstewartgallus
Copy link
Contributor

Consider the following code samples:
(1)

    let mut positions = [Zero::zero (), ..ObjectAmount];
    for uint::range (0, positions.len ()) |ii| {
         positions[ii] = do objects[ii].position
    }

(2)

   let positions = do objects.map |object| { object.position }

Code example number (2) looks much prettier than code example (1) but is incorrect, as it returns a dynamically sized array. The code returns a dynamically sized array because the objects array is coerced to a dynamically sized array, and then the map method is called on the dynamic array. Can some method of making code sample number (2) happen be implemented? Right now, the behaviour is unintuitive, and annoying.

@catamorphism
Copy link
Contributor

I'm not sure this is practical without some sort of dependent types, but in any case, nominating for milestone 1 (well-defined) so we can decide.

@mstewartgallus
Copy link
Contributor Author

Maybe some kind of Array kind could be added?

For example,

pub trait <T> MapUtil: Array<T> {
    fn map<S, U: Array<T>>(Self) -> U;
}

@thestinger
Copy link
Contributor

The map method on vectors is marked as deprecated in vec.rs and will be replaced by the iterator form of map.

There's currently no way to implement methods on fixed-size arrays, so the issue here is #7622.

mgacek8 added a commit to mgacek8/rust that referenced this issue Mar 4, 2021
Required to resolve rust-lang#6562 rust-clippy issue.
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 25, 2021
…_with_default_with_other_ctors, r=phansch

mem_replace_with_default: recognize some std library ctors

fixes rust-lang#6562
changelog: mem_replace_with_default: recognize some common constructors equivalent to `Default::default()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants