Why does `*mut` "use" its type parameters, but `*const` does not?

struct Foo<T>(*mut Self); // works
struct Bar<T>(*const Self); // error[E0392]: parameter `T` is never used

Er, what?

4 Likes

I do not have an answer to your question, but am curious: how did you even discover this ?

I changed a field from *mut Self to Option<NonNull<Self>> and hit the same issue, thought I was going mad and then tried *const.

2 Likes

I would file a bug with rustc.

Wanted to check here that it wasn't deliberate first, but I think your view on that is as good as any!

Filed `*mut` "uses" type params, but `*const` (and therefore `NonNull`) does not · Issue #118976 · rust-lang/rust · GitHub

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.