Skip to content

Commit

Permalink
Auto merge of #127655 - RalfJung:invalid_type_param_default, r=<try>
Browse files Browse the repository at this point in the history
WIP: make invalid_type_param_default a hard error

Cc #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.)
  • Loading branch information
bors committed Jul 12, 2024
2 parents b286722 + 4282f48 commit 6a57490
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
enum Defaults {
Allowed,
// See #36887
#[allow(dead_code)] // FIXME remove if the PR moves forward
FutureCompatDisallowed,
Deny,
}
Expand Down Expand Up @@ -262,7 +263,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
| ItemKind::OpaqueTy(..)
| ItemKind::Union(..) => (None, Defaults::Allowed),
ItemKind::Const(..) => (None, Defaults::Deny),
_ => (None, Defaults::FutureCompatDisallowed),
_ => (None, Defaults::Deny),
}
}

Expand All @@ -274,7 +275,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
(None, Defaults::Deny)
}

_ => (None, Defaults::FutureCompatDisallowed),
_ => (None, Defaults::Deny),
};

let has_self = opt_self.is_some();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

fn avg<T=i32>(_: T) {}
//~^ ERROR defaults for type parameters are only allowed
//~| WARN this was previously accepted

struct S<T>(T);
impl<T=i32> S<T> {}
//~^ ERROR defaults for type parameters are only allowed
//~| WARN this was previously accepted

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type`
|
LL | fn avg<T=i32>(_: T) {}
| ^^^^^
|
= 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 <https://github.com/rust-lang/rust/issues/36887>
= note: `#[deny(invalid_type_param_default)]` on by default

error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
--> $DIR/feature-gate-default_type_parameter_fallback.rs:8:6
--> $DIR/feature-gate-default_type_parameter_fallback.rs:7:6
|
LL | impl<T=i32> S<T> {}
| ^^^^^
|
= 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 <https://github.com/rust-lang/rust/issues/36887>

error: aborting due to 2 previous errors

0 comments on commit 6a57490

Please sign in to comment.