-
Notifications
You must be signed in to change notification settings - Fork 13k
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
const generics return type with const expression mismatched types #69943
Comments
This is correct according to the const generics' RFC:
|
thanks @Patryk27, seems it is an Unresolved questions according to the RFC. But the error message is a bit confusing.
|
FYI, this kind of thing compiles fine and does exactly what you expect it to do as long as you're not explicit about the generic constraints inside the function body, and let the return type be inferred from what you've already declared it as. Here's a working playground link of your code, where the only change is just doing |
@slightlyoutofphase thanks, that works. but method call will fail to compiles fn bar_ret_2<const N: usize, const M: usize>(a: Foo<N>, b: Foo<M>) -> Foo<{ max(N, M) }> {
bar_ret(a, b)
} |
Yeah, I guess that kind of direct "passthrough" where both functions have exactly the same generic constraints and the second one returns the result of the first doesn't quite work yet. I feel like that's not a huge issue probably, though. The sort of syntax that does compile, i.e. the I'd say to me at least, also, having an actual "call" (so to speak) to the
None of this really matters though, just my two cents after having written a bunch of code using const generics, haha. |
Actually, wait, I was wrong, there's a way to make this work so that you're even able to call
Here's a working playground link that expands on your code a bit and uses the I guess the reason it works with an alias probably has something to do with forcing the |
Using a type alias is exactly what the original RFC proposes to solve this issue. |
Is it a purely technical limitation currently that it doesn't work with the "direct" use of I can't imagine it's intentional when it seems like most people would basically expect the direct use to amount to being completely equivalent to the alias in practice. |
I also found it very hard or not possible to use type alias as workaround in some cases, example |
related issue #62058 |
Why do you consider this blocking? Unifying generic constants is not necessary for |
I marked this one more as a note to myself to check that we couldn't get diagnostics like this still, where it suggests two things are different that look literally the same. But, as you say, it shouldn't be an issue for |
the unification for generic constants has now been implemented under the |
I tried this code:
I expected to see this happen:
compile success
Instead, this happened:
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: