Skip to content

Commit 9d79e3d

Browse files
authored
Rollup merge of rust-lang#48246 - estebank:ice, r=nikomatsakis
Avoid ICE in arg mistmatch error for tuple variants Fix rust-lang#47706.
2 parents 9dd7169 + b9fa2da commit 9d79e3d

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,
@@ -874,6 +874,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
874874
_ => ArgKind::Arg("_".to_owned(), "_".to_owned())
875875
}).collect::<Vec<ArgKind>>())
876876
}
877+
hir::map::NodeVariant(&hir::Variant {
878+
span,
879+
node: hir::Variant_ {
880+
data: hir::VariantData::Tuple(ref fields, _),
881+
..
882+
},
883+
..
884+
}) => {
885+
(self.tcx.sess.codemap().def_span(span),
886+
fields.iter().map(|field| {
887+
ArgKind::Arg(format!("{}", field.name), "_".to_string())
888+
}).collect::<Vec<_>>())
889+
}
877890
_ => panic!("non-FnLike node found: {:?}", node),
878891
}
879892
}

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)