-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
No way to use fn
with both const generics and impl Trait
#85475
Comments
fn
with both const generics and impl Trait
This is not limited to const generics, it also happens with type generics. AFAIK this is intended behavior. |
With type generics there is an actual solution - the compiler can infer the types from the context. And you can always explict types of args / return to aid the compiler in doing so. EDIT: Okay, you can extract |
I'd just like to state that while consistent with type generics, I share the concern that it's not clear why this restriction needs to be in place. I'm refactoring some code in anticipation of using const generics soon, but I have to add a few inferred type generics for no apparent reason (they were inferred just fine as |
Perfect! Thanks for the info. |
Say we have a function that uses both const generics and takes an
impl Trait
argumentThe function itself compiles just fine... but there is no way to use it.
Specifying the argument like so
does not work since one cannot provide explicit arguments when
impl Trait
is used [E0632]and if we remove the explicit arguments
the compiler fairly complains that it doesn't know what value to use for the const generic [E0282]
Workaround: Use explicit arguments instead of
impl Trait
and infer them with
_
TLDR:
fn
with bothconst
generic andimpl Trait
itself compiles, but is not useable in any way. Rust PlaygroundMeta
Tested on both Stable
1.52.1
and Nightly1.54.0-nightly (2021-05-18 4e3e6db011c5b482d2be)
channels, with same results.The text was updated successfully, but these errors were encountered: