From 99993780dc2db803877ed700cbf315246fc3ad7f Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Fri, 26 May 2017 22:20:53 +0900 Subject: [PATCH] Add warning cycle #42238. --- src/librustc/lint/builtin.rs | 7 +++++++ src/librustc_lint/lib.rs | 4 ++++ src/librustc_typeck/astconv.rs | 21 +++++++++++++------- src/librustc_typeck/check/mod.rs | 3 ++- src/test/compile-fail/issue-32995-2.rs | 11 +++++++++++ src/test/compile-fail/issue-32995.rs | 27 +++++++++++++++++++++++--- 6 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index e681d55cf94..f08c37b773a 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -236,6 +236,12 @@ "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 ) } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 53ea3a8333f..8ff2439b6e9 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -250,6 +250,10 @@ macro_rules! add_lint_group { id: LintId::of(MISSING_FRAGMENT_SPECIFIER), reference: "issue #40107 ", }, + FutureIncompatibleInfo { + id: LintId::of(PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES), + reference: "issue #42238 ", + }, FutureIncompatibleInfo { id: LintId::of(ANONYMOUS_PARAMETERS), reference: "issue #41686 ", diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index d8a3ebe063a..7c013e91e5f 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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); + } } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 05594cff8a0..ea4a78eaf29 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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, &[][..]) diff --git a/src/test/compile-fail/issue-32995-2.rs b/src/test/compile-fail/issue-32995-2.rs index 80113d3b4ec..cb68d52ef96 100644 --- a/src/test/compile-fail/issue-32995-2.rs +++ b/src/test/compile-fail/issue-32995-2.rs @@ -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() {} } //~^ 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 diff --git a/src/test/compile-fail/issue-32995.rs b/src/test/compile-fail/issue-32995.rs index d38bec45513..f2ed8bf53ea 100644 --- a/src/test/compile-fail/issue-32995.rs +++ b/src/test/compile-fail/issue-32995.rs @@ -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 = Box::new(1); //~^ ERROR parenthesized parameters may only be used with a trait + //~| WARN previously accepted + //~| NOTE issue #42238 } fn foo() { let d : X() = Default::default(); //~^ ERROR parenthesized parameters may only be used with a trait + //~| WARN previously accepted + //~| NOTE issue #42238 } -- 2.44.0