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

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

Closed
comex opened this issue Oct 6, 2014 · 1 comment
Closed

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

comex opened this issue Oct 6, 2014 · 1 comment

Comments

@comex
Copy link
Contributor

comex commented Oct 6, 2014

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.

@steveklabnik
Copy link
Member

Today, this code looks like

fn main() {
    let val = &mut vec!(1);
    let slice1 = val.as_slice(); // OK
    let slice2 = &val[]; // er
}

and compiles just fine. Note the last &.

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 13, 2024
…r, r=Veykril

internal: Move and split flycheck crate into rust-analyzer main crate

The crate no longer is about flychecking, it mainly hosts common command process handling shared by flycheck, test explorer and now project discovery. This re-organizes that into the main crate.
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

2 participants