Skip to content

Commit 63ecd6a

Browse files
committed
Prohibit parenthesized params in more types.
1 parent bedd7da commit 63ecd6a

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
161161
match item_segment.parameters {
162162
hir::AngleBracketedParameters(_) => {}
163163
hir::ParenthesizedParameters(..) => {
164-
struct_span_err!(tcx.sess, span, E0214,
165-
"parenthesized parameters may only be used with a trait")
166-
.span_label(span, "only traits may use parentheses")
167-
.emit();
164+
self.prohibit_parenthesized_params(item_segment);
168165

169166
return Substs::for_item(tcx, def_id, |_, _| {
170167
tcx.types.re_static
@@ -948,6 +945,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
948945

949946
pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) {
950947
for segment in segments {
948+
if let hir::ParenthesizedParameters(_) = segment.parameters {
949+
self.prohibit_parenthesized_params(segment);
950+
break;
951+
}
951952
for typ in segment.parameters.types() {
952953
struct_span_err!(self.tcx().sess, typ.span, E0109,
953954
"type parameters are not allowed on this type")
@@ -970,6 +971,15 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
970971
}
971972
}
972973

974+
pub fn prohibit_parenthesized_params(&self, segment: &hir::PathSegment) {
975+
if let hir::ParenthesizedParameters(ref data) = segment.parameters {
976+
struct_span_err!(self.tcx().sess, data.span, E0214,
977+
"parenthesized parameters may only be used with a trait")
978+
.span_label(data.span, "only traits may use parentheses")
979+
.emit();
980+
}
981+
}
982+
973983
pub fn prohibit_projection(&self, span: Span) {
974984
let mut err = struct_span_err!(self.tcx().sess, span, E0229,
975985
"associated type bindings are not allowed here");

src/test/compile-fail/issue-32995.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let s: String() = String::from("foo");
13+
//~^ ERROR parenthesized parameters may only be used with a trait
14+
15+
let x: usize() = 1;
16+
//~^ ERROR parenthesized parameters may only be used with a trait
17+
18+
let b: ::std::boxed()::Box<_> = Box::new(1);
19+
//~^ ERROR parenthesized parameters may only be used with a trait
20+
}
21+
22+
fn foo<X:Default>() {
23+
let d : X() = Default::default();
24+
//~^ ERROR parenthesized parameters may only be used with a trait
25+
}

0 commit comments

Comments
 (0)