-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for future-incompatibility lint invalid_type_param_default
#36887
Comments
@nikomatsakis, could you write a description for this? |
@petrochenkov done. |
Where can I find discussion of this issue? I don't see any on RFC 213, nor its tracking issue (#27336). |
@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). |
Is there a reason this is being phased out on functions? It's sometimes useful to have |
@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. |
Ok, I'm now curious... where can I read about other possible meanings? The expectation seems pretty straightforward, just like in case with |
Turn sufficiently old compatibility lints into hard errors It's been almost 7 months since #36894 was merged, so it's time to take the next step. [breaking-change], needs crater run. PRs/issues submitted to affected crates: https://github.com/alexcrichton/ctest/pull/17 Sean1708/rusty-cheddar#55 m-r-r/helianto#3 azdle/virgil#1 rust-locale/rust-locale#24 mneumann/acyclic-network-rs#1 reem/rust-typemap#38 cc https://internals.rust-lang.org/t/moving-forward-on-forward-compatibility-lints/4204 cc #34537 #36887 Closes #36886 Closes #36888 Closes #36890 Closes #36891 Closes #36892 r? @nikomatsakis
Turn sufficiently old compatibility lints into hard errors It's been almost 7 months since rust-lang#36894 was merged, so it's time to take the next step. [breaking-change], needs crater run. PRs/issues submitted to affected crates: https://github.com/alexcrichton/ctest/pull/17 Sean1708/rusty-cheddar#55 m-r-r/helianto#3 azdle/virgil#1 rust-locale/rust-locale#24 mneumann/acyclic-network-rs#1 reem/rust-typemap#38 cc https://internals.rust-lang.org/t/moving-forward-on-forward-compatibility-lints/4204 cc rust-lang#34537 rust-lang#36887 Closes rust-lang#36886 Closes rust-lang#36888 Closes rust-lang#36890 Closes rust-lang#36891 Closes rust-lang#36892 r? @nikomatsakis
I'm also curious as to what the issue is for default type arguments in generic functions. I'm running into a case where it would greatly help ergonomics of using a function with an optional generic parameter: https://is.gd/Gy9bXW |
…um`, `type`, or `trait` definitions --> cli/src/trusted_operation.rs:44:41 | 44 | pub(crate) fn perform_trusted_operation<TG = TrustedGetter>( | ^^^^^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #36887 <rust-lang/rust#36887> = note: `#[deny(invalid_type_param_default)]` on by default
I'd also like this restriction to be lifted for functions, especially for trait functions. It would be much more ergonomic to have an API which allows default type parameters; For example, |
It is especially usefull for optional functions: fn foo<F: Fn() -> String>(bar:Option<F>){}
fn main(){
foo(Some(|| String::new()));
foo(None)
} Here, I have to use turbofish syntax even if it is irrelevant If I do: fn foo<F: Fn() -> String=fn() -> String>(bar:Option<F>){}
fn main(){
foo(Some(|| String::new()));
foo(None)
} Now it compiles ! |
I have to wonder how much time this would have saved people if it was like this from the start. |
And in essence, this is just a hint for the compiler saying "instead of raising |
Default type parameters on functions are not completely ignored. Inference doesn't fallback to them just like default type parameters elsewhere, and there are less workarounds because you can't name the types of functions items. #[allow(invalid_type_param_default)]
fn partial_default<T, U: Default = String>() -> U {
U::default()
}
fn main() {
let x = partial_default::<()>();
println!("{}", std::any::type_name_of_val(&x));
} Because if you have one or more non-defaulted parameters, you can omit defaulted parameters in a turbofish, and (unlike when all parameters are elided / when there is no turbofish), the elided parameters will take on their default values instead of being inference variables. This is required for things like |
… r=<try> WIP: make invalid_type_param_default a hard error Cc rust-lang#36887 `@rust-lang/types` I assume the plan is still to disallow this? It has been a future-compat lint for a long time, seems ripe to go for hard error. This should be cratered. (But I can also make it `FutureReleaseErrorReportInDeps` first if you prefer.)
FWIW I did a crater run in #127655 and there's still quite a few crates affected by this lint -- mostly because of |
…t, r=compiler-errors turn `invalid_type_param_default` into a `FutureReleaseErrorReportInDeps` `@rust-lang/types` I assume the plan is still to disallow this? It has been a future-compat lint for a long time, seems ripe to go for hard error. However, turns out that outright removing it right now would lead to [tons of crater regressions](rust-lang#127655 (comment)), so for now this PR just makes this future-compat lint show up in cargo's reports, so people are warned when they use a dependency that is affected by this. Fixes rust-lang#27336 by removing the feature gate (so there's no way to silence the lint even on nightly) CC rust-lang#36887
…t, r=compiler-errors turn `invalid_type_param_default` into a `FutureReleaseErrorReportInDeps` ``@rust-lang/types`` I assume the plan is still to disallow this? It has been a future-compat lint for a long time, seems ripe to go for hard error. However, turns out that outright removing it right now would lead to [tons of crater regressions](rust-lang#127655 (comment)), so for now this PR just makes this future-compat lint show up in cargo's reports, so people are warned when they use a dependency that is affected by this. Fixes rust-lang#27336 by removing the feature gate (so there's no way to silence the lint even on nightly) CC rust-lang#36887
…t, r=compiler-errors turn `invalid_type_param_default` into a `FutureReleaseErrorReportInDeps` ```@rust-lang/types``` I assume the plan is still to disallow this? It has been a future-compat lint for a long time, seems ripe to go for hard error. However, turns out that outright removing it right now would lead to [tons of crater regressions](rust-lang#127655 (comment)), so for now this PR just makes this future-compat lint show up in cargo's reports, so people are warned when they use a dependency that is affected by this. Fixes rust-lang#27336 by removing the feature gate (so there's no way to silence the lint even on nightly) CC rust-lang#36887
…t, r=compiler-errors turn `invalid_type_param_default` into a `FutureReleaseErrorReportInDeps` ````@rust-lang/types```` I assume the plan is still to disallow this? It has been a future-compat lint for a long time, seems ripe to go for hard error. However, turns out that outright removing it right now would lead to [tons of crater regressions](rust-lang#127655 (comment)), so for now this PR just makes this future-compat lint show up in cargo's reports, so people are warned when they use a dependency that is affected by this. Fixes rust-lang#27336 by removing the feature gate (so there's no way to silence the lint even on nightly) CC rust-lang#36887
…t, r=compiler-errors turn `invalid_type_param_default` into a `FutureReleaseErrorReportInDeps` `````@rust-lang/types````` I assume the plan is still to disallow this? It has been a future-compat lint for a long time, seems ripe to go for hard error. However, turns out that outright removing it right now would lead to [tons of crater regressions](rust-lang#127655 (comment)), so for now this PR just makes this future-compat lint show up in cargo's reports, so people are warned when they use a dependency that is affected by this. Fixes rust-lang#27336 by removing the feature gate (so there's no way to silence the lint even on nightly) CC rust-lang#36887
Rollup merge of rust-lang#127655 - RalfJung:invalid_type_param_default, r=compiler-errors turn `invalid_type_param_default` into a `FutureReleaseErrorReportInDeps` `````@rust-lang/types````` I assume the plan is still to disallow this? It has been a future-compat lint for a long time, seems ripe to go for hard error. However, turns out that outright removing it right now would lead to [tons of crater regressions](rust-lang#127655 (comment)), so for now this PR just makes this future-compat lint show up in cargo's reports, so people are warned when they use a dependency that is affected by this. Fixes rust-lang#27336 by removing the feature gate (so there's no way to silence the lint even on nightly) CC rust-lang#36887
Similar problem for things like |
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. use euclid::UnknownUnit;
// Equivalent to
// `type Point2D<T> = euclid::Point<T, UnknownUnit>;`
use euclid::default::Point2D;
pub fn my_silly_point<U>() -> euclid::Point2D<i32, U> {
Point2D::new(42, 21)
}
pub fn also_my_silly_point() -> Point2D<i32> {
my_silly_point()
}
fn no_units_pls() {
let leaky_implementation_details = my_silly_point::<UnknownUnit>();
let strange_and_awkward = my_silly_point::<()>();
let but_i_can = also_my_silly_point();
}
fn im_already_using_units() {
struct ScreenSpace;
let center = euclid::Point2D::<i32, ScreenSpace>::new(2560, 1440) / 2;
let i_can = center - my_silly_point();
let but_i_have_to = center - also_my_silly_point().cast_unit();
let or_maybe_for_some_reason = center - euclid::Point2D::from_untyped(also_my_silly_point());
} I don't know why |
Yeah default type params in type aliases are common. AFAIK they do not cause any kind of inference fallback so they do not share the issues of what is being tracked here.
So for code that currently hits this future compat error, that seems like a good thing to migrate to.
|
invalid_type_param_default
compatibility lintinvalid_type_param_default
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:
When 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
invalid_type_param_default
lint as warn-by-defaultinvalid_type_param_default
lint deny-by-defaultinvalid_type_param_default
lint a hard error, but there was still too much breakageinvalid_type_param_default
into 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 insteadinvalid_type_param_default
lint a hard errorThe text was updated successfully, but these errors were encountered: