Skip to content

Commit 1b41019

Browse files
committed
Also adds test for this case.
1 parent c94a9ac commit 1b41019

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

src/librustc/traits/error_reporting.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -684,24 +684,36 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
684684
expected_found.found,
685685
expected_trait_ty.is_closure())
686686
} else if let &TypeError::Sorts(ref expected_found) = e {
687-
let expected = if let ty::TyTuple(tys, _) = expected_found.expected.sty {
687+
let expected_len = if let ty::TyTuple(tys, _) = expected_found.expected.sty {
688688
tys.len()
689+
} else if let ty::TyRef(_,ty::TypeAndMut{ty,..}) = expected_found.expected.sty {
690+
if let ty::TyTuple(tys,_) = ty.sty {
691+
tys.len()
692+
} else {
693+
1
694+
}
689695
} else {
690696
1
691697
};
692-
let found = if let ty::TyTuple(tys, _) = expected_found.found.sty {
698+
let found_len = if let ty::TyTuple(tys, _) = expected_found.found.sty {
693699
tys.len()
700+
} else if let ty::TyRef(_,ty::TypeAndMut{ty,..}) = expected_found.found.sty {
701+
if let ty::TyTuple(tys,_) = ty.sty {
702+
tys.len()
703+
} else {
704+
1
705+
}
694706
} else {
695707
1
696708
};
697709

698-
if expected != found {
710+
if expected_len != found_len {
699711
// Expected `|| { }`, found `|x, y| { }`
700712
// Expected `fn(x) -> ()`, found `|| { }`
701713
self.report_arg_count_mismatch(span,
702714
found_span,
703-
expected,
704-
found,
715+
expected_len,
716+
found_len,
705717
expected_trait_ty.is_closure())
706718
} else {
707719
self.report_type_argument_mismatch(span,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 a = vec![(1,2)];
13+
let b = a.iter().map(|x: (u32, u32)| 0);
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0281]: type mismatch: `[closure@$DIR/issue-42143.rs:13:26: 13:43]` implements the trait `std::ops::FnMut<((u32, u32),)>`, but the trait `std::ops::FnMut<(&({integer}, {integer}),)>` is required
2+
--> $DIR/issue-42143.rs:13:22
3+
|
4+
13 | let b = a.iter().map(|x: (u32, u32)| 0);
5+
| ^^^ ----------------- implements `std::ops::FnMut<((u32, u32),)>`
6+
| |
7+
| requires `std::ops::FnMut<(&({integer}, {integer}),)>`
8+
| expected reference, found tuple
9+
10+
error[E0281]: type mismatch: `[closure@$DIR/issue-42143.rs:13:26: 13:43]` implements the trait `std::ops::FnOnce<((u32, u32),)>`, but the trait `std::ops::FnOnce<(&({integer}, {integer}),)>` is required
11+
--> $DIR/issue-42143.rs:13:22
12+
|
13+
13 | let b = a.iter().map(|x: (u32, u32)| 0);
14+
| ^^^ ----------------- implements `std::ops::FnOnce<((u32, u32),)>`
15+
| |
16+
| requires `std::ops::FnOnce<(&({integer}, {integer}),)>`
17+
| expected reference, found tuple
18+
19+
error: aborting due to previous error(s)
20+

0 commit comments

Comments
 (0)