-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Description
(I don't know that this is a bug, exactly, but. Was still the best-fit template.)
I tried this code:
fn main() {
let x: Option<&[u8]> = Some(&[1, 2]);
assert_eq!(x, Some(&[3, 4]));
}
I expected to see this happen: This should compile, and then fail the assertion.
Instead, this happened: This fails to compile with the following error:
error[E0308]: mismatched types
--> src/main.rs:3:19
|
3 | assert_eq!(x, Some(&[3, 4]));
| ^^^^^^^^^^^^^ expected `Option<&[u8]>`, found `Option<&[{integer}; 2]>`
|
= note: expected enum `Option<&[u8]>`
found enum `Option<&[{integer}; 2]>`
Re-writing the code as
fn main() {
let x: Option<&[u8]> = Some(&[1, 2]);
assert!(x == Some(&[3, 4]));
}
works as expected.
Also, yes, I know that it's possible to manually coerce this by writing assert_eq!(x, Some(&[3, 4][..]));
, but it's disappointing that I should have to.
Meta
rustc --version --verbose
:
Used the playground; it reports 1.77.0-nightly (2024-01-22 d5fd0997291ca0135401)
amab8901
Metadata
Metadata
Assignees
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.