-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Inconsistent rustc inference #141103
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
Comments
This is working as intended. Default generics only apply if generics are specified but the defaulted generic is omitted. To get the desired behavior, you can write |
That's what I was trying to show, I feel the behavior is inconsistent. Maybe I'm just missing something. |
In my understanding, what you're requesting is actually rather complicated, and people haven't yet figured out how to do this. (Since rust has to figure out whether you want the types to be inferred vs defaulted.) See #27336 |
That makes sense, I suspected there was a subtlety (otherwise the problem would have been solved by now, I guess). For completeness, here's what the linked Issue says: fn foo<T = u64>(t: T) { ... }
fn main() { foo::<_>(22) }
// ^
// |
// What type gets inferred here?
|
I tried this code:
See on Compiler Explorer.
In
main
, I try to create aMockType
and the compiler is acting inconsistently.As I am not adding any information by specifiying
::<()>
, I would expect it to either be able to infer thatT = ()
in the second case or unable to default toDefaultU
in the first.Meta
rustc --version --verbose
:but it also happens on stable (1.87.0)
Backtrace
The text was updated successfully, but these errors were encountered: