Constructing Option<&'static dyn T>::None
in a const fn
requires const_fn_trait_bounds
#87240
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Thank you for continuing to improve Rust!
Given the following code: playground
The current output is:
After reading this message and reading #57563, I'm not sure what trait bound is a problem. The code that is literally written here does not have any trait bounds - no syntax
R: T
; nor does it have any (explicit) genericconst fn
.I assume there is a good reason why this doesn't immediately work - I know the Rust team has put tons of work into making all this analysis correct, so this is not a complaint about the analysis. :-) I'm just not sure how to go from the compiler's message to an action other than "switch to nightly".
(I can confirm that switching to nightly and enabling
#![feature(const_fn_trait_bounds)]
does quiet the warning. It's not clear to me what more-specific issue than #57563 is tracking it?)Experiments / speculation:
I'm assuming there's some sort of desugaring here that's causing a trait bound to appear - e.g. the
None
constructor becoming aconst fn
(per #61456) , and something in theOption
's generic argument turning into a trait bound. However,Option<T>
itself doesn't have any trait bounds onT
(...other than the defaultSized
, which the error message says is OK), so I'm not sure what to change.Some experimenting shows that
Option<&static T>
its OK for a built-inT
:compiles on stable (1.53.0).
And even using a different
?Sized
type -[u8]
- works out alright:compiles as well.
That's based on a not-great understanding of
Sized
- if I understand correctly bothdyn T
and[u8]
are?Sized
.The text was updated successfully, but these errors were encountered: