Skip to content

Commit 9999378

Browse files
committed
Add warning cycle #42238.
1 parent e8137d7 commit 9999378

File tree

6 files changed

+62
-11
lines changed

6 files changed

+62
-11
lines changed

Diff for: src/librustc/lint/builtin.rs

+7
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ declare_lint! {
236236
"detects missing fragment specifiers in unused `macro_rules!` patterns"
237237
}
238238

239+
declare_lint! {
240+
pub PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
241+
Warn,
242+
"detects parenthesized generic parameters in type and module names"
243+
}
244+
239245
declare_lint! {
240246
pub DEPRECATED,
241247
Warn,
@@ -286,6 +292,7 @@ impl LintPass for HardwiredLints {
286292
LEGACY_IMPORTS,
287293
LEGACY_CONSTRUCTOR_VISIBILITY,
288294
MISSING_FRAGMENT_SPECIFIER,
295+
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
289296
DEPRECATED
290297
)
291298
}

Diff for: src/librustc_lint/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
250250
id: LintId::of(MISSING_FRAGMENT_SPECIFIER),
251251
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
252252
},
253+
FutureIncompatibleInfo {
254+
id: LintId::of(PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES),
255+
reference: "issue #42238 <https://github.com/rust-lang/rust/issues/42238>",
256+
},
253257
FutureIncompatibleInfo {
254258
id: LintId::of(ANONYMOUS_PARAMETERS),
255259
reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",

Diff for: src/librustc_typeck/astconv.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc::ty::subst::{Kind, Subst, Substs};
2222
use rustc::traits;
2323
use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
2424
use rustc::ty::wf::object_region_bounds;
25+
use rustc::lint::builtin::PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES;
2526
use rustc_back::slice;
2627
use require_c_abi_if_variadic;
2728
use util::common::{ErrorReported, FN_OUTPUT_NAME};
@@ -161,7 +162,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
161162
match item_segment.parameters {
162163
hir::AngleBracketedParameters(_) => {}
163164
hir::ParenthesizedParameters(..) => {
164-
self.prohibit_parenthesized_params(item_segment);
165+
self.prohibit_parenthesized_params(item_segment, true);
165166

166167
return Substs::for_item(tcx, def_id, |_, _| {
167168
tcx.types.re_static
@@ -957,7 +958,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
957958
pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) {
958959
for segment in segments {
959960
if let hir::ParenthesizedParameters(_) = segment.parameters {
960-
self.prohibit_parenthesized_params(segment);
961+
self.prohibit_parenthesized_params(segment, false);
961962
break;
962963
}
963964
for typ in segment.parameters.types() {
@@ -982,12 +983,18 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
982983
}
983984
}
984985

985-
pub fn prohibit_parenthesized_params(&self, segment: &hir::PathSegment) {
986+
pub fn prohibit_parenthesized_params(&self, segment: &hir::PathSegment, emit_error: bool) {
986987
if let hir::ParenthesizedParameters(ref data) = segment.parameters {
987-
struct_span_err!(self.tcx().sess, data.span, E0214,
988-
"parenthesized parameters may only be used with a trait")
989-
.span_label(data.span, "only traits may use parentheses")
990-
.emit();
988+
if emit_error {
989+
struct_span_err!(self.tcx().sess, data.span, E0214,
990+
"parenthesized parameters may only be used with a trait")
991+
.span_label(data.span, "only traits may use parentheses")
992+
.emit();
993+
} else {
994+
let msg = "parenthesized parameters may only be used with a trait".to_string();
995+
self.tcx().sess.add_lint(PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
996+
ast::CRATE_NODE_ID, data.span, msg);
997+
}
991998
}
992999
}
9931000

Diff for: src/librustc_typeck/check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4495,7 +4495,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
44954495
(&data.lifetimes[..], &data.types[..], data.infer_types, &data.bindings[..])
44964496
}
44974497
Some(&hir::ParenthesizedParameters(_)) => {
4498-
AstConv::prohibit_parenthesized_params(self, &segment.as_ref().unwrap().0);
4498+
AstConv::prohibit_parenthesized_params(self, &segment.as_ref().unwrap().0,
4499+
false);
44994500
(&[][..], &[][..], true, &[][..])
45004501
}
45014502
None => (&[][..], &[][..], true, &[][..])

Diff for: src/test/compile-fail/issue-32995-2.rs

+11
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,29 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![deny(parenthesized_params_in_types_and_modules)]
12+
//~^ NOTE lint level defined here
13+
//~| NOTE lint level defined here
14+
//~| NOTE lint level defined here
15+
#![allow(dead_code, unused_variables)]
1116
#![feature(conservative_impl_trait)]
1217

1318
fn main() {
1419
{ fn f<X: ::std::marker()::Send>() {} }
1520
//~^ ERROR parenthesized parameters may only be used with a trait
21+
//~| WARN previously accepted
22+
//~| NOTE issue #42238
1623

1724
{ fn f() -> impl ::std::marker()::Send { } }
1825
//~^ ERROR parenthesized parameters may only be used with a trait
26+
//~| WARN previously accepted
27+
//~| NOTE issue #42238
1928
}
2029

2130
#[derive(Clone)]
2231
struct X;
2332

2433
impl ::std::marker()::Copy for X {}
2534
//~^ ERROR parenthesized parameters may only be used with a trait
35+
//~| WARN previously accepted
36+
//~| NOTE issue #42238

Diff for: src/test/compile-fail/issue-32995.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,55 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
fn main() {
12-
let s: String() = String::from("foo");
13-
//~^ ERROR parenthesized parameters may only be used with a trait
11+
#![deny(parenthesized_params_in_types_and_modules)]
12+
//~^ NOTE lint level defined here
13+
//~| NOTE lint level defined here
14+
//~| NOTE lint level defined here
15+
//~| NOTE lint level defined here
16+
//~| NOTE lint level defined here
17+
//~| NOTE lint level defined here
18+
//~| NOTE lint level defined here
19+
#![allow(dead_code, unused_variables)]
1420

21+
fn main() {
1522
let x: usize() = 1;
1623
//~^ ERROR parenthesized parameters may only be used with a trait
24+
//~| WARN previously accepted
25+
//~| NOTE issue #42238
1726

1827
let b: ::std::boxed()::Box<_> = Box::new(1);
1928
//~^ ERROR parenthesized parameters may only be used with a trait
29+
//~| WARN previously accepted
30+
//~| NOTE issue #42238
2031

2132
macro_rules! pathexpr {
2233
($p:path) => { $p }
2334
}
2435

2536
let p = pathexpr!(::std::str()::from_utf8)(b"foo").unwrap();
2637
//~^ ERROR parenthesized parameters may only be used with a trait
38+
//~| WARN previously accepted
39+
//~| NOTE issue #42238
2740

2841
let p = pathexpr!(::std::str::from_utf8())(b"foo").unwrap();
2942
//~^ ERROR parenthesized parameters may only be used with a trait
43+
//~| WARN previously accepted
44+
//~| NOTE issue #42238
3045

3146
let o : Box<::std::marker()::Send> = Box::new(1);
3247
//~^ ERROR parenthesized parameters may only be used with a trait
48+
//~| WARN previously accepted
49+
//~| NOTE issue #42238
3350

3451
let o : Box<Send + ::std::marker()::Sync> = Box::new(1);
3552
//~^ ERROR parenthesized parameters may only be used with a trait
53+
//~| WARN previously accepted
54+
//~| NOTE issue #42238
3655
}
3756

3857
fn foo<X:Default>() {
3958
let d : X() = Default::default();
4059
//~^ ERROR parenthesized parameters may only be used with a trait
60+
//~| WARN previously accepted
61+
//~| NOTE issue #42238
4162
}

0 commit comments

Comments
 (0)