Skip to content

Commit

Permalink
make invalid_type_param_default a hard error
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Jul 12, 2024
1 parent b286722 commit 4282f48
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 4282f48

Please sign in to comment.