You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking Issue for RFC 213: Default Type Parameter Fallback #27336
B-RFC-approvedBlocker: Approved by a merged RFC.B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-default_type_parameter_fallback`#![feature(default_type_parameter_fallback)]`T-langRelevant to the language team
#![crate_type = "lib"]#![feature(default_type_parameter_fallback)]traitA<T = Self>{fna(t:&T) -> Self;}traitB<T = Self>{fnb(&self) -> T;}impl<U,T = U>B<T>forUwhereT:A<U>{fnb(&self) -> T{T::a(self)}}structX(u8);implAforX{fna(x:&X) -> X{X(x.0)}}fnf(x:&X){
x.b();// ok}fng(x:&X){let x = x.b();
x.0;// error: the type of this value must be known in this context}
@mahkoh there is a necessary patch that hasn't gotten rebased since I stopped my summer internship. I've been unfortunately busy with real life stuff, looks like @nikomatsakis has plans for landing a slightly different version according to a recent post of his on the corresponding documentation issue for this feature.
@nikomatsakis I know the lang team didn't see any future in this feature, will you put that on record in the issue 😄?
One example where this feature seems to be the only way out is the following concrete example of API evolution in libstd.
Option<T> implements PartialEq today, but we would like to extend it to PartialEq<Option<U>> where T: PartialEq<U>. It appears this feature can solve the type inference regressions that would otherwise occur (and might block us from doing this oft-requested improvement of Option).
@bluss I HAVE been dubious of this feature, but I'm been slowly reconsidering. @aturon is supposed to be doing some exploration of this whole space and writing up some detailed thoughts. I actually started rebasing @jroesch's dead branch to implement the desired semantics and making some progress there too, but I've been distracted.
One advantage of finishing up the impl is that it would let us experiment with extensions like the one you describe to see how backwards compatible they truly are -- one problem with fallback is that it is not ACTUALLY backwards compatible, because of the possibility of competing incompatible fallbacks.
I think we should completely remove the feature gate. It's currently only partially implemented and requires some significant design work before we re-add it afaict.
B-RFC-approvedBlocker: Approved by a merged RFC.B-RFC-implementedBlocker: Approved by a merged RFC and implemented but not stabilized.B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-default_type_parameter_fallback`#![feature(default_type_parameter_fallback)]`T-langRelevant to the language team
Activity
bluss commentedon Nov 20, 2015
What is the status of this?
pnkfelix commentedon Dec 1, 2015
@bluss it is still feature-gated, AFAICT. See e.g. the discussion on PR #26870 , or just look at this playpen
I am not sure what the planned schedule is for unfeature-gating it.
nominating for discussion.
mahkoh commentedon Dec 11, 2015
This doesn't seem to be working properly.
jroesch commentedon Dec 15, 2015
@mahkoh there is a necessary patch that hasn't gotten rebased since I stopped my summer internship. I've been unfortunately busy with real life stuff, looks like @nikomatsakis has plans for landing a slightly different version according to a recent post of his on the corresponding documentation issue for this feature.
bluss commentedon Feb 22, 2016
@nikomatsakis I know the lang team didn't see any future in this feature, will you put that on record in the issue 😄?
One example where this feature seems to be the only way out is the following concrete example of API evolution in libstd.
Option<T>implementsPartialEqtoday, but we would like to extend it toPartialEq<Option<U>> where T: PartialEq<U>. It appears this feature can solve the type inference regressions that would otherwise occur (and might block us from doing this oft-requested improvement of Option).nikomatsakis commentedon Feb 23, 2016
@bluss I HAVE been dubious of this feature, but I'm been slowly reconsidering. @aturon is supposed to be doing some exploration of this whole space and writing up some detailed thoughts. I actually started rebasing @jroesch's dead branch to implement the desired semantics and making some progress there too, but I've been distracted.
One advantage of finishing up the impl is that it would let us experiment with extensions like the one you describe to see how backwards compatible they truly are -- one problem with fallback is that it is not ACTUALLY backwards compatible, because of the possibility of competing incompatible fallbacks.
nikomatsakis commentedon Feb 23, 2016
That said I still have my doubts :)
79 remaining items
lcnr commentedon Jul 15, 2024
I think we should completely remove the feature gate. It's currently only partially implemented and requires some significant design work before we re-add it afaict.
nikomatsakis commentedon Jul 15, 2024
RalfJung commentedon Jul 15, 2024
Sadly that's not really possible currently,
typemapuses this feature...RalfJung commentedon Jul 15, 2024
I will reopen the issue then -- as long as the feature gate exists, the tracking issue it points to should remain open.
Rollup merge of rust-lang#127655 - RalfJung:invalid_type_param_defaul…
Rollup merge of rust-lang#127655 - RalfJung:invalid_type_param_defaul…
Rollup merge of rust-lang#127655 - RalfJung:invalid_type_param_defaul…
Rollup merge of rust-lang#127655 - RalfJung:invalid_type_param_defaul…
Rollup merge of rust-lang#127655 - RalfJung:invalid_type_param_defaul…
Unrolled build for rust-lang#127655
nik-rev commentedon Mar 8, 2026
I found a hack that allows us to pretend that default type parameters affect inference in some circumstances
Given this:
I want users to be able to write this:
But that won't work, the default type parameter
Sink = io::Stderrdoes not affect type inference:The solution is to add a method called
default()that just callsDefault::default():That causes the expression
Hook::default()to really callHook::<io::Stderr>::default(), which calls<Hook<io::Stderr> as Default>::default()Document Rust limitation with typed consistency parameter
Add u32 bucket counts as named sibling types (#12)