-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
detect wrong number of args when type-checking a closure
Instead of creating inference variables for those argument types, use the trait error-reporting code to give a nicer error.
- Loading branch information
1 parent
bd10ef7
commit cc05561
Showing
5 changed files
with
191 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2016 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. | ||
|
||
// Regression test for #47244: in this specific scenario, when the | ||
// expected type indicated 1 argument but the closure takes two, we | ||
// would (early on) create type variables for the type of `b`. If the | ||
// user then attempts to invoke a method on `b`, we would get an error | ||
// saying that the type of `b` must be known, which was not very | ||
// helpful. | ||
|
||
use std::collections::HashMap; | ||
fn main() { | ||
|
||
let m = HashMap::new(); | ||
m.insert( "foo", "bar" ); | ||
|
||
m.iter().map( |_, b| { | ||
//~^ ERROR closure is expected to take a single 2-tuple | ||
|
||
b.to_string() | ||
}); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/mismatched_types/closure-arg-count-expected-type-issue-47244.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 2 distinct arguments | ||
--> $DIR/closure-arg-count-expected-type-issue-47244.rs:24:14 | ||
| | ||
24 | m.iter().map( |_, b| { | ||
| ^^^ ------ takes 2 distinct arguments | ||
| | | ||
| expected closure that takes a single 2-tuple as argument | ||
help: change the closure to accept a tuple instead of individual arguments | ||
| | ||
24 | m.iter().map( |(_, b)| { | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|