-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deduce the argument types based on the expected type, trawling throug…
…h the fulfillment contect if necessary.
- Loading branch information
1 parent
fe2fcb3
commit 8e44688
Showing
8 changed files
with
249 additions
and
11 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
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,19 @@ | ||
// Copyright 2012 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. | ||
|
||
#![feature(unboxed_closures)] | ||
|
||
fn with_int(f: &mut FnMut(&int)) { | ||
} | ||
|
||
fn main() { | ||
let mut x: Option<&int> = None; | ||
with_int(&mut |&mut: y| x = Some(y)); //~ ERROR cannot infer | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/compile-fail/unboxed-closures-infer-argument-types-two-region-pointers.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 2014 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. | ||
|
||
// That a closure whose expected argument types include two distinct | ||
// bound regions. | ||
|
||
#![feature(unboxed_closures)] | ||
|
||
use std::cell::Cell; | ||
|
||
fn doit<T,F>(val: T, f: &F) | ||
where F : Fn(&Cell<&T>, &T) | ||
{ | ||
let x = Cell::new(&val); | ||
f.call((&x,&val)) | ||
} | ||
|
||
pub fn main() { | ||
doit(0i, &|&: x, y| { | ||
x.set(y); //~ ERROR cannot infer | ||
}); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-bound.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,24 @@ | ||
// Copyright 2014 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. | ||
|
||
// Test that we are able to infer that the type of `x` is `int` based | ||
// on the expected type from the object. | ||
|
||
#![feature(unboxed_closures)] | ||
|
||
fn doit<T,F>(val: T, f: &F) | ||
where F : Fn(T) | ||
{ | ||
f.call((val,)) | ||
} | ||
|
||
pub fn main() { | ||
doit(0i, &|&: x /*: int*/ | { x.to_int(); }); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/run-pass/unboxed-closures-infer-argument-types-from-expected-object-type.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,20 @@ | ||
// Copyright 2014 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. | ||
|
||
// Test that we are able to infer that the type of `x` is `int` based | ||
// on the expected type from the object. | ||
|
||
#![feature(unboxed_closures)] | ||
|
||
fn doit<T>(val: T, f: &Fn(T)) { f.call((val,)) } | ||
|
||
pub fn main() { | ||
doit(0i, &|&: x /*: int*/ | { x.to_int(); }); | ||
} |
24 changes: 24 additions & 0 deletions
24
.../run-pass/unboxed-closures-infer-argument-types-with-bound-regions-from-expected-bound.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,24 @@ | ||
// Copyright 2014 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. | ||
|
||
// Test that we are able to infer that the type of `x` is `int` based | ||
// on the expected type from the object. | ||
|
||
#![feature(unboxed_closures)] | ||
|
||
fn doit<T,F>(val: T, f: &F) | ||
where F : Fn(&T) | ||
{ | ||
f.call((&val,)) | ||
} | ||
|
||
pub fn main() { | ||
doit(0i, &|&: x /*: int*/ | { x.to_int(); }); | ||
} |