]> git.lizzy.rs Git - rust.git/commitdiff
convert from hard error to future-incompatible lint
authorNiko Matsakis <niko@alum.mit.edu>
Tue, 5 Jan 2016 18:43:31 +0000 (13:43 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Tue, 5 Jan 2016 21:21:53 +0000 (16:21 -0500)
src/librustc/lint/builtin.rs
src/librustc_lint/lib.rs
src/librustc_typeck/collect.rs
src/test/compile-fail/type-parameter-invalid-lint.rs [new file with mode: 0644]

index 26c38a863e22d140d4d490c6d8e02216b07f1baa..aff925d108272cb40f96dad30552e4911013300a 100644 (file)
     "detect private items in public interfaces not caught by the old implementation"
 }
 
+declare_lint! {
+    pub INVALID_TYPE_PARAM_DEFAULT,
+    Warn,
+    "type parameter default erroneously allowed in invalid location"
+}
+
 /// Does nothing as a lint pass, but registers some `Lint`s
 /// which are used by other parts of the compiler.
 #[derive(Copy, Clone)]
@@ -152,6 +158,7 @@ fn get_lints(&self) -> LintArray {
             TRIVIAL_CASTS,
             TRIVIAL_NUMERIC_CASTS,
             PRIVATE_IN_PUBLIC,
+            INVALID_TYPE_PARAM_DEFAULT,
             CONST_ERR
         )
     }
index 80ef334fe189b1790a6f1eec51bf37563177450f..f2e75960406f188e5e10309212f7c85b3a82053a 100644 (file)
@@ -143,8 +143,8 @@ macro_rules! add_lint_group {
                     UNUSED_MUT, UNREACHABLE_CODE, UNUSED_MUST_USE,
                     UNUSED_UNSAFE, PATH_STATEMENTS, UNUSED_ATTRIBUTES);
 
-    add_lint_group!(sess, "future_incompatible",
-                    PRIVATE_IN_PUBLIC);
+    add_lint_group!(sess, FUTURE_INCOMPATIBLE,
+                    PRIVATE_IN_PUBLIC, INVALID_TYPE_PARAM_DEFAULT);
 
     // We have one lint pass defined specially
     store.register_late_pass(sess, false, box lint::GatherNodeLevels);
index 2b3ee9fe6dc6663353c6706ac89e8100b35982db..a03caba2a676e90db13d2b9ca40bd63285b38a9d 100644 (file)
@@ -65,6 +65,7 @@
 */
 
 use astconv::{self, AstConv, ty_of_arg, ast_ty_to_ty, ast_region_to_region};
+use lint;
 use middle::def;
 use middle::def_id::DefId;
 use constrained_type_params as ctp;
@@ -92,7 +93,6 @@
 use syntax::ast;
 use syntax::attr;
 use syntax::codemap::Span;
-use syntax::feature_gate::{GateIssue, emit_feature_err};
 use syntax::parse::token::special_idents;
 use syntax::ptr::P;
 use rustc_front::hir;
@@ -1936,13 +1936,12 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
 
     if space != TypeSpace && default.is_some() {
         if !tcx.sess.features.borrow().default_type_parameter_fallback {
-            emit_feature_err(&tcx.sess.parse_sess.span_diagnostic,
-                             "default_type_parameter_fallback",
-                             param.span,
-                             GateIssue::Language,
-                             "other than on a `struct` or `enum` definition, \
-                              defaults for type parameters are experimental \
-                              and known to be buggy");
+            tcx.sess.add_lint(
+                lint::builtin::INVALID_TYPE_PARAM_DEFAULT,
+                param.id,
+                param.span,
+                format!("defaults for type parameters are only allowed \
+                         on `struct` or `enum` definitions (see issue #27336)"));
         }
     }
 
diff --git a/src/test/compile-fail/type-parameter-invalid-lint.rs b/src/test/compile-fail/type-parameter-invalid-lint.rs
new file mode 100644 (file)
index 0000000..a3ecbfa
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![deny(future_incompatible)]
+#![allow(dead_code)]
+
+fn avg<T=i32>(_: T) {}
+//~^ ERROR defaults for type parameters are only allowed
+//~| NOTE HARD ERROR
+fn main() {}