Skip to content

Commit 26d5c0e

Browse files
committed
Turn invalid_type_param_default into a lint again
1 parent d73a0fe commit 26d5c0e

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/librustc/lint/builtin.rs

+7
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ declare_lint! {
130130
"detect private items in public interfaces not caught by the old implementation"
131131
}
132132

133+
declare_lint! {
134+
pub INVALID_TYPE_PARAM_DEFAULT,
135+
Deny,
136+
"type parameter default erroneously allowed in invalid location"
137+
}
138+
133139
declare_lint! {
134140
pub RENAMED_AND_REMOVED_LINTS,
135141
Warn,
@@ -224,6 +230,7 @@ impl LintPass for HardwiredLints {
224230
TRIVIAL_CASTS,
225231
TRIVIAL_NUMERIC_CASTS,
226232
PRIVATE_IN_PUBLIC,
233+
INVALID_TYPE_PARAM_DEFAULT,
227234
CONST_ERR,
228235
RENAMED_AND_REMOVED_LINTS,
229236
RESOLVE_TRAIT_ON_DEFAULTED_UNIT,

src/librustc_lint/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
196196
id: LintId::of(SAFE_EXTERN_STATICS),
197197
reference: "issue #36247 <https://github.com/rust-lang/rust/issues/36247>",
198198
},
199+
FutureIncompatibleInfo {
200+
id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
201+
reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
202+
},
199203
FutureIncompatibleInfo {
200204
id: LintId::of(EXTRA_REQUIREMENT_IN_IMPL),
201205
reference: "issue #37166 <https://github.com/rust-lang/rust/issues/37166>",
@@ -251,8 +255,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
251255
"converted into hard error, see https://github.com/rust-lang/rust/issues/33685");
252256
store.register_removed("inaccessible_extern_crate",
253257
"converted into hard error, see https://github.com/rust-lang/rust/issues/36886");
254-
store.register_removed("invalid_type_param_default",
255-
"converted into hard error, see https://github.com/rust-lang/rust/issues/36887");
256258
store.register_removed("super_or_self_in_global_path",
257259
"converted into hard error, see https://github.com/rust-lang/rust/issues/36888");
258260
store.register_removed("overlapping_inherent_impls",

src/librustc_typeck/collect.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ There are some shortcomings in this design:
5454
*/
5555

5656
use astconv::{AstConv, Bounds};
57+
use lint;
5758
use constrained_type_params as ctp;
5859
use middle::lang_items::SizedTraitLangItem;
5960
use middle::const_val::ConstVal;
@@ -896,8 +897,12 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
896897

897898
if !allow_defaults && p.default.is_some() {
898899
if !tcx.sess.features.borrow().default_type_parameter_fallback {
899-
tcx.sess.span_err(p.span, "defaults for type parameters are only allowed in \
900-
`struct`, `enum`, `type`, or `trait` definitions.");
900+
tcx.sess.add_lint(
901+
lint::builtin::INVALID_TYPE_PARAM_DEFAULT,
902+
p.id,
903+
p.span,
904+
format!("defaults for type parameters are only allowed in `struct`, \
905+
`enum`, `type`, or `trait` definitions."));
901906
}
902907
}
903908

src/test/compile-fail/type-parameter-invalid-lint.rs

+5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010

1111
// gate-test-default_type_parameter_fallback
1212

13+
#![deny(invalid_type_param_default)]
14+
#![allow(unused)]
15+
1316
fn avg<T=i32>(_: T) {}
1417
//~^ ERROR defaults for type parameters are only allowed
18+
//~| WARN this was previously accepted
1519

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

2025
fn main() {}

0 commit comments

Comments
 (0)