Skip to content

Commit

Permalink
Avoid ICE in arg mistmatch error for tuple variants
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Feb 15, 2018
1 parent 16362c7 commit b9fa2da
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/librustc/traits/error_reporting.rs
Expand Up @@ -756,7 +756,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}).collect(),
ref sty => vec![ArgKind::Arg("_".to_owned(), format!("{}", sty))],
};
if found.len()== expected.len() {
if found.len() == expected.len() {
self.report_closure_arg_mismatch(span,
found_span,
found_trait_ref,
Expand Down Expand Up @@ -870,6 +870,19 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
_ => ArgKind::Arg("_".to_owned(), "_".to_owned())
}).collect::<Vec<ArgKind>>())
}
hir::map::NodeVariant(&hir::Variant {
span,
node: hir::Variant_ {
data: hir::VariantData::Tuple(ref fields, _),
..
},
..
}) => {
(self.tcx.sess.codemap().def_span(span),
fields.iter().map(|field| {
ArgKind::Arg(format!("{}", field.name), "_".to_string())
}).collect::<Vec<_>>())
}
_ => panic!("non-FnLike node found: {:?}", node),
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/issue-47706.rs
Expand Up @@ -22,3 +22,18 @@ impl Foo {
}
//~^^ ERROR function is expected to take 1 argument, but it takes 2 arguments [E0593]
}

enum Qux {
Bar(i32),
}

fn foo<F>(f: F)
where
F: Fn(),
{
}

fn main() {
foo(Qux::Bar);
}
//~^^ ERROR function is expected to take 0 arguments, but it takes 1 argument [E0593]
21 changes: 19 additions & 2 deletions src/test/ui/issue-47706.stderr
@@ -1,5 +1,3 @@
error[E0601]: main function not found

error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
--> $DIR/issue-47706.rs:21:18
|
Expand All @@ -9,5 +7,24 @@ error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
21 | self.foo.map(Foo::new)
| ^^^ expected function that takes 1 argument

error[E0593]: function is expected to take 0 arguments, but it takes 1 argument
--> $DIR/issue-47706.rs:37:5
|
27 | Bar(i32),
| -------- takes 1 argument
...
37 | foo(Qux::Bar);
| ^^^ expected function that takes 0 arguments
|
note: required by `foo`
--> $DIR/issue-47706.rs:30:1
|
30 | / fn foo<F>(f: F)
31 | | where
32 | | F: Fn(),
33 | | {
34 | | }
| |_^

error: aborting due to 2 previous errors

0 comments on commit b9fa2da

Please sign in to comment.