Skip to content

Commit 3235446

Browse files
committed
Accept parenthesized type args for error recovery
1 parent d38e700 commit 3235446

8 files changed

+30
-25
lines changed

src/librustc/hir/lowering.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,11 @@ impl<'a> LoweringContext<'a> {
18261826
struct_span_err!(self.sess, data.span, E0214, "{}", msg)
18271827
.span_label(data.span, "only traits may use parentheses")
18281828
.emit();
1829-
(hir::GenericArgs::none(), false)
1829+
(self.lower_angle_bracketed_parameter_data(
1830+
&data.as_angle_bracketed_args(),
1831+
param_mode,
1832+
itctx).0,
1833+
false)
18301834
}
18311835
},
18321836
}

src/libsyntax/ast.rs

+10
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ pub struct ParenthesisedArgs {
192192
pub output: Option<P<Ty>>,
193193
}
194194

195+
impl ParenthesisedArgs {
196+
pub fn as_angle_bracketed_args(&self) -> AngleBracketedArgs {
197+
AngleBracketedArgs {
198+
span: self.span,
199+
args: self.inputs.iter().cloned().map(|input| GenericArg::Type(input)).collect(),
200+
bindings: vec![],
201+
}
202+
}
203+
}
204+
195205
// hack to ensure that we don't try to access the private parts of `NodeId` in this module
196206
mod node_id_inner {
197207
use rustc_data_structures::indexed_vec::Idx;

src/test/ui/error-codes/E0214.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ error[E0214]: parenthesized parameters may only be used with a trait
44
LL | let v: Vec(&str) = vec!["foo"];
55
| ^^^^^^ only traits may use parentheses
66

7-
error[E0107]: wrong number of type arguments: expected 1, found 0
8-
--> $DIR/E0214.rs:2:12
9-
|
10-
LL | let v: Vec(&str) = vec!["foo"];
11-
| ^^^^^^^^^ expected 1 type argument
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
148

15-
Some errors occurred: E0107, E0214.
16-
For more information about an error, try `rustc --explain E0107`.
9+
For more information about this error, try `rustc --explain E0214`.

src/test/ui/issues/issue-23589.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fn main() {
22
let v: Vec(&str) = vec!['1', '2'];
33
//~^ ERROR parenthesized parameters may only be used with a trait
4+
//~| ERROR mismatched types
45
}

src/test/ui/issues/issue-23589.stderr

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ error[E0214]: parenthesized parameters may only be used with a trait
44
LL | let v: Vec(&str) = vec!['1', '2'];
55
| ^^^^^^ only traits may use parentheses
66

7-
error[E0107]: wrong number of type arguments: expected 1, found 0
8-
--> $DIR/issue-23589.rs:2:12
7+
error[E0308]: mismatched types
8+
--> $DIR/issue-23589.rs:2:29
99
|
1010
LL | let v: Vec(&str) = vec!['1', '2'];
11-
| ^^^^^^^^^ expected 1 type argument
11+
| ^^^ expected &str, found char
12+
|
13+
= note: expected type `&str`
14+
found type `char`
1215

1316
error: aborting due to 2 previous errors
1417

15-
Some errors occurred: E0107, E0214.
16-
For more information about an error, try `rustc --explain E0107`.
18+
Some errors occurred: E0214, E0308.
19+
For more information about an error, try `rustc --explain E0214`.

src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-1.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct Bar<A> {
77
fn bar() {
88
let x: Box<Bar()> = panic!();
99
//~^ ERROR parenthesized parameters may only be used with a trait
10+
//~| ERROR wrong number of type arguments: expected 1, found 0
1011
}
1112

1213
fn main() { }

src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-3.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ error[E0214]: parenthesized parameters may only be used with a trait
44
LL | let b = Bar::(isize, usize)::new(); // OK too (for the parser)
55
| ^^^^^^^^^^^^^^^^ only traits may use parentheses
66

7-
error[E0107]: wrong number of type arguments: expected 2, found 0
8-
--> $DIR/unboxed-closure-sugar-used-on-struct-3.rs:14:13
9-
|
10-
LL | let b = Bar::(isize, usize)::new(); // OK too (for the parser)
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected 2 type arguments
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
148

15-
Some errors occurred: E0107, E0214.
16-
For more information about an error, try `rustc --explain E0107`.
9+
For more information about this error, try `rustc --explain E0214`.

src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct Bar<A> {
66

77
fn foo(b: Box<Bar()>) {
88
//~^ ERROR parenthesized parameters may only be used with a trait
9-
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
9+
//~| ERROR wrong number of type arguments: expected 1, found 0
1010
}
1111

1212
fn main() { }

0 commit comments

Comments
 (0)