-
Notifications
You must be signed in to change notification settings - Fork 507
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
Default type parameters are not in the language reference #24
Comments
It would be even better if the semantics could be less tricky :) Where is the problem with always trying to infer unspecified types and falling back on defaults when they can't be inferred? This is the behaviour I would expect, at least. |
I would like the first case to work: struct Foo<T = u8>(T);
impl<T: Default> Default for Foo<T> {
fn default() -> Self {
Self(Default::default())
}
}
// This breaks with: error[E0282]: type annotations needed for `main::Foo<T>`
let a = Foo::default();
// This works.
let b: Foo = Foo::default(); See it live here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=0577801bc59bb19cc6c61039863d130a |
You should file an issue against rust-lang/rust about that. The reference just documents what's already there. |
Migrated from rust-lang/rust#38011
Default type parameters (e g
struct Foo<A = u32>(A)
) is a language feature, but they are not mentioned in the language reference.It would be nice if such a reference also mentioned the tricky semantics around how it interacts with inference, as mentioned here.
The text was updated successfully, but these errors were encountered: