LYR-SEM0170
an extend block's type parameter is bound by nothing
An extend<…> block declares a type parameter that its target does not name and that no constraint of a named parameter fixes, as U in extend<T, U> Shelf<T>.
Explanation
A block's parameters are bound by matching its target against a type, or fixed through an associated type of a constraint (S :: [Source<Item = U>]). A parameter that neither reaches is never bound, so the block applies to no type and none of its members could be called.
Remove the parameter, or name it in the target or in a constraint that fixes it.
Wrong
struct Shelf<T> {
v: T,
}
extend<T, U> Shelf<T> {
fn one(): int {
return 1;
}
}
fn main(): void {
let _ = Shelf { v = 2 }.one();
}
Right
struct Shelf<T> {
v: T,
}
extend<T> Shelf<T> {
fn one(): int {
return 1;
}
}
fn main(): void {
let _ = Shelf { v = 2 }.one();
}