I really don't get this diagnostic. It says that U is unused, but removing U causes a " cannot find type U in this scope" diagnostic. Is U used or not? I feel like this diagnostic could be improved.
(btw, I arrived at this code while reading https://doc.rust-lang.org/book/2018-edition/ch13-01-closures.html#limitations-of-the-cacher-implementation)
struct Cacher<T, U: Copy>
where T: Fn(U) -> U
{
calculation: T,
value: Option<u32>,
}
fn main() {
let c = Cacher::new(|x| x);
println!("Hello, world!");
}
(Playground)
Errors:
Compiling playground v0.0.1 (file:///playground)
error[E0392]: parameter `U` is never used
--> src/main.rs:2:18
|
2 | struct Cacher<T, U: Copy>
| ^ unused type parameter
|
= help: consider removing `U` or using a marker such as `std::marker::PhantomData`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0392`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
I really don't get this diagnostic. It says that U is unused, but removing U causes a " cannot find type
Uin this scope" diagnostic. Is U used or not? I feel like this diagnostic could be improved.(btw, I arrived at this code while reading https://doc.rust-lang.org/book/2018-edition/ch13-01-closures.html#limitations-of-the-cacher-implementation)
(Playground)
Errors: