Repository navigation
Tracking issue for future-incompatibility lint invalid_type_param_default #36887
Description
This is the summary issue for the invalid_type_param_default
future-compatibility warning and other related errors. The goal of
this page is describe why this change was made and how you can fix
code that is affected by it. It also provides a place to ask questions
or register a complaint if you feel the change should not be made. For
more information on the policy around future-compatibility warnings,
see our breaking change policy guidelines.
What is the warning for?
Type parameter defaults outside of type declarations were never intended
to be permitted, but some early versions of Rust did accept them. For
example:
struct Foo<T=i32> {
// the default of `i32` is legal here, since this
// is a type declaration
}
impl<T=i32> Debug for Foo<T> { .. }
// ^^^^^ default not legal here, in an impl
fn bar<T=i32>(x: T) { }
// ^^^^^ default not legal here, in a fnWhen will this warning become a hard error?
At the beginning of each 6-week release cycle, the Rust compiler team
will review the set of outstanding future compatibility warnings and
nominate some of them for Final Comment Period. Toward the end of
the cycle, we will review any comments and make a final determination
whether to convert the warning into a hard error or remove it
entirely.
Current status
- Feature gate defaulted type parameters appearing outside of types #30724 introduces the
invalid_type_param_defaultlint as warn-by-default - Make sufficiently old or low-impact compatibility lints deny-by-default #36894 makes the
invalid_type_param_defaultlint deny-by-default - Turn sufficiently old compatibility lints into hard errors #42136 tried to make the
invalid_type_param_defaultlint a hard error, but there was still too much breakage - turn
invalid_type_param_defaultinto aFutureReleaseErrorReportInDeps#127655 tried to make this a hard error, but there was still too much breakage (mostly due totypemap), so it was just made to show up in future breakage reports instead - PR ? makes the
invalid_type_param_defaultlint a hard error
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIdea
Activity
petrochenkov commentedon Oct 1, 2016
@nikomatsakis, could you write a description for this?
nikomatsakis commentedon Oct 11, 2016
@petrochenkov done.
nrc commentedon Nov 28, 2016
Where can I find discussion of this issue? I don't see any on RFC 213, nor its tracking issue (#27336).
nikomatsakis commentedon Nov 28, 2016
@nrc perhaps I should have phrased the summary with slightly differently. I think the main thing is that defaults were being accepted in stable code but ignored, unless you opt in to a feature gate, which gives them some semantics (but semantics that I now think I disagree with).
RReverser commentedon Apr 23, 2017
Is there a reason this is being phased out on functions?
It's sometimes useful to have
fn do_smth<A, B=A>(a: A, b: B) { ... }.nikomatsakis commentedon Apr 24, 2017
@RReverser Yes. Because, IIRC, they are basically ignored on stable Rust. On nightly Rust, meanwhile, we were considering various possible meanings, but have not yet found one that we are satisfied with.
RReverser commentedon Apr 24, 2017
Ok, I'm now curious... where can I read about other possible meanings? The expectation seems pretty straightforward, just like in case with
struct- that withfn do_smth<T=SomeType>() {},do_smth()would be equivalent dodo_smth::<SomeType>()but maybe I'm missing some issues?Auto merge of #42136 - petrochenkov:oldhard, r=nikomatsakis
42 remaining items
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
tjpalmer commentedon Aug 9, 2024
Similar problem for things like
Option<impl ToString>. Having to say something likeNone::<String>is sort of silly.EndilWayfare commentedon Sep 7, 2024
euclidis another example of a class of use-case in which this is useful for ergonomic/noise-reduction reasons.The geometric primitives from this crate have an "optional" type parameter to specify unit of measure, but it's not really optional. You don't have to make active use of it, but you do have to mention it in your client code regardless.
I don't know why
euclidchooses to uses a type alias instead of a default type parameter, or even if this is even a deliberate design decision. But, if a crate author decides they don't like default type parameters and you do like default type parameters, functions-with-default-type-parameters would let you have/emulate them without, e.g., a redundant wrapper struct.RalfJung commentedon Sep 7, 2024
[-]Tracking issue for `invalid_type_param_default` compatibility lint[/-][+]Tracking issue for future-incompatibility lint `invalid_type_param_default`[/+]Houtamelo commentedon May 1, 2025
Based on the comments it is very clear that allow default type parameters in function signatures is desirable. Is there an RFC for this already? If not, I could open it.
fmease commentedon May 1, 2025
I strongly recommend to read the following first: https://internals.rust-lang.org/t/interaction-of-user-defined-and-integral-fallbacks-with-inference/2496/2 (linked from #2733).
Also CC #98931 (comment):
valarauca commentedon Apr 2, 2026
So 10 years later, is this actually happening or not?
refactor(kermit): make hash_join generic over HashStrategy