Add warning cycle #42238.

This commit is contained in:
Masaki Hara 2017-05-26 22:20:53 +09:00
parent e8137d7cea
commit 99993780dc
No known key found for this signature in database
GPG Key ID: 7CA7A85E049A82E8
6 changed files with 62 additions and 11 deletions

View File

@ -236,6 +236,12 @@ declare_lint! {
"detects missing fragment specifiers in unused `macro_rules!` patterns" "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! { declare_lint! {
pub DEPRECATED, pub DEPRECATED,
Warn, Warn,
@ -286,6 +292,7 @@ impl LintPass for HardwiredLints {
LEGACY_IMPORTS, LEGACY_IMPORTS,
LEGACY_CONSTRUCTOR_VISIBILITY, LEGACY_CONSTRUCTOR_VISIBILITY,
MISSING_FRAGMENT_SPECIFIER, MISSING_FRAGMENT_SPECIFIER,
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
DEPRECATED DEPRECATED
) )
} }

View File

@ -250,6 +250,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
id: LintId::of(MISSING_FRAGMENT_SPECIFIER), id: LintId::of(MISSING_FRAGMENT_SPECIFIER),
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>", 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 { FutureIncompatibleInfo {
id: LintId::of(ANONYMOUS_PARAMETERS), id: LintId::of(ANONYMOUS_PARAMETERS),
reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>", reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",

View File

@ -22,6 +22,7 @@ use rustc::ty::subst::{Kind, Subst, Substs};
use rustc::traits; use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable}; use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
use rustc::ty::wf::object_region_bounds; use rustc::ty::wf::object_region_bounds;
use rustc::lint::builtin::PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES;
use rustc_back::slice; use rustc_back::slice;
use require_c_abi_if_variadic; use require_c_abi_if_variadic;
use util::common::{ErrorReported, FN_OUTPUT_NAME}; use util::common::{ErrorReported, FN_OUTPUT_NAME};
@ -161,7 +162,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
match item_segment.parameters { match item_segment.parameters {
hir::AngleBracketedParameters(_) => {} hir::AngleBracketedParameters(_) => {}
hir::ParenthesizedParameters(..) => { hir::ParenthesizedParameters(..) => {
self.prohibit_parenthesized_params(item_segment); self.prohibit_parenthesized_params(item_segment, true);
return Substs::for_item(tcx, def_id, |_, _| { return Substs::for_item(tcx, def_id, |_, _| {
tcx.types.re_static tcx.types.re_static
@ -957,7 +958,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) { pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) {
for segment in segments { for segment in segments {
if let hir::ParenthesizedParameters(_) = segment.parameters { if let hir::ParenthesizedParameters(_) = segment.parameters {
self.prohibit_parenthesized_params(segment); self.prohibit_parenthesized_params(segment, false);
break; break;
} }
for typ in segment.parameters.types() { for typ in segment.parameters.types() {
@ -982,12 +983,18 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
} }
} }
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 { if let hir::ParenthesizedParameters(ref data) = segment.parameters {
struct_span_err!(self.tcx().sess, data.span, E0214, if emit_error {
"parenthesized parameters may only be used with a trait") struct_span_err!(self.tcx().sess, data.span, E0214,
.span_label(data.span, "only traits may use parentheses") "parenthesized parameters may only be used with a trait")
.emit(); .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);
}
} }
} }

View File

@ -4495,7 +4495,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
(&data.lifetimes[..], &data.types[..], data.infer_types, &data.bindings[..]) (&data.lifetimes[..], &data.types[..], data.infer_types, &data.bindings[..])
} }
Some(&hir::ParenthesizedParameters(_)) => { 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, &[][..]) (&[][..], &[][..], true, &[][..])
} }
None => (&[][..], &[][..], true, &[][..]) None => (&[][..], &[][..], true, &[][..])

View File

@ -8,14 +8,23 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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)] #![feature(conservative_impl_trait)]
fn main() { fn main() {
{ fn f<X: ::std::marker()::Send>() {} } { fn f<X: ::std::marker()::Send>() {} }
//~^ ERROR parenthesized parameters may only be used with a trait //~^ ERROR parenthesized parameters may only be used with a trait
//~| WARN previously accepted
//~| NOTE issue #42238
{ fn f() -> impl ::std::marker()::Send { } } { fn f() -> impl ::std::marker()::Send { } }
//~^ ERROR parenthesized parameters may only be used with a trait //~^ ERROR parenthesized parameters may only be used with a trait
//~| WARN previously accepted
//~| NOTE issue #42238
} }
#[derive(Clone)] #[derive(Clone)]
@ -23,3 +32,5 @@ struct X;
impl ::std::marker()::Copy for X {} impl ::std::marker()::Copy for X {}
//~^ ERROR parenthesized parameters may only be used with a trait //~^ ERROR parenthesized parameters may only be used with a trait
//~| WARN previously accepted
//~| NOTE issue #42238

View File

@ -8,15 +8,26 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
fn main() { #![deny(parenthesized_params_in_types_and_modules)]
let s: String() = String::from("foo"); //~^ NOTE lint level defined here
//~^ ERROR parenthesized parameters may only be used with a trait //~| 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; let x: usize() = 1;
//~^ ERROR parenthesized parameters may only be used with a trait //~^ ERROR parenthesized parameters may only be used with a trait
//~| WARN previously accepted
//~| NOTE issue #42238
let b: ::std::boxed()::Box<_> = Box::new(1); let b: ::std::boxed()::Box<_> = Box::new(1);
//~^ ERROR parenthesized parameters may only be used with a trait //~^ ERROR parenthesized parameters may only be used with a trait
//~| WARN previously accepted
//~| NOTE issue #42238
macro_rules! pathexpr { macro_rules! pathexpr {
($p:path) => { $p } ($p:path) => { $p }
@ -24,18 +35,28 @@ fn main() {
let p = pathexpr!(::std::str()::from_utf8)(b"foo").unwrap(); let p = pathexpr!(::std::str()::from_utf8)(b"foo").unwrap();
//~^ ERROR parenthesized parameters may only be used with a trait //~^ 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(); let p = pathexpr!(::std::str::from_utf8())(b"foo").unwrap();
//~^ ERROR parenthesized parameters may only be used with a trait //~^ 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); let o : Box<::std::marker()::Send> = Box::new(1);
//~^ ERROR parenthesized parameters may only be used with a trait //~^ 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); let o : Box<Send + ::std::marker()::Sync> = Box::new(1);
//~^ ERROR parenthesized parameters may only be used with a trait //~^ ERROR parenthesized parameters may only be used with a trait
//~| WARN previously accepted
//~| NOTE issue #42238
} }
fn foo<X:Default>() { fn foo<X:Default>() {
let d : X() = Default::default(); let d : X() = Default::default();
//~^ ERROR parenthesized parameters may only be used with a trait //~^ ERROR parenthesized parameters may only be used with a trait
//~| WARN previously accepted
//~| NOTE issue #42238
} }