From 26d5c0e20cbdd27af12a756ddfb1758d0888aad3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 27 May 2017 01:52:25 +0300 Subject: [PATCH] Turn `invalid_type_param_default` into a lint again --- src/librustc/lint/builtin.rs | 7 +++++++ src/librustc_lint/lib.rs | 6 ++++-- src/librustc_typeck/collect.rs | 9 +++++++-- src/test/compile-fail/type-parameter-invalid-lint.rs | 5 +++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 5a88731f16c..736c3b289e1 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -130,6 +130,12 @@ "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 @@ fn get_lints(&self) -> LintArray { 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 a5b1d39dd86..9870842a28e 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -196,6 +196,10 @@ macro_rules! add_lint_group { 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 @@ macro_rules! add_lint_group { "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 d7813efdd2f..fb3bcd31e21 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -54,6 +54,7 @@ */ 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 eea6f22644b..c7a1197372d 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() {}