diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 5a88731f16c38..736c3b289e198 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -130,6 +130,12 @@ declare_lint! { "detect private items in public interfaces not caught by the old implementation" } +declare_lint! { + pub INVALID_TYPE_PARAM_DEFAULT, + Deny, + "type parameter default erroneously allowed in invalid location" +} + declare_lint! { pub RENAMED_AND_REMOVED_LINTS, Warn, @@ -224,6 +230,7 @@ impl LintPass for HardwiredLints { TRIVIAL_CASTS, TRIVIAL_NUMERIC_CASTS, PRIVATE_IN_PUBLIC, + INVALID_TYPE_PARAM_DEFAULT, CONST_ERR, RENAMED_AND_REMOVED_LINTS, RESOLVE_TRAIT_ON_DEFAULTED_UNIT, diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index a5b1d39dd869e..9870842a28e38 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -196,6 +196,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { id: LintId::of(SAFE_EXTERN_STATICS), reference: "issue #36247 ", }, + FutureIncompatibleInfo { + id: LintId::of(INVALID_TYPE_PARAM_DEFAULT), + reference: "issue #36887 ", + }, FutureIncompatibleInfo { id: LintId::of(EXTRA_REQUIREMENT_IN_IMPL), reference: "issue #37166 ", @@ -251,8 +255,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { "converted into hard error, see https://github.com/rust-lang/rust/issues/33685"); store.register_removed("inaccessible_extern_crate", "converted into hard error, see https://github.com/rust-lang/rust/issues/36886"); - store.register_removed("invalid_type_param_default", - "converted into hard error, see https://github.com/rust-lang/rust/issues/36887"); store.register_removed("super_or_self_in_global_path", "converted into hard error, see https://github.com/rust-lang/rust/issues/36888"); store.register_removed("overlapping_inherent_impls", diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index d7813efdd2fba..fb3bcd31e21fc 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -54,6 +54,7 @@ There are some shortcomings in this design: */ use astconv::{AstConv, Bounds}; +use lint; use constrained_type_params as ctp; use middle::lang_items::SizedTraitLangItem; use middle::const_val::ConstVal; @@ -896,8 +897,12 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if !allow_defaults && p.default.is_some() { if !tcx.sess.features.borrow().default_type_parameter_fallback { - tcx.sess.span_err(p.span, "defaults for type parameters are only allowed in \ - `struct`, `enum`, `type`, or `trait` definitions."); + tcx.sess.add_lint( + lint::builtin::INVALID_TYPE_PARAM_DEFAULT, + p.id, + p.span, + format!("defaults for type parameters are only allowed in `struct`, \ + `enum`, `type`, or `trait` definitions.")); } } diff --git a/src/test/compile-fail/type-parameter-invalid-lint.rs b/src/test/compile-fail/type-parameter-invalid-lint.rs index eea6f22644b69..c7a1197372dee 100644 --- a/src/test/compile-fail/type-parameter-invalid-lint.rs +++ b/src/test/compile-fail/type-parameter-invalid-lint.rs @@ -10,11 +10,16 @@ // gate-test-default_type_parameter_fallback +#![deny(invalid_type_param_default)] +#![allow(unused)] + fn avg(_: T) {} //~^ ERROR defaults for type parameters are only allowed +//~| WARN this was previously accepted struct S(T); impl S {} //~^ ERROR defaults for type parameters are only allowed +//~| WARN this was previously accepted fn main() {}