-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Rustc help tips create a loop with borrowing #72742
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-bug
Category: This is a bug.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
F-on_unimplemented
Error messages that can be tackled with `#[rustc_on_unimplemented]`
F-unsized_locals
`#![feature(unsized_locals)]`
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
For reference, what you likely want to do is one of the following use std::convert::TryInto;
fn main() {
let x: [u8; 3] = vec!(1, 2, 3)[..].try_into().unwrap(); // sized array
let y: &[u8] = &vec!(1, 2, 3)[..]; // `u8` slice
} Bare slices ( |
Current output:
After #106223:
|
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Dec 29, 2022
…compiler-errors On unsized locals with explicit types suggest `&` Fix rust-lang#72742.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Dec 29, 2022
…compiler-errors On unsized locals with explicit types suggest `&` Fix rust-lang#72742.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
C-bug
Category: This is a bug.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
F-on_unimplemented
Error messages that can be tackled with `#[rustc_on_unimplemented]`
F-unsized_locals
`#![feature(unsized_locals)]`
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I tried compiling this code:
which resulted in the following output of rustc:
So the compiler says
help: consider borrowing here: &vec!(1, 2, 3)[..]
So I tried adding a borrow and recompiling the code:
which resulted in:
so the compiler says
help: consider removing the borrow: vec!(1, 2, 3)[..]
and so I'm stuck in a loop. The compiler can't decide whether I should borrow or not.
As a newbie to Rust, this is very frustrating and the opposite of helpful, it just confuses me further.
Please fix this indecisiveness :)
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: