Skip to content

Commit b572e84

Browse files
authored
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
2 parents ebd08d8 + 9d9b55c commit b572e84

12 files changed

+115
-30
lines changed

Diff for: compiler/rustc_feature/src/removed.rs

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ declare_features! (
8282
/// Allows the use of `#[derive(Anything)]` as sugar for `#[derive_Anything]`.
8383
(removed, custom_derive, "1.32.0", Some(29644),
8484
Some("subsumed by `#[proc_macro_derive]`")),
85+
/// Allows default type parameters to influence type inference.
86+
(removed, default_type_parameter_fallback, "CURRENT_RUSTC_VERSION", Some(27336),
87+
Some("never properly implemented; requires significant design work")),
8588
/// Allows using `#[doc(keyword = "...")]`.
8689
(removed, doc_keyword, "1.28.0", Some(51315),
8790
Some("merged into `#![feature(rustdoc_internals)]`")),

Diff for: compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ declare_features! (
431431
(unstable, custom_test_frameworks, "1.30.0", Some(50297)),
432432
/// Allows declarative macros 2.0 (`macro`).
433433
(unstable, decl_macro, "1.17.0", Some(39412)),
434-
/// Allows default type parameters to influence type inference.
435-
(unstable, default_type_parameter_fallback, "1.3.0", Some(27336)),
436434
/// Allows using `#[deprecated_safe]` to deprecate the safeness of a function or trait
437435
(unstable, deprecated_safe, "1.61.0", Some(94978)),
438436
/// Allows having using `suggestion` in the `#[deprecated]` attribute.

Diff for: compiler/rustc_hir_analysis/src/collect/generics_of.rs

-2
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
338338
if default.is_some() {
339339
match allow_defaults {
340340
Defaults::Allowed => {}
341-
Defaults::FutureCompatDisallowed
342-
if tcx.features().default_type_parameter_fallback => {}
343341
Defaults::FutureCompatDisallowed => {
344342
tcx.node_span_lint(
345343
lint::builtin::INVALID_TYPE_PARAM_DEFAULT,

Diff for: compiler/rustc_lint_defs/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ declare_lint! {
12671267
Deny,
12681268
"type parameter default erroneously allowed in invalid location",
12691269
@future_incompatible = FutureIncompatibleInfo {
1270-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
1270+
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
12711271
reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
12721272
};
12731273
}

Diff for: tests/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr

-21
This file was deleted.

Diff for: tests/ui/impl-trait/where-allowed.stderr

+22
Original file line numberDiff line numberDiff line change
@@ -433,3 +433,25 @@ error: aborting due to 50 previous errors
433433

434434
Some errors have detailed explanations: E0053, E0118, E0283, E0562, E0599, E0658, E0666.
435435
For more information about an error, try `rustc --explain E0053`.
436+
Future incompatibility report: Future breakage diagnostic:
437+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
438+
--> $DIR/where-allowed.rs:239:7
439+
|
440+
LL | impl <T = impl Debug> T {}
441+
| ^^^^^^^^^^^^^^
442+
|
443+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
444+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
445+
= note: `#[deny(invalid_type_param_default)]` on by default
446+
447+
Future breakage diagnostic:
448+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
449+
--> $DIR/where-allowed.rs:246:36
450+
|
451+
LL | fn in_method_generic_param_default<T = impl Debug>(_: T) {}
452+
| ^^^^^^^^^^^^^^
453+
|
454+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
455+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
456+
= note: `#[deny(invalid_type_param_default)]` on by default
457+

Diff for: tests/ui/issues/issue-26812.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#![feature(default_type_parameter_fallback)]
2-
31
fn avg<T=T::Item>(_: T) {}
42
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
3+
//~| ERROR defaults for type parameters
4+
//~| WARN previously accepted
55

66
fn main() {}

Diff for: tests/ui/issues/issue-26812.stderr

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
error[E0128]: generic parameters with a default cannot use forward declared identifiers
2-
--> $DIR/issue-26812.rs:3:10
2+
--> $DIR/issue-26812.rs:1:10
33
|
44
LL | fn avg<T=T::Item>(_: T) {}
55
| ^^^^^^^ defaulted generic parameters cannot be forward declared
66

7-
error: aborting due to 1 previous error
7+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
8+
--> $DIR/issue-26812.rs:1:8
9+
|
10+
LL | fn avg<T=T::Item>(_: T) {}
11+
| ^^^^^^^^^
12+
|
13+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
14+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
15+
= note: `#[deny(invalid_type_param_default)]` on by default
16+
17+
error: aborting due to 2 previous errors
818

919
For more information about this error, try `rustc --explain E0128`.
20+
Future incompatibility report: Future breakage diagnostic:
21+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
22+
--> $DIR/issue-26812.rs:1:8
23+
|
24+
LL | fn avg<T=T::Item>(_: T) {}
25+
| ^^^^^^^^^
26+
|
27+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
28+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
29+
= note: `#[deny(invalid_type_param_default)]` on by default
30+

Diff for: tests/ui/lifetimes/unusual-rib-combinations.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ error: aborting due to 8 previous errors
7272

7373
Some errors have detailed explanations: E0106, E0214, E0308, E0770.
7474
For more information about an error, try `rustc --explain E0106`.
75+
Future incompatibility report: Future breakage diagnostic:
76+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
77+
--> $DIR/unusual-rib-combinations.rs:15:6
78+
|
79+
LL | fn c<T = u8()>() {}
80+
| ^^^^^^^^
81+
|
82+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
83+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
84+
= note: `#[deny(invalid_type_param_default)]` on by default
85+

Diff for: tests/ui/type-inference/unbounded-type-param-in-fn-with-assoc-type.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ LL | foo::<T, U>();
1212
error: aborting due to 1 previous error
1313

1414
For more information about this error, try `rustc --explain E0282`.
15+
Future incompatibility report: Future breakage diagnostic:
16+
warning: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
17+
--> $DIR/unbounded-type-param-in-fn-with-assoc-type.rs:3:11
18+
|
19+
LL | fn foo<T, U = u64>() -> (T, U) {
20+
| ^^^^^^^
21+
|
22+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
23+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
24+
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
2+
--> $DIR/default_type_parameter_in_fn_or_impl.rs:3:8
3+
|
4+
LL | fn avg<T=i32>(_: T) {}
5+
| ^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
9+
= note: `#[deny(invalid_type_param_default)]` on by default
10+
11+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
12+
--> $DIR/default_type_parameter_in_fn_or_impl.rs:8:6
13+
|
14+
LL | impl<T=i32> S<T> {}
15+
| ^^^^^
16+
|
17+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
19+
20+
error: aborting due to 2 previous errors
21+
22+
Future incompatibility report: Future breakage diagnostic:
23+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
24+
--> $DIR/default_type_parameter_in_fn_or_impl.rs:3:8
25+
|
26+
LL | fn avg<T=i32>(_: T) {}
27+
| ^^^^^
28+
|
29+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
30+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
31+
= note: `#[deny(invalid_type_param_default)]` on by default
32+
33+
Future breakage diagnostic:
34+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
35+
--> $DIR/default_type_parameter_in_fn_or_impl.rs:8:6
36+
|
37+
LL | impl<T=i32> S<T> {}
38+
| ^^^^^
39+
|
40+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
41+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
42+
= note: `#[deny(invalid_type_param_default)]` on by default
43+

0 commit comments

Comments
 (0)