Skip to content

Can't use [] to get slice of &mut Vec #17831

@comex

Description

@comex
let val = &mut vec!(1u);
let slice1 = val.as_slice(); // OK
let slice2 = val[]; // error: cannot take a slice of a value with type `&mut collections::vec::Vec<uint>`

(If I use core::ops::Slice, as_slice_() works but as_slice() stops working. I don't understand how that works either.)

The RFC says "uses of this notation will auto-deref just as if they were method invocations", so I think this is a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions