Skip to content

Commit b9fa2da

Browse files
committed
Avoid ICE in arg mistmatch error for tuple variants
1 parent 16362c7 commit b9fa2da

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/librustc/traits/error_reporting.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
756756
}).collect(),
757757
ref sty => vec![ArgKind::Arg("_".to_owned(), format!("{}", sty))],
758758
};
759-
if found.len()== expected.len() {
759+
if found.len() == expected.len() {
760760
self.report_closure_arg_mismatch(span,
761761
found_span,
762762
found_trait_ref,
@@ -870,6 +870,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
870870
_ => ArgKind::Arg("_".to_owned(), "_".to_owned())
871871
}).collect::<Vec<ArgKind>>())
872872
}
873+
hir::map::NodeVariant(&hir::Variant {
874+
span,
875+
node: hir::Variant_ {
876+
data: hir::VariantData::Tuple(ref fields, _),
877+
..
878+
},
879+
..
880+
}) => {
881+
(self.tcx.sess.codemap().def_span(span),
882+
fields.iter().map(|field| {
883+
ArgKind::Arg(format!("{}", field.name), "_".to_string())
884+
}).collect::<Vec<_>>())
885+
}
873886
_ => panic!("non-FnLike node found: {:?}", node),
874887
}
875888
}

src/test/ui/issue-47706.rs

+15
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,18 @@ impl Foo {
2222
}
2323
//~^^ ERROR function is expected to take 1 argument, but it takes 2 arguments [E0593]
2424
}
25+
26+
enum Qux {
27+
Bar(i32),
28+
}
29+
30+
fn foo<F>(f: F)
31+
where
32+
F: Fn(),
33+
{
34+
}
35+
36+
fn main() {
37+
foo(Qux::Bar);
38+
}
39+
//~^^ ERROR function is expected to take 0 arguments, but it takes 1 argument [E0593]

src/test/ui/issue-47706.stderr

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
error[E0601]: main function not found
2-
31
error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
42
--> $DIR/issue-47706.rs:21:18
53
|
@@ -9,5 +7,24 @@ error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
97
21 | self.foo.map(Foo::new)
108
| ^^^ expected function that takes 1 argument
119

10+
error[E0593]: function is expected to take 0 arguments, but it takes 1 argument
11+
--> $DIR/issue-47706.rs:37:5
12+
|
13+
27 | Bar(i32),
14+
| -------- takes 1 argument
15+
...
16+
37 | foo(Qux::Bar);
17+
| ^^^ expected function that takes 0 arguments
18+
|
19+
note: required by `foo`
20+
--> $DIR/issue-47706.rs:30:1
21+
|
22+
30 | / fn foo<F>(f: F)
23+
31 | | where
24+
32 | | F: Fn(),
25+
33 | | {
26+
34 | | }
27+
| |_^
28+
1229
error: aborting due to 2 previous errors
1330

0 commit comments

Comments
 (0)