Skip to content

Missed unsizing coercion #90528

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

Closed
binajmen opened this issue Nov 3, 2021 · 1 comment · Fixed by #108841
Closed

Missed unsizing coercion #90528

binajmen opened this issue Nov 3, 2021 · 1 comment · Fixed by #108841
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@binajmen
Copy link

binajmen commented Nov 3, 2021

Given the following code:

let buf = BufReader::new(&[0xff as u8, 0xff, 0x00, 0x1d, 0x01, 0x04, 0xff, 0xff, 0xff]);

The current output is:

let buf = BufReader::new(&[0xff as u8, 0xff, 0x00, 0x1d, 0x01, 0x04, 0xff, 0xff, 0xff]);
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::io::Read` is not implemented for `&[u8; 9]`

Following a discussion with the Rust community on Discord, ideally the output should be adapted:

This looks like a missed unsizing coercion. Read is implemented for &[u8], but not for &[u8; 9]: you have a reference to an array, not to a slice. Try &[/your bytes here/][..]. –– T-Dark

actually a possible improvements for error message tbh –– ruff

array & slice is kinda similar in syntax –– ruff

https://discord.com/channels/273534239310479360/274215136414400513/905455195910205480
https://discord.com/channels/273534239310479360/274215136414400513/905455866029936641

@binajmen binajmen added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 3, 2021
@BGR360
Copy link
Contributor

BGR360 commented Nov 28, 2021

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 12, 2023
…rrors

Add suggestion to diagnostic when user has array but trait wants slice. (rebased)

Rebase of rust-lang#91314, except for change to multipart suggestion

Resolves rust-lang#90528

r? `@compiler-errors` since you requested the multipart suggestion
@bors bors closed this as completed in 67c9dbf Mar 12, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants