]> git.lizzy.rs Git - rust.git/commitdiff
Add warning cycle #42238.
authorMasaki Hara <ackie.h.gmai@gmail.com>
Fri, 26 May 2017 13:20:53 +0000 (22:20 +0900)
committerMasaki Hara <ackie.h.gmai@gmail.com>
Fri, 26 May 2017 13:21:46 +0000 (22:21 +0900)
src/librustc/lint/builtin.rs
src/librustc_lint/lib.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/mod.rs
src/test/compile-fail/issue-32995-2.rs
src/test/compile-fail/issue-32995.rs

index e681d55cf94b893db2fd37f65eb7e5a422bc4dda..f08c37b773af948a3c1e15287337fafce43fd15d 100644 (file)
     "detects missing fragment specifiers in unused `macro_rules!` patterns"
 }
 
+declare_lint! {
+    pub PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
+    Warn,
+    "detects parenthesized generic parameters in type and module names"
+}
+
 declare_lint! {
     pub DEPRECATED,
     Warn,
@@ -286,6 +292,7 @@ fn get_lints(&self) -> LintArray {
             LEGACY_IMPORTS,
             LEGACY_CONSTRUCTOR_VISIBILITY,
             MISSING_FRAGMENT_SPECIFIER,
+            PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
             DEPRECATED
         )
     }
index 53ea3a8333f2d761c8027d1d9295ac87829d7d1d..8ff2439b6e9f87b3af9f3813db80a7a0584bcf7b 100644 (file)
@@ -250,6 +250,10 @@ macro_rules! add_lint_group {
             id: LintId::of(MISSING_FRAGMENT_SPECIFIER),
             reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
         },
+        FutureIncompatibleInfo {
+            id: LintId::of(PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES),
+            reference: "issue #42238 <https://github.com/rust-lang/rust/issues/42238>",
+        },
         FutureIncompatibleInfo {
             id: LintId::of(ANONYMOUS_PARAMETERS),
             reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",
index d8a3ebe063a4560f3ec56e8321bd74591c2d4ca5..7c013e91e5f7b7779aacb1abaf7558a7cbf6e53b 100644 (file)
@@ -22,6 +22,7 @@
 use rustc::traits;
 use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
 use rustc::ty::wf::object_region_bounds;
+use rustc::lint::builtin::PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES;
 use rustc_back::slice;
 use require_c_abi_if_variadic;
 use util::common::{ErrorReported, FN_OUTPUT_NAME};
@@ -161,7 +162,7 @@ pub fn ast_path_substs_for_ty(&self,
         match item_segment.parameters {
             hir::AngleBracketedParameters(_) => {}
             hir::ParenthesizedParameters(..) => {
-                self.prohibit_parenthesized_params(item_segment);
+                self.prohibit_parenthesized_params(item_segment, true);
 
                 return Substs::for_item(tcx, def_id, |_, _| {
                     tcx.types.re_static
@@ -957,7 +958,7 @@ fn qpath_to_ty(&self,
     pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) {
         for segment in segments {
             if let hir::ParenthesizedParameters(_) = segment.parameters {
-                self.prohibit_parenthesized_params(segment);
+                self.prohibit_parenthesized_params(segment, false);
                 break;
             }
             for typ in segment.parameters.types() {
@@ -982,12 +983,18 @@ pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) {
         }
     }
 
-    pub fn prohibit_parenthesized_params(&self, segment: &hir::PathSegment) {
+    pub fn prohibit_parenthesized_params(&self, segment: &hir::PathSegment, emit_error: bool) {
         if let hir::ParenthesizedParameters(ref data) = segment.parameters {
-            struct_span_err!(self.tcx().sess, data.span, E0214,
-                      "parenthesized parameters may only be used with a trait")
-                .span_label(data.span, "only traits may use parentheses")
-                .emit();
+            if emit_error {
+                struct_span_err!(self.tcx().sess, data.span, E0214,
+                          "parenthesized parameters may only be used with a trait")
+                    .span_label(data.span, "only traits may use parentheses")
+                    .emit();
+            } else {
+                let msg = "parenthesized parameters may only be used with a trait".to_string();
+                self.tcx().sess.add_lint(PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
+                                         ast::CRATE_NODE_ID, data.span, msg);
+            }
         }
     }
 
index 05594cff8a02e2c1cb26894c2cd9c742534fe21d..ea4a78eaf296b0b209b7eda0684625d961a5ec6b 100644 (file)
@@ -4495,7 +4495,8 @@ fn check_path_parameter_count(&self,
                     (&data.lifetimes[..], &data.types[..], data.infer_types, &data.bindings[..])
                 }
                 Some(&hir::ParenthesizedParameters(_)) => {
-                    AstConv::prohibit_parenthesized_params(self, &segment.as_ref().unwrap().0);
+                    AstConv::prohibit_parenthesized_params(self, &segment.as_ref().unwrap().0,
+                                                           false);
                     (&[][..], &[][..], true, &[][..])
                 }
                 None => (&[][..], &[][..], true, &[][..])
index 80113d3b4ec73e15c200f1ca091138b0b6200f8a..cb68d52ef968df73dcdca2aaffdf22d690071cd5 100644 (file)
@@ -8,14 +8,23 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![deny(parenthesized_params_in_types_and_modules)]
+//~^ NOTE lint level defined here
+//~| NOTE lint level defined here
+//~| NOTE lint level defined here
+#![allow(dead_code, unused_variables)]
 #![feature(conservative_impl_trait)]
 
 fn main() {
     { fn f<X: ::std::marker()::Send>() {} }
     //~^ ERROR parenthesized parameters may only be used with a trait
+    //~| WARN previously accepted
+    //~| NOTE issue #42238
 
     { fn f() -> impl ::std::marker()::Send { } }
     //~^ ERROR parenthesized parameters may only be used with a trait
+    //~| WARN previously accepted
+    //~| NOTE issue #42238
 }
 
 #[derive(Clone)]
@@ -23,3 +32,5 @@ fn main() {
 
 impl ::std::marker()::Copy for X {}
 //~^ ERROR parenthesized parameters may only be used with a trait
+//~| WARN previously accepted
+//~| NOTE issue #42238
index d38bec455134e896ae7a4870ee164db6ef43f27d..f2ed8bf53eade23ad61283f4c72ba3ede9736601 100644 (file)
@@ -8,15 +8,26 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-fn main() {
-    let s: String() = String::from("foo");
-    //~^ ERROR parenthesized parameters may only be used with a trait
+#![deny(parenthesized_params_in_types_and_modules)]
+//~^ NOTE lint level defined here
+//~| NOTE lint level defined here
+//~| NOTE lint level defined here
+//~| NOTE lint level defined here
+//~| NOTE lint level defined here
+//~| NOTE lint level defined here
+//~| NOTE lint level defined here
+#![allow(dead_code, unused_variables)]
 
+fn main() {
     let x: usize() = 1;
     //~^ ERROR parenthesized parameters may only be used with a trait
+    //~| WARN previously accepted
+    //~| NOTE issue #42238
 
     let b: ::std::boxed()::Box<_> = Box::new(1);
     //~^ ERROR parenthesized parameters may only be used with a trait
+    //~| WARN previously accepted
+    //~| NOTE issue #42238
 
     macro_rules! pathexpr {
         ($p:path) => { $p }
@@ -24,18 +35,28 @@ macro_rules! pathexpr {
 
     let p = pathexpr!(::std::str()::from_utf8)(b"foo").unwrap();
     //~^ ERROR parenthesized parameters may only be used with a trait
+    //~| WARN previously accepted
+    //~| NOTE issue #42238
 
     let p = pathexpr!(::std::str::from_utf8())(b"foo").unwrap();
     //~^ ERROR parenthesized parameters may only be used with a trait
+    //~| WARN previously accepted
+    //~| NOTE issue #42238
 
     let o : Box<::std::marker()::Send> = Box::new(1);
     //~^ ERROR parenthesized parameters may only be used with a trait
+    //~| WARN previously accepted
+    //~| NOTE issue #42238
 
     let o : Box<Send + ::std::marker()::Sync> = Box::new(1);
     //~^ ERROR parenthesized parameters may only be used with a trait
+    //~| WARN previously accepted
+    //~| NOTE issue #42238
 }
 
 fn foo<X:Default>() {
     let d : X() = Default::default();
     //~^ ERROR parenthesized parameters may only be used with a trait
+    //~| WARN previously accepted
+    //~| NOTE issue #42238
 }