-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*mut
"uses" type params, but *const
(and therefore NonNull
) does not
#118976
Comments
Note that the use of struct Foo<T>(*mut Foo<T>); // works
struct Bar<T>(*const Bar<T>); // error[E0392]: parameter `T` is never used |
Similar example: struct Foo<T: 'static>(&'static mut Foo<T>); // works
struct Bar<T: 'static>(&'static Bar<T>); // errors You can remedy this with |
Ah, thank you. I had thought it might be variance-related and did refresh my memory with a read of the chapters on subtyping in the reference and nomicon but neither mention "bivariance" at all nor how variance relates to whether a type parameter is deemed to be "used" in a type definition. Perhaps this is already documented somewhere that I missed, but if not maybe this is a documentation bug? |
The rustc dev guide mentions bivariance but that one isn't really user-facing as its name suggests. Not sure why the Reference and the Nomicon don't mention it, maybe because it's considered to be an implementation detail? |
Can it really be an implementation detail if its effect is user facing ? |
Yeah, makes sense. Probably worth opening an issue over at the Reference and/or the Nomicon. It's an implementation detail insofar that rustc never mentions bivariance in any error messages for example and only talks about generic parameters “that must be used”. |
Okay, thanks again. Will open an issue as advised. Closing here. |
Yes, that's a helpful clarification. Perhaps that could be added into the explanation of E0392? |
Rollup merge of rust-lang#127871 - compiler-errors:recursive, r=estebank Mention that type parameters are used recursively on bivariance error Right now when a type parameter is used recursively, even with indirection (so it has a finite size) we say that the type parameter is unused: ``` struct B<T>(Box<B<T>>); ``` This is confusing, because the type parameter is *used*, it just doesn't have its variance constrained. This PR tweaks that message to mention that it must be used *non-recursively*. Not sure if we should actually mention "variance" here, but also I'd somewhat prefer we don't keep the power users in the dark w.r.t the real underlying issue, which is that the variance isn't constrained. That technical detail is reserved for a note, though. cc `@fee1-dead` Fixes rust-lang#118976 Fixes rust-lang#26283 Fixes rust-lang#53191 Fixes rust-lang#105740 Fixes rust-lang#110466
Update(fmease): See #118976 (comment) and #118976 (comment).
As first mentioned on URLO, and demonstrated on quick playground:
Is this a bug, or is there some obscure reason for it?
The text was updated successfully, but these errors were encountered: