Cannot call method that requires a non-array unsized coercion, contrary to the reference #122708
Labels
A-associated-items
Area: Associated items such as associated types and consts.
C-bug
Category: This is a bug.
T-types
Relevant to the types team, which will review and decide on the PR/issue.
In short: why can't I call
Cell::new([1, 2, 3]).as_slice_of_cells()
?Minimal example:
I expected to see this happen: this should compile. As documented by the reference, these candidates should be considered in the above method call:
Foo<[u8; 3]>
&Foo<[u8; 3]>
&mut Foo<[u8; 3]>
Foo<[u8]>
(by unsized coercion)&Foo<[u8]>
&mut Foo<[u8]>
The
foo_generic_slice
method should be called via the unsized coercion toFoo<[u8]>
.Instead, this happened: I get a compile error, stating that I must perform the unsized coercion manually:
In contrast, if the unsized coercion is from
[T; N]
to[T]
rather than for a custom DST, the method can be called. This happens every time.len()
is called on an array. See this playground which tests other broken and working scenarios.There's also another unsized coercion that seems to be ignored entirely - the coercion from
T
todyn Trait
is ignored for inherent methods implemented ondyn Trait
- it seems that actually looking up all of these candidates as described by the reference could be incredibly costly, especially for theFoo<T>
toFoo<dyn Trait>
coercion.Meta
Happens in Rust 1.76.0 and 1.79.0-nightly (2024-03-17 eb45c84). Appears to occur in every version of Rust.
The text was updated successfully, but these errors were encountered: