Suggested resolution to "unconstrained generic constant" does not make sense for types other than usize #82509
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
F-generic_const_exprs
`#![feature(generic_const_exprs)]`
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Based on a StackOverflow question.
Given the following code: (Playground)
The current output is:
This suggestion fails to compile, because
baz
andquux
(and their sum) have typei64
, while the context of a slice length requiresusize
. Ideally, it should instead suggestwhere Foo<{baz + quux}>: Sized
, which does compile.Strictly speaking, pulling out the context of the constant expression's use and checking if it implements
Sized
will not work if the type is not supposed to implementSized
; perhapsPhantomData<Foo<{baz + quux}>>: Sized
would be an alternative to suggest in that case. Overall, the pattern does seem a little hacky, working around the fact that there is no way to specify a constraint that a type exists.The text was updated successfully, but these errors were encountered: