auto merge of #15191 : pcwalton/rust/variance-in-trait-matching, r=huonw

I believe that #5781 got fixed by the DST work. It duplicated the
variance inference work in #12828. Therefore, all that is left in #5781
is adding a test.

Closes #5781.

r? @huonw
This commit is contained in:
bors 2014-06-28 18:21:34 +00:00
commit de337f3ddf
20 changed files with 214 additions and 84 deletions

View file

@ -23,7 +23,7 @@ fn with<R:deref>(f: |x: &int| -> R) -> int {
}
fn return_it() -> int {
with(|o| o) //~ ERROR lifetime of function argument does not outlive the function call
with(|o| o) //~ ERROR cannot infer an appropriate lifetime
}
fn main() {

View file

@ -0,0 +1,31 @@
// 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.
extern crate serialize;
use std::io::MemWriter;
use std::io;
use serialize::{Encodable, Encoder};
pub fn buffer_encode<'a,
T:Encodable<serialize::json::Encoder<'a>,io::IoError>>(
to_encode_object: &T)
-> Vec<u8> {
let mut m = MemWriter::new();
{
let mut encoder =
serialize::json::Encoder::new(&mut m as &mut io::Writer);
//~^ ERROR `m` does not live long enough
to_encode_object.encode(&mut encoder);
}
m.unwrap()
}
fn main() {}

View file

@ -0,0 +1,30 @@
// 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.
// Issue #5781. Tests that subtyping is handled properly in trait matching.
trait Make<'a> {
fn make(x: &'a mut int) -> Self;
}
impl<'a> Make<'a> for &'a mut int {
fn make(x: &'a mut int) -> &'a mut int {
x
}
}
fn f() -> &'static mut int {
let mut x = 1;
let y: &'static mut int = Make::make(&mut x); //~ ERROR `x` does not live long enough
y
}
fn main() {}

View file

@ -13,8 +13,9 @@
use std::task;
fn main() {
task::try(proc() {
let r: Result<int,_> = task::try(proc() {
fail!("test");
1
}).unwrap()
1i
});
assert!(r.is_ok());
}

View file

@ -13,8 +13,10 @@
use std::task::TaskBuilder;
fn main() {
TaskBuilder::new().named("owned name".to_string()).try(proc() {
let r: Result<int,_> = TaskBuilder::new().named("owned name".to_string())
.try(proc() {
fail!("test");
1
}).unwrap()
});
assert!(r.is_ok());
}

View file

@ -11,8 +11,11 @@
// error-pattern:task 'send name' failed at 'test'
fn main() {
::std::task::TaskBuilder::new().named("send name".into_maybe_owned()).try(proc() {
fail!("test");
3
}).unwrap()
let r: Result<int,_> =
::std::task::TaskBuilder::new().named("send name".into_maybe_owned())
.try(proc() {
fail!("test");
3
});
assert!(r.is_ok());
}

View file

@ -11,7 +11,9 @@
// error-pattern:task 'static name' failed at 'test'
fn main() {
::std::task::TaskBuilder::new().named("static name").try(proc() {
fail!("test");
}).unwrap()
let r: Result<int,_> =
::std::task::TaskBuilder::new().named("static name").try(proc() {
fail!("test");
});
assert!(r.is_ok());
}

View file

@ -15,7 +15,10 @@ use std::task;
fn main() {
// the purpose of this test is to make sure that task::spawn()
// works when provided with a bare function:
task::try(startfn).unwrap();
let r = task::try(startfn);
if r.is_err() {
fail!()
}
}
fn startfn() {

View file

@ -1,3 +1,5 @@
// ignore-test
// 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.