Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Also adds test for this case.
  • Loading branch information
Emilgardis committed Jun 5, 2017
1 parent c94a9ac commit 1b41019
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,24 +684,36 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
expected_found.found,
expected_trait_ty.is_closure())
} else if let &TypeError::Sorts(ref expected_found) = e {
let expected = if let ty::TyTuple(tys, _) = expected_found.expected.sty {
let expected_len = if let ty::TyTuple(tys, _) = expected_found.expected.sty {
tys.len()
} else if let ty::TyRef(_,ty::TypeAndMut{ty,..}) = expected_found.expected.sty {
if let ty::TyTuple(tys,_) = ty.sty {
tys.len()
} else {
1
}
} else {
1
};
let found = if let ty::TyTuple(tys, _) = expected_found.found.sty {
let found_len = if let ty::TyTuple(tys, _) = expected_found.found.sty {
tys.len()
} else if let ty::TyRef(_,ty::TypeAndMut{ty,..}) = expected_found.found.sty {
if let ty::TyTuple(tys,_) = ty.sty {
tys.len()
} else {
1
}
} else {
1
};

if expected != found {
if expected_len != found_len {
// Expected `|| { }`, found `|x, y| { }`
// Expected `fn(x) -> ()`, found `|| { }`
self.report_arg_count_mismatch(span,
found_span,
expected,
found,
expected_len,
found_len,
expected_trait_ty.is_closure())
} else {
self.report_type_argument_mismatch(span,
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/mismatched_types/issue-42143.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
let a = vec![(1,2)];
let b = a.iter().map(|x: (u32, u32)| 0);
}
20 changes: 20 additions & 0 deletions src/test/ui/mismatched_types/issue-42143.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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
--> $DIR/issue-42143.rs:13:22
|
13 | let b = a.iter().map(|x: (u32, u32)| 0);
| ^^^ ----------------- implements `std::ops::FnMut<((u32, u32),)>`
| |
| requires `std::ops::FnMut<(&({integer}, {integer}),)>`
| expected reference, found tuple

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
--> $DIR/issue-42143.rs:13:22
|
13 | let b = a.iter().map(|x: (u32, u32)| 0);
| ^^^ ----------------- implements `std::ops::FnOnce<((u32, u32),)>`
| |
| requires `std::ops::FnOnce<(&({integer}, {integer}),)>`
| expected reference, found tuple

error: aborting due to previous error(s)

0 comments on commit 1b41019

Please sign in to comment.