-
Notifications
You must be signed in to change notification settings - Fork 174
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
Generic parameters can have defaults #307
Comments
Defaults are not very well supported in rustc. Tyoe inference doesn't fall back to param defaults I believe. |
Do you have an example @bjorn3? That is really interesting to know. |
struct Box<T, A: Default = ()>(T, A);
impl<T, A: Default> Box<T, A> {
fn new(x: T) -> Self {
Box(x, Default::default())
}
}
fn main() {
Box::new(1);
}
|
Thanks! |
This was referenced Apr 16, 2021
Closed
Closed
philberty
added a commit
that referenced
this issue
Apr 27, 2021
Type parameters can have defaults these need to be name resolved. Addresses: #307
philberty
added a commit
that referenced
this issue
Apr 30, 2021
In the case that the GenericArgs to a type/fn are less than the expected number of required substitutions we need to look for what is the min number of required substitutions which might be zero if each TypeParam has a default. In the event we have less than expected arguments we can substitute the defaults if available as the GenericArgumentMappings. Addresses: #307
philberty
added a commit
that referenced
this issue
Apr 30, 2021
In the case that the GenericArgs to a type/fn are less than the expected number of required substitutions we need to look for what is the min number of required substitutions which might be zero if each TypeParam has a default. In the event we have less than expected arguments we can substitute the defaults if available as the GenericArgumentMappings. Addresses: #307
philberty
added a commit
that referenced
this issue
Apr 30, 2021
In the case that the GenericArgs to a type/fn are less than the expected number of required substitutions we need to look for what is the min number of required substitutions which might be zero if each TypeParam has a default. In the event we have less than expected arguments we can substitute the defaults if available as the GenericArgumentMappings. Addresses: #307
bors bot
added a commit
that referenced
this issue
Apr 30, 2021
401: Add defaults support for generics r=philberty a=philberty This adds in the basic support for default arguments for generics such as: ```rust struct Foo<A,B=f32>(A,B); ``` or recursive type params such as: ```rust struct Foo<A, B = (A, A)>(A, B); ``` Fixes #307 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For example this test case: https://github.com/rust-lang/rust/blob/master/src/test/ui/generics/generic-impl-less-params-with-defaults.rs
The text was updated successfully, but these errors were encountered: