Skip to content

Missed unsizing coercion #90528

Closed
Closed
@binajmen

Description

@binajmen

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions