diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-08-27 21:46:52 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2014-08-27 21:46:52 -0400 |
| commit | 1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f (patch) | |
| tree | 552fabade603ab0d148a49ae3cf1abd3f399740a /src/test/compile-fail | |
| parent | 3ee047ae1ffab454270bc1859b3beef3556ef8f9 (diff) | |
| download | rust-1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f.tar.gz rust-1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f.zip | |
Implement generalized object and type parameter bounds (Fixes #16462)
Diffstat (limited to 'src/test/compile-fail')
72 files changed, 892 insertions, 205 deletions
diff --git a/src/test/compile-fail/bad-method-typaram-kind.rs b/src/test/compile-fail/bad-method-typaram-kind.rs index db6db02ded5..b63ecc6b66f 100644 --- a/src/test/compile-fail/bad-method-typaram-kind.rs +++ b/src/test/compile-fail/bad-method-typaram-kind.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo<T>() { +fn foo<T:'static>() { 1u.bar::<T>(); //~ ERROR: does not fulfill `Send` } diff --git a/src/test/compile-fail/borrowck-call-sendfn.rs b/src/test/compile-fail/borrowck-call-sendfn.rs index 57c0deb178d..eb2ea6b3de4 100644 --- a/src/test/compile-fail/borrowck-call-sendfn.rs +++ b/src/test/compile-fail/borrowck-call-sendfn.rs @@ -9,7 +9,7 @@ // except according to those terms. struct Foo { - f: proc() + f: proc():'static } fn call(x: Foo) { diff --git a/src/test/compile-fail/borrowck-object-lifetime.rs b/src/test/compile-fail/borrowck-object-lifetime.rs index c55a5a30538..bbb58e21198 100644 --- a/src/test/compile-fail/borrowck-object-lifetime.rs +++ b/src/test/compile-fail/borrowck-object-lifetime.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// 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. // @@ -8,17 +8,22 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// Test that borrows that occur due to calls to object methods +// properly "claim" the object path. trait Foo { fn borrowed(&self) -> &(); + fn mut_borrowed(&mut self) -> &(); } -fn borrowed_receiver(x: &Foo) -> &() { - x.borrowed() +fn borrowed_receiver(x: &Foo) { + let _y = x.borrowed(); + let _z = x.borrowed(); } -fn owned_receiver(x: Box<Foo>) -> &'static () { - x.borrowed() //~ ERROR `*x` does not live long enough +fn mut_borrowed_receiver(x: &mut Foo) { + let _y = x.borrowed(); + let _z = x.mut_borrowed(); //~ ERROR cannot borrow } fn mut_owned_receiver(mut x: Box<Foo>) { diff --git a/src/test/compile-fail/box-static-bound.rs b/src/test/compile-fail/box-static-bound.rs index 5ef52ab6645..29ee79b0079 100644 --- a/src/test/compile-fail/box-static-bound.rs +++ b/src/test/compile-fail/box-static-bound.rs @@ -12,7 +12,7 @@ use std::gc::{Gc, GC}; fn f<T>(x: T) -> Gc<T> { - box(GC) x //~ ERROR value may contain references + box(GC) x //~ ERROR the parameter type `T` may not live long enough } fn g<T:'static>(x: T) -> Gc<T> { diff --git a/src/test/compile-fail/builtin-superkinds-self-type.rs b/src/test/compile-fail/builtin-superkinds-self-type.rs index 67222bdafbf..726413981a5 100644 --- a/src/test/compile-fail/builtin-superkinds-self-type.rs +++ b/src/test/compile-fail/builtin-superkinds-self-type.rs @@ -11,7 +11,7 @@ // Tests (negatively) the ability for the Self type in default methods // to use capabilities granted by builtin kinds as supertraits. -trait Foo : Sync { +trait Foo : Sync+'static { fn foo(self, mut chan: Sender<Self>) { chan.send(self); //~ ERROR does not fulfill `Send` } diff --git a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs index 951354d964d..1ff9dc9dac4 100644 --- a/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs +++ b/src/test/compile-fail/closure-bounds-cant-promote-superkind-in-struct.rs @@ -13,7 +13,7 @@ struct X { } fn foo(blk: ||:'static) -> X { - return X { field: blk }; //~ ERROR expected bounds `'static+Send` + return X { field: blk }; //~ ERROR expected bounds `Send` } fn main() { diff --git a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs index 9176412cd79..c0b463535d4 100644 --- a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs +++ b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs @@ -12,8 +12,8 @@ fn bar(blk: ||:'static) { } fn foo(x: &()) { - bar(|| { //~ ERROR cannot infer an appropriate lifetime - let _ = x; + bar(|| { + let _ = x; //~ ERROR captured variable `x` does not outlive }) } diff --git a/src/test/compile-fail/closure-bounds-subtype.rs b/src/test/compile-fail/closure-bounds-subtype.rs index d69a56b76b0..5bd9f20dd83 100644 --- a/src/test/compile-fail/closure-bounds-subtype.rs +++ b/src/test/compile-fail/closure-bounds-subtype.rs @@ -9,13 +9,13 @@ // except according to those terms. -fn take_any(_: ||:) { +fn take_any(_: ||) { } fn take_const_owned(_: ||:Sync+Send) { } -fn give_any(f: ||:) { +fn give_any(f: ||) { take_any(f); } diff --git a/src/test/compile-fail/drop-on-non-struct.rs b/src/test/compile-fail/drop-on-non-struct.rs index bf501ecfb70..af4c12c754b 100644 --- a/src/test/compile-fail/drop-on-non-struct.rs +++ b/src/test/compile-fail/drop-on-non-struct.rs @@ -14,7 +14,6 @@ type Foo = Vec<u8>; impl Drop for Foo { //~^ ERROR cannot provide an extension implementation -//~^^ ERROR multiple applicable methods fn drop(&mut self) { println!("kaboom"); } diff --git a/src/test/compile-fail/isuue-12470.rs b/src/test/compile-fail/issue-12470.rs index bf13b7ebbdb..aa7e3cd3739 100644 --- a/src/test/compile-fail/isuue-12470.rs +++ b/src/test/compile-fail/issue-12470.rs @@ -24,7 +24,7 @@ impl X for B { } struct A<'a> { - p: &'a X + p: &'a X+'a } fn make_a<'a>(p: &'a X) -> A<'a> { diff --git a/src/test/compile-fail/issue-14285.rs b/src/test/compile-fail/issue-14285.rs index d5e608ecae3..624ddf0c8bb 100644 --- a/src/test/compile-fail/issue-14285.rs +++ b/src/test/compile-fail/issue-14285.rs @@ -14,7 +14,7 @@ struct A; impl Foo for A {} -struct B<'a>(&'a Foo); +struct B<'a>(&'a Foo+'a); fn foo<'a>(a: &Foo) -> B<'a> { B(a) //~ ERROR cannot infer an appropriate lifetime diff --git a/src/test/compile-fail/issue-3154.rs b/src/test/compile-fail/issue-3154.rs index 141bf2b4279..5f55c550aeb 100644 --- a/src/test/compile-fail/issue-3154.rs +++ b/src/test/compile-fail/issue-3154.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct thing<'a, Q> { +struct thing<'a, Q:'a> { x: &'a Q } diff --git a/src/test/compile-fail/issue-3907-2.rs b/src/test/compile-fail/issue-3907-2.rs index ab9f7a84530..71f91050256 100644 --- a/src/test/compile-fail/issue-3907-2.rs +++ b/src/test/compile-fail/issue-3907-2.rs @@ -11,12 +11,12 @@ // aux-build:issue_3907.rs extern crate issue_3907; -type Foo = issue_3907::Foo; +type Foo = issue_3907::Foo+'static; struct S { name: int } -fn bar(_x: Foo) {} //~ ERROR variable `_x` has dynamically sized type `issue_3907::Foo` +fn bar(_x: Foo) {} //~ ERROR variable `_x` has dynamically sized type fn main() {} diff --git a/src/test/compile-fail/issue-3953.rs b/src/test/compile-fail/issue-3953.rs index 4484a004251..ab2018af999 100644 --- a/src/test/compile-fail/issue-3953.rs +++ b/src/test/compile-fail/issue-3953.rs @@ -12,15 +12,9 @@ use std::cmp::PartialEq; -trait Hahaha: PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + //~ ERROR duplicate supertrait - PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + - PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + - PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + - PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + - PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + - PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + - PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + PartialEq + - PartialEq {} +trait Hahaha: PartialEq + PartialEq { + //~^ ERROR trait `PartialEq` already appears in the list of bounds +} struct Lol(int); diff --git a/src/test/compile-fail/issue-4972.rs b/src/test/compile-fail/issue-4972.rs index 199bc3f5c29..bff167fa391 100644 --- a/src/test/compile-fail/issue-4972.rs +++ b/src/test/compile-fail/issue-4972.rs @@ -12,12 +12,12 @@ trait MyTrait { } pub enum TraitWrapper { - A(Box<MyTrait>), + A(Box<MyTrait+'static>), } fn get_tw_map(tw: &TraitWrapper) -> &MyTrait { match *tw { - A(box ref map) => map, //~ ERROR type `Box<MyTrait>` cannot be dereferenced + A(box ref map) => map, //~ ERROR cannot be dereferenced } } diff --git a/src/test/compile-fail/issue-5035-2.rs b/src/test/compile-fail/issue-5035-2.rs index 689b8f7c613..0251a06c5bd 100644 --- a/src/test/compile-fail/issue-5035-2.rs +++ b/src/test/compile-fail/issue-5035-2.rs @@ -9,8 +9,8 @@ // except according to those terms. trait I {} -type K = I; +type K = I+'static; -fn foo(_x: K) {} //~ ERROR: variable `_x` has dynamically sized type `I` +fn foo(_x: K) {} //~ ERROR: variable `_x` has dynamically sized type fn main() {} diff --git a/src/test/compile-fail/issue-5216.rs b/src/test/compile-fail/issue-5216.rs index ec9ec9565c4..18af9736ed9 100644 --- a/src/test/compile-fail/issue-5216.rs +++ b/src/test/compile-fail/issue-5216.rs @@ -9,12 +9,12 @@ // except according to those terms. fn f() { } -struct S(||); //~ ERROR missing lifetime specifier +struct S(||); //~ ERROR explicit lifetime bound required pub static C: S = S(f); fn g() { } -type T = ||; //~ ERROR missing lifetime specifier +type T = ||; //~ ERROR explicit lifetime bound required pub static D: T = g; fn main() {} diff --git a/src/test/compile-fail/issue-5883.rs b/src/test/compile-fail/issue-5883.rs index 14136d96c2d..f3bbb8051b7 100644 --- a/src/test/compile-fail/issue-5883.rs +++ b/src/test/compile-fail/issue-5883.rs @@ -11,14 +11,14 @@ trait A {} struct Struct { - r: A + r: A+'static } -fn new_struct(r: A) -> Struct { - //~^ ERROR variable `r` has dynamically sized type `A` +fn new_struct(r: A+'static) -> Struct { + //~^ ERROR variable `r` has dynamically sized type Struct { r: r } //~ ERROR trying to initialise a dynamically sized struct } trait Curve {} -enum E {X(Curve)} +enum E {X(Curve+'static)} fn main() {} diff --git a/src/test/compile-fail/kindck-impl-type-params.rs b/src/test/compile-fail/kindck-impl-type-params.rs index 48e1bdd671a..4cc03ee3dcd 100644 --- a/src/test/compile-fail/kindck-impl-type-params.rs +++ b/src/test/compile-fail/kindck-impl-type-params.rs @@ -28,7 +28,7 @@ fn f<T>(val: T) { fn main() { let t: S<&int> = S; let a = &t as &Gettable<&int>; - //~^ ERROR instantiating a type parameter with an incompatible type `&int` + //~^ ERROR instantiating a type parameter with an incompatible type let t: Box<S<String>> = box S; let a = t as Box<Gettable<String>>; //~^ ERROR instantiating a type parameter with an incompatible type diff --git a/src/test/compile-fail/proc-bounds.rs b/src/test/compile-fail/kindck-proc-bounds.rs index e8c6a3ba191..57c8cc3da8a 100644 --- a/src/test/compile-fail/proc-bounds.rs +++ b/src/test/compile-fail/kindck-proc-bounds.rs @@ -10,16 +10,13 @@ fn is_send<T: Send>() {} fn is_freeze<T: Sync>() {} -fn is_static<T: 'static>() {} -fn main() { +fn foo<'a>() { is_send::<proc()>(); //~^ ERROR: instantiating a type parameter with an incompatible type is_freeze::<proc()>(); //~^ ERROR: instantiating a type parameter with an incompatible type - - is_static::<proc()>(); - //~^ ERROR: instantiating a type parameter with an incompatible type } +fn main() { } diff --git a/src/test/compile-fail/kindck-send-object.rs b/src/test/compile-fail/kindck-send-object.rs new file mode 100644 index 00000000000..99519263923 --- /dev/null +++ b/src/test/compile-fail/kindck-send-object.rs @@ -0,0 +1,44 @@ +// 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 which of the builtin types are considered sendable. The tests +// in this file all test the "kind" violates detected during kindck. +// See all `regions-bounded-by-send.rs` + +fn assert_send<T:Send>() { } +trait Dummy { } +trait Message : Send { } + +// careful with object types, who knows what they close over... + +fn object_ref_with_static_bound_not_ok() { + assert_send::<&'static Dummy+'static>(); //~ ERROR does not fulfill +} + +fn box_object_with_no_bound_not_ok<'a>() { + assert_send::<Box<Dummy>>(); //~ ERROR does not fulfill +} + +fn proc_with_no_bound_not_ok<'a>() { + assert_send::<proc()>(); //~ ERROR does not fulfill +} + +fn closure_with_no_bound_not_ok<'a>() { + assert_send::<||:'static>(); //~ ERROR does not fulfill +} + +fn object_with_send_bound_ok() { + assert_send::<&'static Dummy+Send>(); + assert_send::<Box<Dummy+Send>>(); + assert_send::<proc():Send>; + assert_send::<||:Send>; +} + +fn main() { } diff --git a/src/test/compile-fail/kindck-send.rs b/src/test/compile-fail/kindck-send.rs deleted file mode 100644 index 424c7a4e430..00000000000 --- a/src/test/compile-fail/kindck-send.rs +++ /dev/null @@ -1,60 +0,0 @@ -// 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. - -// Test which of the builtin types are considered sendable. - - -fn assert_send<T:Send>() { } -trait Dummy { } - -fn test<'a,T,U:Send>(_: &'a int) { - // lifetime pointers with 'static lifetime are ok - assert_send::<&'static int>(); - assert_send::<&'static str>(); - assert_send::<&'static [int]>(); - - // whether or not they are mutable - assert_send::<&'static mut int>(); - - // otherwise lifetime pointers are not ok - assert_send::<&'a int>(); //~ ERROR does not fulfill `Send` - assert_send::<&'a str>(); //~ ERROR does not fulfill `Send` - assert_send::<&'a [int]>(); //~ ERROR does not fulfill `Send` - - // boxes are ok - assert_send::<Box<int>>(); - assert_send::<String>(); - assert_send::<Vec<int> >(); - - // but not if they own a bad thing - assert_send::<Box<&'a int>>(); //~ ERROR does not fulfill `Send` - - // careful with object types, who knows what they close over... - assert_send::<&'static Dummy>(); //~ ERROR does not fulfill `Send` - assert_send::<&'a Dummy>(); //~ ERROR does not fulfill `Send` - assert_send::<&'a Dummy+Send>(); //~ ERROR does not fulfill `Send` - assert_send::<Box<Dummy>>(); //~ ERROR does not fulfill `Send` - - // ...unless they are properly bounded - assert_send::<&'static Dummy+Send>(); - assert_send::<Box<Dummy+Send>>(); - - // but closure and object types can have lifetime bounds which make - // them not ok (FIXME #5121) - // assert_send::<proc:'a()>(); // ERROR does not fulfill `Send` - // assert_send::<Box<Dummy+'a>>(); // ERROR does not fulfill `Send` - - // unsafe ptrs are ok unless they point at unsendable things - assert_send::<*const int>(); - assert_send::<*const &'a int>(); //~ ERROR does not fulfill `Send` -} - -fn main() { -} diff --git a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs new file mode 100644 index 00000000000..21bd676a225 --- /dev/null +++ b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param-3.rs @@ -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. + +// ignore-tidy-linelength + +struct Bar<'x, 'y, 'z> { bar: &'y int, baz: int } +fn bar1<'a>(x: &Bar) -> (&'a int, &'a int, &'a int) { +//~^ NOTE: consider using an explicit lifetime parameter as shown: fn bar1<'b, 'c, 'a>(x: &'a Bar<'b, 'a, 'c>) -> (&'a int, &'a int, &'a int) + (x.bar, &x.baz, &x.baz) + //~^ ERROR: cannot infer + //~^^ ERROR: cannot infer + //~^^^ ERROR: cannot infer +} + +fn bar2<'a, 'b, 'c>(x: &Bar<'a, 'b, 'c>) -> (&'a int, &'a int, &'a int) { +//~^ NOTE: consider using an explicit lifetime parameter as shown: fn bar2<'a, 'c>(x: &'a Bar<'a, 'a, 'c>) -> (&'a int, &'a int, &'a int) + (x.bar, &x.baz, &x.baz) + //~^ ERROR: cannot infer + //~^^ ERROR: cannot infer + //~^^^ ERROR: cannot infer +} + +fn main() { } diff --git a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs index 481fb3dee73..b7da4d73489 100644 --- a/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs +++ b/src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs @@ -33,21 +33,6 @@ fn foo4<'a, 'b>(x: &'a Foo) -> (&'b int, &'a int, &'b int) { //~^ ERROR: cannot infer } -struct Bar<'x, 'y, 'z> { bar: &'y int, baz: int } -fn bar1<'a>(x: &Bar) -> (&'a int, &'a int, &'a int) { -//~^ NOTE: consider using an explicit lifetime parameter as shown: fn bar1<'b, 'c, 'a>(x: &'a Bar<'b, 'a, 'c>) -> (&'a int, &'a int, &'a int) - (x.bar, &x.baz, &x.baz) //~ ERROR: cannot infer - //~^ ERROR: cannot infer - //~^^ ERROR: cannot infer -} - -fn bar2<'a, 'b, 'c>(x: &Bar<'a, 'b, 'c>) -> (&'a int, &'a int, &'a int) { -//~^ NOTE: consider using an explicit lifetime parameter as shown: fn bar2<'a, 'c>(x: &'a Bar<'a, 'a, 'c>) -> (&'a int, &'a int, &'a int) - (x.bar, &x.baz, &x.baz) //~ ERROR: cannot infer - //~^ ERROR: cannot infer - //~^^ ERROR: cannot infer -} - struct Cat<'x, T> { cat: &'x int, t: T } struct Dog<'y> { dog: &'y int } diff --git a/src/test/compile-fail/moves-sru-moved-field.rs b/src/test/compile-fail/moves-sru-moved-field.rs index 8b02740497d..74e5e6b1202 100644 --- a/src/test/compile-fail/moves-sru-moved-field.rs +++ b/src/test/compile-fail/moves-sru-moved-field.rs @@ -9,7 +9,7 @@ // except according to those terms. -type Noncopyable = proc(); +type Noncopyable = proc():'static; struct Foo { copied: int, diff --git a/src/test/compile-fail/region-bounds-on-objects-and-type-parameters.rs b/src/test/compile-fail/region-bounds-on-objects-and-type-parameters.rs new file mode 100644 index 00000000000..40cff3e466b --- /dev/null +++ b/src/test/compile-fail/region-bounds-on-objects-and-type-parameters.rs @@ -0,0 +1,44 @@ +// 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 related to when a region bound is required to be specified. + +trait IsStatic : 'static { } +trait IsSend : Send { } +trait Is<'a> : 'a { } +trait Is2<'a> : 'a { } +trait SomeTrait { } + +// Bounds on object types: + +struct Foo<'a,'b,'c> { + // All of these are ok, because we can derive exactly one bound: + a: Box<IsStatic>, + b: Box<Is<'static>>, + c: Box<Is<'a>>, + d: Box<IsSend>, + e: Box<Is<'a>+Send>, // we can derive two bounds, but one is 'static, so ok + f: Box<SomeTrait>, //~ ERROR explicit lifetime bound required + g: Box<SomeTrait+'a>, + + z: Box<Is<'a>+'b+'c>, //~ ERROR only a single explicit lifetime bound is permitted +} + +fn test< + 'a, + 'b, + A:IsStatic, + B:Is<'a>+Is2<'b>, //~ ERROR ambiguous lifetime bound + C:'b+Is<'a>+Is2<'b>, + D:Is<'a>+Is2<'static>, + E:'a+'b //~ ERROR only a single explicit lifetime bound is permitted +>() { } + +fn main() { } diff --git a/src/test/compile-fail/region-object-lifetime-1.rs b/src/test/compile-fail/region-object-lifetime-1.rs new file mode 100644 index 00000000000..01daeb628ef --- /dev/null +++ b/src/test/compile-fail/region-object-lifetime-1.rs @@ -0,0 +1,49 @@ +// Copyright 2012-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. + +// Various tests related to testing how region inference works +// with respect to the object receivers. + +trait Foo { + fn borrowed<'a>(&'a self) -> &'a (); +} + +// Here the receiver and return value all have the same lifetime, +// so no error results. +fn borrowed_receiver_same_lifetime<'a>(x: &'a Foo) -> &'a () { + x.borrowed() +} + +// Borrowed receiver but two distinct lifetimes, we get an error. +fn borrowed_receiver_different_lifetimes<'a,'b>(x: &'a Foo) -> &'b () { + x.borrowed() //~ ERROR cannot infer +} + +// Borrowed receiver with two distinct lifetimes, but we know that +// 'b:'a, hence &'a () is permitted. +fn borrowed_receiver_related_lifetimes<'a,'b>(x: &'a Foo+'b) -> &'a () { + x.borrowed() +} + +// Here we have two distinct lifetimes, but we try to return a pointer +// with the longer lifetime when (from the signature) we only know +// that it lives as long as the shorter lifetime. Therefore, error. +fn borrowed_receiver_related_lifetimes2<'a,'b>(x: &'a Foo+'b) -> &'b () { + x.borrowed() //~ ERROR cannot infer +} + +// Here, the object is bounded by an anonymous lifetime and returned +// as `&'static`, so you get an error. +fn owned_receiver(x: Box<Foo>) -> &'static () { + x.borrowed() //~ ERROR cannot infer +} + +fn main() {} + diff --git a/src/test/compile-fail/regionck-closure-lifetimes.rs b/src/test/compile-fail/regionck-closure-lifetimes.rs index 846e03d57c3..bb895a318ff 100644 --- a/src/test/compile-fail/regionck-closure-lifetimes.rs +++ b/src/test/compile-fail/regionck-closure-lifetimes.rs @@ -15,7 +15,7 @@ fn env<'a>(blk: |p: ||: 'a|) { let mut state = 0i; let statep = &mut state; - blk(|| *statep = 1i); //~ ERROR cannot infer + blk(|| *statep = 1i); //~ ERROR captured variable `statep` does not outlive } fn no_env_no_for<'a>(blk: |p: |||: 'a) { diff --git a/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs b/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs index 1c590db11e3..7520a4c125a 100644 --- a/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs +++ b/src/test/compile-fail/regionck-unboxed-closure-lifetimes.rs @@ -16,9 +16,8 @@ fn main() { let mut f; { let c = 1; - let c_ref = &c; + let c_ref = &c; //~ ERROR `c` does not live long enough f = |&mut: a: int, b: int| { a + b + *c_ref }; - //~^ ERROR cannot infer an appropriate lifetime } } diff --git a/src/test/compile-fail/regions-bound-missing-bound-in-impl.rs b/src/test/compile-fail/regions-bound-missing-bound-in-impl.rs new file mode 100644 index 00000000000..0c9f5004f57 --- /dev/null +++ b/src/test/compile-fail/regions-bound-missing-bound-in-impl.rs @@ -0,0 +1,57 @@ +// 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. + +// Check that explicit region bounds are allowed on the various +// nominal types (but not on other types) and that they are type +// checked. + +#![no_std] + +struct Inv<'a> { // invariant w/r/t 'a + x: &'a mut &'a int +} + +pub trait Foo<'a> { + fn no_bound<'b>(self, b: Inv<'b>); + fn has_bound<'b:'a>(self, b: Inv<'b>); + fn wrong_bound1<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>); + fn wrong_bound2<'b,'c,'d:'a+'b+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>); +} + + +impl<'a> Foo<'a> for &'a int { + fn no_bound<'b:'a>(self, b: Inv<'b>) { + //~^ ERROR lifetime parameters or bounds on method `no_bound` do not match + } + + fn has_bound<'b>(self, b: Inv<'b>) { + //~^ ERROR lifetime parameters or bounds on method `has_bound` do not match + } + + fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) { + //~^ ERROR method `wrong_bound1` has an incompatible type for trait + // + // Note: This is a terrible error message. It is caused + // because, in the trait, 'b is early bound, and in the impl, + // 'c is early bound, so -- after substitution -- the + // lifetimes themselves look isomorphic. We fail because the + // lifetimes that appear in the types are in the wrong + // order. This should really be fixed by keeping more + // information about the lifetime declarations in the trait so + // that we can compare better to the impl, even in cross-crate + // cases. + } + + fn wrong_bound2<'b,'c,'e:'b+'c>(self, b: Inv<'b>, c: Inv<'c>, e: Inv<'e>) { + //~^ ERROR distinct set of bounds from its counterpart + } +} + +fn main() { } diff --git a/src/test/compile-fail/regions-bounded-by-send.rs b/src/test/compile-fail/regions-bounded-by-send.rs new file mode 100644 index 00000000000..3c7ffbc8d1f --- /dev/null +++ b/src/test/compile-fail/regions-bounded-by-send.rs @@ -0,0 +1,91 @@ +// 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. + +// Test which of the builtin types are considered sendable. The tests +// in this file all test region bound and lifetime violations that are +// detected during type check. + +fn assert_send<T:Send>() { } +trait Dummy { } + +// lifetime pointers with 'static lifetime are ok + +fn static_lifime_ok<'a,T,U:Send>(_: &'a int) { + assert_send::<&'static int>(); + assert_send::<&'static str>(); + assert_send::<&'static [int]>(); + + // whether or not they are mutable + assert_send::<&'static mut int>(); +} + +// otherwise lifetime pointers are not ok + +fn param_not_ok<'a>(x: &'a int) { + assert_send::<&'a int>(); //~ ERROR does not fulfill +} + +fn param_not_ok1<'a>(_: &'a int) { + assert_send::<&'a str>(); //~ ERROR does not fulfill +} + +fn param_not_ok2<'a>(_: &'a int) { + assert_send::<&'a [int]>(); //~ ERROR does not fulfill +} + +// boxes are ok + +fn box_ok() { + assert_send::<Box<int>>(); + assert_send::<String>(); + assert_send::<Vec<int>>(); +} + +// but not if they own a bad thing + +fn box_with_region_not_ok<'a>() { + assert_send::<Box<&'a int>>(); //~ ERROR does not fulfill +} + +// objects with insufficient bounds no ok + +fn object_with_random_bound_not_ok<'a>() { + assert_send::<&'a Dummy+'a>(); //~ ERROR does not fulfill +} + +fn object_with_send_bound_not_ok<'a>() { + assert_send::<&'a Dummy+Send>(); //~ ERROR does not fulfill +} + +fn proc_with_lifetime_not_ok<'a>() { + assert_send::<proc():'a>(); //~ ERROR does not fulfill +} + +fn closure_with_lifetime_not_ok<'a>() { + assert_send::<||:'a>(); //~ ERROR does not fulfill +} + +// unsafe pointers are ok unless they point at unsendable things + +fn unsafe_ok1<'a>(_: &'a int) { + assert_send::<*const int>(); + assert_send::<*mut int>(); +} + +fn unsafe_ok2<'a>(_: &'a int) { + assert_send::<*const &'a int>(); //~ ERROR does not fulfill +} + +fn unsafe_ok3<'a>(_: &'a int) { + assert_send::<*mut &'a int>(); //~ ERROR does not fulfill +} + +fn main() { +} diff --git a/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs b/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs new file mode 100644 index 00000000000..04a94b75215 --- /dev/null +++ b/src/test/compile-fail/regions-bounded-by-trait-requiring-static.rs @@ -0,0 +1,73 @@ +// 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. + +// Test which of the builtin types are considered sendable. The tests +// in this file all test region bound and lifetime violations that are +// detected during type check. + +trait Dummy : 'static { } +fn assert_send<T:'static>() { } + +// lifetime pointers with 'static lifetime are ok + +fn static_lifime_ok<'a,T,U:Send>(_: &'a int) { + assert_send::<&'static int>(); + assert_send::<&'static str>(); + assert_send::<&'static [int]>(); + + // whether or not they are mutable + assert_send::<&'static mut int>(); +} + +// otherwise lifetime pointers are not ok + +fn param_not_ok<'a>(x: &'a int) { + assert_send::<&'a int>(); //~ ERROR does not fulfill +} + +fn param_not_ok1<'a>(_: &'a int) { + assert_send::<&'a str>(); //~ ERROR does not fulfill +} + +fn param_not_ok2<'a>(_: &'a int) { + assert_send::<&'a [int]>(); //~ ERROR does not fulfill +} + +// boxes are ok + +fn box_ok() { + assert_send::<Box<int>>(); + assert_send::<String>(); + assert_send::<Vec<int>>(); +} + +// but not if they own a bad thing + +fn box_with_region_not_ok<'a>() { + assert_send::<Box<&'a int>>(); //~ ERROR does not fulfill +} + +// unsafe pointers are ok unless they point at unsendable things + +fn unsafe_ok1<'a>(_: &'a int) { + assert_send::<*const int>(); + assert_send::<*mut int>(); +} + +fn unsafe_ok2<'a>(_: &'a int) { + assert_send::<*const &'a int>(); //~ ERROR does not fulfill +} + +fn unsafe_ok3<'a>(_: &'a int) { + assert_send::<*mut &'a int>(); //~ ERROR does not fulfill +} + +fn main() { +} diff --git a/src/test/compile-fail/regions-bounded-method-type-parameters-cross-crate.rs b/src/test/compile-fail/regions-bounded-method-type-parameters-cross-crate.rs new file mode 100644 index 00000000000..ab97bad5bc2 --- /dev/null +++ b/src/test/compile-fail/regions-bounded-method-type-parameters-cross-crate.rs @@ -0,0 +1,33 @@ +// 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. + +// aux-build:regions-bounded-method-type-parameters-cross-crate-lib.rs + +// Check explicit region bounds on methods in the cross crate case. + +extern crate lib = "regions-bounded-method-type-parameters-cross-crate-lib"; + +use lib::Inv; +use lib::MaybeOwned; +use lib::IntoMaybeOwned; + +fn call_into_maybe_owned<'a,F:IntoMaybeOwned<'a>>(f: F) { + // Exercise a code path I found to be buggy. We were not encoding + // the region parameters from the receiver correctly on trait + // methods. + f.into_maybe_owned(); +} + +fn call_bigger_region<'a, 'b>(a: Inv<'a>, b: Inv<'b>) { + // Here the value provided for 'y is 'b, and hence 'b:'a does not hold. + a.bigger_region(b) //~ ERROR cannot infer +} + +fn main() { } diff --git a/src/test/compile-fail/regions-bounded-method-type-parameters-trait-bound.rs b/src/test/compile-fail/regions-bounded-method-type-parameters-trait-bound.rs new file mode 100644 index 00000000000..e628eb3285a --- /dev/null +++ b/src/test/compile-fail/regions-bounded-method-type-parameters-trait-bound.rs @@ -0,0 +1,44 @@ +// 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. + +#![no_std] +#![feature(lang_items)] + +// Check that explicit region bounds are allowed on the various +// nominal types (but not on other types) and that they are type +// checked. + +#[lang="sized"] +trait Sized { } + +struct Inv<'a> { // invariant w/r/t 'a + x: &'a mut &'a int +} + +trait Foo<'x> { + fn method<'y:'x>(self, y: Inv<'y>); +} + +fn caller1<'a,'b,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) { + // Here the value provided for 'y is 'a, and hence 'a:'a holds. + f.method(a); +} + +fn caller2<'a,'b,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) { + // Here the value provided for 'y is 'b, and hence 'b:'a does not hold. + f.method(b); //~ ERROR cannot infer +} + +fn caller3<'a,'b:'a,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) { + // Here the value provided for 'y is 'b, and hence 'b:'a holds. + f.method(b); +} + +fn main() { } diff --git a/src/test/compile-fail/proc-static-bound.rs b/src/test/compile-fail/regions-bounded-method-type-parameters.rs index f11ddc0151f..ba1993686d5 100644 --- a/src/test/compile-fail/proc-static-bound.rs +++ b/src/test/compile-fail/regions-bounded-method-type-parameters.rs @@ -8,19 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn main() { - let mut x = Some(1); - let mut p: proc(&mut Option<int>) = proc(_) {}; - match x { - Some(ref y) => { - p = proc(z: &mut Option<int>) { - *z = None; - let _ = y; - //~^ ERROR cannot capture variable of type `&int`, which does not fulfill `'static` - }; - } - None => {} - } - p(&mut x); +#![no_std] + +// Check that explicit region bounds are allowed on the various +// nominal types (but not on other types) and that they are type +// checked. + +struct Foo; + +impl Foo { + fn some_method<A:'static>(self) { } +} + +fn caller<'a>(x: &int) { + Foo.some_method::<&'a int>(); + //~^ ERROR does not fulfill the required lifetime } +fn main() { } diff --git a/src/test/compile-fail/owned-ptr-static-bound.rs b/src/test/compile-fail/regions-close-object-into-object.rs index dc6e8b1d6be..a45c8e1db54 100644 --- a/src/test/compile-fail/owned-ptr-static-bound.rs +++ b/src/test/compile-fail/regions-close-object-into-object.rs @@ -10,21 +10,25 @@ trait A<T> {} -struct B<'a, T>(&'a A<T>); +struct B<'a, T>(&'a A<T>+'a); trait X {} impl<'a, T> X for B<'a, T> {} -fn f<'a, T, U>(v: Box<A<T>>) -> Box<X> { - box B(v) as Box<X> //~ ERROR value may contain references; add `'static` bound to `T` +fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> { + box B(v) as Box<X> } -fn g<'a, T, U>(v: Box<A<U>>) -> Box<X> { - box B(v) as Box<X> //~ ERROR value may contain references; add `'static` bound to `U` +fn g<'a, T: 'static>(v: Box<A<T>>) -> Box<X+'static> { + box B(v) as Box<X> //~ ERROR cannot infer } -fn h<'a, T: 'static>(v: Box<A<T>>) -> Box<X> { - box B(v) as Box<X> // ok +fn h<'a, T, U>(v: Box<A<U>+'static>) -> Box<X+'static> { + box B(v) as Box<X> +} + +fn i<'a, T, U>(v: Box<A<U>>) -> Box<X+'static> { + box B(v) as Box<X> //~ ERROR cannot infer } fn main() {} diff --git a/src/test/compile-fail/regions-bound-lists-feature-gate-2.rs b/src/test/compile-fail/regions-close-over-borrowed-ref-in-obj.rs index 0f79716f370..037514f45c7 100644 --- a/src/test/compile-fail/regions-bound-lists-feature-gate-2.rs +++ b/src/test/compile-fail/regions-close-over-borrowed-ref-in-obj.rs @@ -8,11 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-pretty - trait Foo { } -fn foo<'a, 'b:'a>() { //~ ERROR region bounds require `issue_5723_bootstrap` -} +impl<'a> Foo for &'a int { } -pub fn main() { } +fn main() { + let blah; + { + let ss: &int = &1; //~ ERROR borrowed value does not live long enough + blah = box ss as Box<Foo>; + } +} diff --git a/src/test/compile-fail/regions-close-over-type-parameter-1.rs b/src/test/compile-fail/regions-close-over-type-parameter-1.rs new file mode 100644 index 00000000000..5465f199f40 --- /dev/null +++ b/src/test/compile-fail/regions-close-over-type-parameter-1.rs @@ -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. + +// Test for what happens when a type parameter `A` is closed over into +// an object. This should yield errors unless `A` (and the object) +// both have suitable bounds. + +trait SomeTrait { fn get(&self) -> int; } + +fn make_object1<A:SomeTrait>(v: A) -> Box<SomeTrait+'static> { + box v as Box<SomeTrait+'static> + //~^ ERROR the parameter type `A` may not live long enough +} + +fn make_object2<'a,A:SomeTrait+'a>(v: A) -> Box<SomeTrait+'a> { + box v as Box<SomeTrait+'a> +} + +fn make_object3<'a,'b,A:SomeTrait+'a>(v: A) -> Box<SomeTrait+'b> { + box v as Box<SomeTrait+'b> + //~^ ERROR the parameter type `A` may not live long enough +} + +fn main() { } diff --git a/src/test/compile-fail/kindck-owned-trait-contains.rs b/src/test/compile-fail/regions-close-over-type-parameter-2.rs index 50704a1afbf..0ee349aaebf 100644 --- a/src/test/compile-fail/kindck-owned-trait-contains.rs +++ b/src/test/compile-fail/regions-close-over-type-parameter-2.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// 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. // @@ -8,25 +8,27 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// Test for what happens when a type parameter `A` is closed over into +// an object. This should yield errors unless `A` (and the object) +// both have suitable bounds. -trait Repeat<A> { fn get(&self) -> A; } +trait Foo { fn get(&self); } -impl<A:Clone> Repeat<A> for A { - fn get(&self) -> A { self.clone() } +impl<A> Foo for A { + fn get(&self) { } } -fn repeater<A:Clone>(v: A) -> Box<Repeat<A>> { - box v as Box<Repeat<A>> // No +fn repeater3<'a,A:'a>(v: A) -> Box<Foo+'a> { + box v as Box<Foo+'a> } fn main() { // Error results because the type of is inferred to be // ~Repeat<&'blk int> where blk is the lifetime of the block below. - let y = { + let _ = { let tmp0 = 3i; let tmp1 = &tmp0; //~ ERROR `tmp0` does not live long enough - repeater(tmp1) + repeater3(tmp1) }; - assert!(3 == *(y.get())); } diff --git a/src/test/compile-fail/regions-early-bound-error.rs b/src/test/compile-fail/regions-early-bound-error.rs index 25016c104ad..5da281d93dd 100644 --- a/src/test/compile-fail/regions-early-bound-error.rs +++ b/src/test/compile-fail/regions-early-bound-error.rs @@ -15,7 +15,7 @@ trait GetRef<'a, T> { fn get(&self) -> &'a T; } -struct Box<'a, T> { +struct Box<'a, T:'a> { t: &'a T } diff --git a/src/test/compile-fail/regions-enum-not-wf.rs b/src/test/compile-fail/regions-enum-not-wf.rs new file mode 100644 index 00000000000..6395ee62f16 --- /dev/null +++ b/src/test/compile-fail/regions-enum-not-wf.rs @@ -0,0 +1,37 @@ +// 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. + +// Various examples of structs whose fields are not well-formed. + +#![no_std] +#![allow(dead_code)] + +enum Ref1<'a, T> { //~ ERROR the parameter type `T` may not live long enough + Ref1Variant1(&'a T) +} + +enum Ref2<'a, T> { //~ ERROR the parameter type `T` may not live long enough + Ref2Variant1, + Ref2Variant2(int, &'a T), +} + +enum RefOk<'a, T:'a> { + RefOkVariant1(&'a T) +} + +enum RefIndirect<'a, T> { //~ ERROR the parameter type `T` may not live long enough + RefIndirectVariant1(int, RefOk<'a,T>) +} + +enum RefDouble<'a, 'b, T> { //~ ERROR reference has a longer lifetime than the data + RefDoubleVariant1(&'a &'b T) +} + +fn main() { } diff --git a/src/test/compile-fail/regions-escape-bound-fn-2.rs b/src/test/compile-fail/regions-escape-bound-fn-2.rs index d2551ec4fed..d752bc97cac 100644 --- a/src/test/compile-fail/regions-escape-bound-fn-2.rs +++ b/src/test/compile-fail/regions-escape-bound-fn-2.rs @@ -16,5 +16,6 @@ fn with_int(f: |x: &int|) { fn main() { let mut x = None; //~^ ERROR lifetime of variable does not enclose its declaration + //~^^ ERROR type of expression contains references that are not valid during the expression with_int(|y| x = Some(y)); } diff --git a/src/test/compile-fail/regions-escape-via-trait-or-not.rs b/src/test/compile-fail/regions-escape-via-trait-or-not.rs index 980a4aed34f..adef1f901fd 100644 --- a/src/test/compile-fail/regions-escape-via-trait-or-not.rs +++ b/src/test/compile-fail/regions-escape-via-trait-or-not.rs @@ -8,17 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -trait deref { +#![no_std] + +#![allow(dead_code)] + +trait Deref { fn get(self) -> int; } -impl<'a> deref for &'a int { +impl<'a> Deref for &'a int { fn get(self) -> int { *self } } -fn with<R:deref>(f: |x: &int| -> R) -> int { +fn with<R:Deref>(f: |x: &int| -> R) -> int { f(&3).get() } diff --git a/src/test/compile-fail/regions-free-region-ordering-callee.rs b/src/test/compile-fail/regions-free-region-ordering-callee.rs index 9762e5c4690..26cf3be429b 100644 --- a/src/test/compile-fail/regions-free-region-ordering-callee.rs +++ b/src/test/compile-fail/regions-free-region-ordering-callee.rs @@ -31,6 +31,12 @@ fn ordering3<'a, 'b>(x: &'a uint, y: &'b uint) -> &'a &'b uint { } fn ordering4<'a, 'b>(a: &'a uint, b: &'b uint, x: |&'a &'b uint|) { + // Do not infer ordering from closure argument types. + let z: Option<&'a &'b uint> = None; + //~^ ERROR reference has a longer lifetime than the data it references +} + +fn ordering5<'a, 'b>(a: &'a uint, b: &'b uint, x: Option<&'a &'b uint>) { let z: Option<&'a &'b uint> = None; } diff --git a/src/test/compile-fail/regions-free-region-ordering-caller.rs b/src/test/compile-fail/regions-free-region-ordering-caller.rs index 2f8caabb7f8..55c0cf3bb26 100644 --- a/src/test/compile-fail/regions-free-region-ordering-caller.rs +++ b/src/test/compile-fail/regions-free-region-ordering-caller.rs @@ -16,18 +16,18 @@ struct Paramd<'a> { x: &'a uint } fn call2<'a, 'b>(a: &'a uint, b: &'b uint) { let z: Option<&'b &'a uint> = None; - //~^ ERROR pointer has a longer lifetime than the data it references + //~^ ERROR reference has a longer lifetime than the data it references } fn call3<'a, 'b>(a: &'a uint, b: &'b uint) { let y: Paramd<'a> = Paramd { x: a }; let z: Option<&'b Paramd<'a>> = None; - //~^ ERROR pointer has a longer lifetime than the data it references + //~^ ERROR reference has a longer lifetime than the data it references } fn call4<'a, 'b>(a: &'a uint, b: &'b uint) { - let z: Option<|&'a &'b uint|> = None; - //~^ ERROR pointer has a longer lifetime than the data it references + let z: Option<&'a &'b uint> = None; + //~^ ERROR reference has a longer lifetime than the data it references } diff --git a/src/test/compile-fail/regions-free-region-ordering-incorrect.rs b/src/test/compile-fail/regions-free-region-ordering-incorrect.rs index 6f6b6761735..9cb61c24922 100644 --- a/src/test/compile-fail/regions-free-region-ordering-incorrect.rs +++ b/src/test/compile-fail/regions-free-region-ordering-incorrect.rs @@ -15,7 +15,7 @@ // // This test began its life as a test for issue #4325. -struct Node<'b, T> { +struct Node<'b, T:'b> { val: T, next: Option<&'b Node<'b, T>> } diff --git a/src/test/compile-fail/regions-freevar.rs b/src/test/compile-fail/regions-freevar.rs index cef3b525997..76bbe71cf75 100644 --- a/src/test/compile-fail/regions-freevar.rs +++ b/src/test/compile-fail/regions-freevar.rs @@ -12,7 +12,7 @@ fn wants_static_fn(_x: ||: 'static) {} fn main() { let i = 3i; - wants_static_fn(|| { //~ ERROR cannot infer - println!("i={}", i); + wants_static_fn(|| { + println!("i={}", i); //~ ERROR captured variable `i` does not outlive }) } diff --git a/src/test/compile-fail/regions-infer-bound-from-trait-self.rs b/src/test/compile-fail/regions-infer-bound-from-trait-self.rs new file mode 100644 index 00000000000..25fd20b6ec5 --- /dev/null +++ b/src/test/compile-fail/regions-infer-bound-from-trait-self.rs @@ -0,0 +1,61 @@ +// 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 can derive lifetime bounds on `Self` from trait +// inheritance. + +trait Static : 'static { } + +trait Is<'a> : 'a { } + +struct Inv<'a> { + x: Option<&'a mut &'a int> +} + +fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { } + +// In these case, `Self` inherits `'static`. + +trait InheritsFromStatic : 'static { + fn foo1<'a>(self, x: Inv<'a>) { + check_bound(x, self) + } +} +trait InheritsFromStaticIndirectly : Static { + fn foo1<'a>(self, x: Inv<'a>) { + check_bound(x, self) + } +} + + +// In these case, `Self` inherits `'a`. + +trait InheritsFromIs<'a> : 'a { + fn foo(self, x: Inv<'a>) { + check_bound(x, self) + } +} + +trait InheritsFromIsIndirectly<'a> : Is<'a> { + fn foo(self, x: Inv<'a>) { + check_bound(x, self) + } +} + +// In this case, `Self` inherits nothing. + +trait InheritsFromNothing<'a> { + fn foo(self, x: Inv<'a>) { + check_bound(x, self) + //~^ ERROR parameter type `Self` may not live long enough + } +} + +fn main() { } diff --git a/src/test/compile-fail/regions-infer-bound-from-trait.rs b/src/test/compile-fail/regions-infer-bound-from-trait.rs new file mode 100644 index 00000000000..d1111377f1e --- /dev/null +++ b/src/test/compile-fail/regions-infer-bound-from-trait.rs @@ -0,0 +1,50 @@ +// 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 can derive lifetime bounds on type parameters +// from trait inheritance. + +trait Static : 'static { } + +trait Is<'a> : 'a { } + +struct Inv<'a> { + x: Option<&'a mut &'a int> +} + +fn check_bound<'a,A:'a>(x: Inv<'a>, a: A) { } + +// In all of these cases, we can derive a bound for A that is longer +// than 'a based on the trait bound of A: + +fn foo1<'a,A:Static>(x: Inv<'a>, a: A) { + check_bound(x, a) +} + +fn foo2<'a,A:Static>(x: Inv<'static>, a: A) { + check_bound(x, a) +} + +fn foo3<'a,A:Is<'a>>(x: Inv<'a>, a: A) { + check_bound(x, a) +} + +// In these cases, there is no trait bound, so we cannot derive any +// bound for A and we get an error: + +fn bar1<'a,A>(x: Inv<'a>, a: A) { + check_bound(x, a) //~ ERROR parameter type `A` may not live long enough +} + +fn bar2<'a,'b,A:Is<'b>>(x: Inv<'a>, y: Inv<'b>, a: A) { + check_bound(x, a) //~ ERROR parameter type `A` may not live long enough +} + +fn main() { } diff --git a/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs b/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs index a743ff81b30..0fa4969b54c 100644 --- a/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs +++ b/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs @@ -11,7 +11,7 @@ // check that the &int here does not cause us to think that `foo` // contains region pointers -struct foo(proc(x: &int)); +struct foo(proc(x: &int):'static); fn take_foo(x: foo<'static>) {} //~ ERROR wrong number of lifetime parameters diff --git a/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs b/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs new file mode 100644 index 00000000000..a52d2f9f9a0 --- /dev/null +++ b/src/test/compile-fail/regions-lifetime-bounds-on-fns.rs @@ -0,0 +1,41 @@ +// 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. + +#![no_std] + +fn a<'a, 'b:'a>(x: &mut &'a int, y: &mut &'b int) { + // Note: this is legal because of the `'b:'a` declaration. + *x = *y; +} + +fn b<'a, 'b>(x: &mut &'a int, y: &mut &'b int) { + // Illegal now because there is no `'b:'a` declaration. + *x = *y; //~ ERROR mismatched types +} + +fn c<'a,'b>(x: &mut &'a int, y: &mut &'b int) { + // Here we try to call `foo` but do not know that `'a` and `'b` are + // related as required. + a(x, y); //~ ERROR cannot infer +} + +fn d() { + // 'a and 'b are early bound in the function `a` because they appear + // inconstraints: + let _: fn(&mut &int, &mut &int) = a; //~ ERROR mismatched types +} + +fn e() { + // 'a and 'b are late bound in the function `b` because there are + // no constraints: + let _: fn(&mut &int, &mut &int) = b; +} + +fn main() { } diff --git a/src/test/compile-fail/regions-proc-bound-capture.rs b/src/test/compile-fail/regions-proc-bound-capture.rs new file mode 100644 index 00000000000..e32ef275256 --- /dev/null +++ b/src/test/compile-fail/regions-proc-bound-capture.rs @@ -0,0 +1,26 @@ +// 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. + +fn borrowed_proc<'a>(x: &'a int) -> proc():'a -> int { + // This is legal, because the region bound on `proc` + // states that it captures `x`. + proc() { + *x + } +} + +fn static_proc<'a>(x: &'a int) -> proc():'static -> int { + // This is illegal, because the region bound on `proc` is 'static. + proc() { //~ ERROR captured variable `x` outlives the `proc()` + *x + } +} + +fn main() { } diff --git a/src/test/compile-fail/regions-bound-lists-feature-gate.rs b/src/test/compile-fail/regions-proc-bounds.rs index de3b2faef86..db71bc4e15c 100644 --- a/src/test/compile-fail/regions-bound-lists-feature-gate.rs +++ b/src/test/compile-fail/regions-proc-bounds.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +fn is_static<T: 'static>() {} -trait Foo { } +fn foo<'a>() { + is_static::<proc():'a>(); + //~^ ERROR does not fulfill the required lifetime -fn foo<'a>(x: Box<Foo + 'a>) { //~ ERROR only the 'static lifetime is accepted here -} - -fn bar<'a, T:'a>() { //~ ERROR only the 'static lifetime is accepted here + is_static::<proc():'static>(); } fn main() { } diff --git a/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref-mut-ref.rs b/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref-mut-ref.rs index d3e0740a0fe..50ea8b1f2ed 100644 --- a/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref-mut-ref.rs +++ b/src/test/compile-fail/regions-reborrow-from-shorter-mut-ref-mut-ref.rs @@ -11,7 +11,7 @@ // Issue #8624. Test for reborrowing with 3 levels, not just two. fn copy_borrowed_ptr<'a, 'b, 'c>(p: &'a mut &'b mut &'c mut int) -> &'b mut int { - &mut ***p //~ ERROR cannot infer an appropriate lifetime + &mut ***p //~ ERROR lifetime of `p` is too short to guarantee its contents } fn main() { diff --git a/src/test/compile-fail/regions-ret-borrowed-1.rs b/src/test/compile-fail/regions-ret-borrowed-1.rs index df46b2aaac0..aac81a2af6b 100644 --- a/src/test/compile-fail/regions-ret-borrowed-1.rs +++ b/src/test/compile-fail/regions-ret-borrowed-1.rs @@ -18,8 +18,9 @@ fn with<R>(f: <'a>|x: &'a int| -> R) -> R { fn return_it<'a>() -> &'a int { with(|o| o) - //~^ ERROR lifetime of return value does not outlive the function call - //~^^ ERROR cannot infer + //~^ ERROR cannot infer + //~^^ ERROR not valid during the expression + //~^^^ ERROR not valid at this point } fn main() { diff --git a/src/test/compile-fail/regions-ret-borrowed.rs b/src/test/compile-fail/regions-ret-borrowed.rs index 507a48fb741..dd9421ee2ef 100644 --- a/src/test/compile-fail/regions-ret-borrowed.rs +++ b/src/test/compile-fail/regions-ret-borrowed.rs @@ -21,8 +21,9 @@ fn with<R>(f: |x: &int| -> R) -> R { fn return_it<'a>() -> &'a int { with(|o| o) - //~^ ERROR lifetime of return value does not outlive the function call - //~^^ ERROR cannot infer + //~^ ERROR cannot infer + //~^^ ERROR not valid during the expression + //~^^^ ERROR not valid at this point } fn main() { diff --git a/src/test/compile-fail/regions-struct-not-wf.rs b/src/test/compile-fail/regions-struct-not-wf.rs new file mode 100644 index 00000000000..3de137a9efb --- /dev/null +++ b/src/test/compile-fail/regions-struct-not-wf.rs @@ -0,0 +1,32 @@ +// 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. + +// Various examples of structs whose fields are not well-formed. + +#![no_std] +#![allow(dead_code)] + +struct Ref<'a, T> { //~ ERROR the parameter type `T` may not live long enough + field: &'a T +} + +struct RefOk<'a, T:'a> { + field: &'a T +} + +struct RefIndirect<'a, T> { //~ ERROR the parameter type `T` may not live long enough + field: RefOk<'a, T> +} + +struct DoubleRef<'a, 'b, T> { //~ ERROR reference has a longer lifetime than the data it references + field: &'a &'b T +} + +fn main() { } diff --git a/src/test/compile-fail/regions-trait-variance.rs b/src/test/compile-fail/regions-trait-variance.rs index 53cfd4e0324..3ceb4e3fef6 100644 --- a/src/test/compile-fail/regions-trait-variance.rs +++ b/src/test/compile-fail/regions-trait-variance.rs @@ -31,7 +31,7 @@ impl Drop for B { } struct A<'r> { - p: &'r X + p: &'r X+'r } fn make_a(p:&X) -> A { diff --git a/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs b/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs index 5cc3f1bdc37..7dcdc9875e3 100644 --- a/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs +++ b/src/test/compile-fail/regions-variance-covariant-use-contravariant.rs @@ -31,7 +31,7 @@ fn use_<'short,'long>(c: Covariant<'long>, // contravariant with respect to its parameter 'a. let _: Covariant<'short> = c; //~ ERROR mismatched types - //~^ ERROR cannot infer an appropriate lifetime + //~^ ERROR cannot infer an appropriate lifetime } fn main() {} diff --git a/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs b/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs index 0790c3f956a..d09e6babe09 100644 --- a/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs +++ b/src/test/compile-fail/regions-variance-invariant-use-contravariant.rs @@ -15,7 +15,7 @@ // variance inference works in the first place. struct Invariant<'a> { - f: &'static mut &'a int + f: &'a mut &'a int } fn use_<'short,'long>(c: Invariant<'long>, diff --git a/src/test/compile-fail/regions-variance-invariant-use-covariant.rs b/src/test/compile-fail/regions-variance-invariant-use-covariant.rs index 9cdd05f8ebe..861668ad50d 100644 --- a/src/test/compile-fail/regions-variance-invariant-use-covariant.rs +++ b/src/test/compile-fail/regions-variance-invariant-use-covariant.rs @@ -15,7 +15,7 @@ // variance inference works in the first place. struct Invariant<'a> { - f: &'static mut &'a int + f: &'a mut &'a int } fn use_<'b>(c: Invariant<'b>) { diff --git a/src/test/compile-fail/selftype-traittype.rs b/src/test/compile-fail/selftype-traittype.rs index 3bf547e3aff..bf7c3b261fd 100644 --- a/src/test/compile-fail/selftype-traittype.rs +++ b/src/test/compile-fail/selftype-traittype.rs @@ -13,7 +13,7 @@ trait add { fn plus(&self, x: Self) -> Self; } -fn do_add(x: Box<add>, y: Box<add>) -> Box<add> { +fn do_add(x: Box<add+'static>, y: Box<add+'static>) -> Box<add+'static> { x.plus(y) //~ ERROR cannot call a method whose type contains a self-type through an object } diff --git a/src/test/compile-fail/static-region-bound.rs b/src/test/compile-fail/static-region-bound.rs index c36610fc79e..2cb1f462e1d 100644 --- a/src/test/compile-fail/static-region-bound.rs +++ b/src/test/compile-fail/static-region-bound.rs @@ -16,6 +16,6 @@ fn f<T:'static>(_: T) {} fn main() { let x = box(GC) 3i; f(x); - let x = &3i; - f(x); //~ ERROR instantiating a type parameter with an incompatible type + let x = &3i; //~ ERROR borrowed value does not live long enough + f(x); } diff --git a/src/test/compile-fail/trailing-plus-in-bounds.rs b/src/test/compile-fail/trailing-plus-in-bounds.rs index e8f9ed4d2cf..b189acb685a 100644 --- a/src/test/compile-fail/trailing-plus-in-bounds.rs +++ b/src/test/compile-fail/trailing-plus-in-bounds.rs @@ -11,7 +11,7 @@ use std::fmt::Show; fn main() { - let x: Box<Show+> = box 3 as Box<Show+>; + let x: Box<Show+> = box 3i as Box<Show+>; //~^ ERROR at least one type parameter bound must be specified //~^^ ERROR at least one type parameter bound must be specified } diff --git a/src/test/compile-fail/trait-bounds-sugar.rs b/src/test/compile-fail/trait-bounds-sugar.rs index c3d608b48f3..7ed8db4fcd2 100644 --- a/src/test/compile-fail/trait-bounds-sugar.rs +++ b/src/test/compile-fail/trait-bounds-sugar.rs @@ -16,15 +16,16 @@ trait Foo {} fn a(_x: Box<Foo+Send>) { } -fn b(_x: &'static Foo) { // should be same as &'static Foo+'static +fn b(_x: &'static Foo+'static) { } fn c(x: Box<Foo+Sync>) { - a(x); //~ ERROR expected bounds `Send` + a(x); //~ ERROR mismatched types } fn d(x: &'static Foo+Sync) { - b(x); //~ ERROR expected bounds `'static` + b(x); //~ ERROR cannot infer + //~^ ERROR mismatched types } fn main() {} diff --git a/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs b/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs index 0f9cfab7b8a..9694c1d9f98 100644 --- a/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs +++ b/src/test/compile-fail/typeck_type_placeholder_lifetime_1.rs @@ -11,7 +11,7 @@ // This test checks that the `_` type placeholder does not react // badly if put as a lifetime parameter. -struct Foo<'a, T> { +struct Foo<'a, T:'a> { r: &'a T } diff --git a/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs b/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs index e9671b353b9..365b786cc1a 100644 --- a/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs +++ b/src/test/compile-fail/typeck_type_placeholder_lifetime_2.rs @@ -11,7 +11,7 @@ // This test checks that the `_` type placeholder does not react // badly if put as a lifetime parameter. -struct Foo<'a, T> { +struct Foo<'a, T:'a> { r: &'a T } diff --git a/src/test/compile-fail/unconstrained-ref.rs b/src/test/compile-fail/unconstrained-ref.rs index a4125f94cd2..87647cdb546 100644 --- a/src/test/compile-fail/unconstrained-ref.rs +++ b/src/test/compile-fail/unconstrained-ref.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct S<'a, T> { +struct S<'a, T:'a> { o: &'a Option<T> } diff --git a/src/test/compile-fail/unsized4.rs b/src/test/compile-fail/unsized4.rs index e377c9d5f41..a66c1d85009 100644 --- a/src/test/compile-fail/unsized4.rs +++ b/src/test/compile-fail/unsized4.rs @@ -12,7 +12,7 @@ trait T {} fn f<Sized? Y: T>() { -//~^ERROR incompatible bounds on type parameter Y, bound T does not allow unsized type +//~^ERROR incompatible bounds on type parameter `Y`, bound `T` does not allow unsized type } pub fn main() { diff --git a/src/test/compile-fail/use-after-move-implicity-coerced-object.rs b/src/test/compile-fail/use-after-move-implicity-coerced-object.rs index 043f3a233a6..3f2f43b0c9b 100644 --- a/src/test/compile-fail/use-after-move-implicity-coerced-object.rs +++ b/src/test/compile-fail/use-after-move-implicity-coerced-object.rs @@ -23,10 +23,10 @@ impl fmt::Show for Number { } struct List { - list: Vec<Box<ToString>> } + list: Vec<Box<ToString+'static>> } impl List { - fn push(&mut self, n: Box<ToString>) { + fn push(&mut self, n: Box<ToString+'static>) { self.list.push(n); } } diff --git a/src/test/compile-fail/variance-regions-direct.rs b/src/test/compile-fail/variance-regions-direct.rs index da4f9846187..fa38482b21c 100644 --- a/src/test/compile-fail/variance-regions-direct.rs +++ b/src/test/compile-fail/variance-regions-direct.rs @@ -32,7 +32,7 @@ struct Test3<'a, 'b, 'c> { //~ ERROR regions=[[+, +, +];[];[]] // Mutability induces invariance: #[rustc_variance] -struct Test4<'a, 'b> { //~ ERROR regions=[[-, o];[];[]] +struct Test4<'a, 'b:'a> { //~ ERROR regions=[[-, o];[];[]] x: &'a mut &'b int, } @@ -64,7 +64,7 @@ struct Test7<'a> { //~ ERROR regions=[[*];[];[]] // Try enums too. #[rustc_variance] -enum Test8<'a, 'b, 'c> { //~ ERROR regions=[[+, -, o];[];[]] +enum Test8<'a, 'b, 'c:'b> { //~ ERROR regions=[[+, -, o];[];[]] Test8A(extern "Rust" fn(&'a int)), Test8B(&'b [int]), Test8C(&'b mut &'c str), diff --git a/src/test/compile-fail/variance-regions-indirect.rs b/src/test/compile-fail/variance-regions-indirect.rs index 0d20f652496..c049fbc0fed 100644 --- a/src/test/compile-fail/variance-regions-indirect.rs +++ b/src/test/compile-fail/variance-regions-indirect.rs @@ -13,29 +13,29 @@ // Try enums too. #[rustc_variance] -enum Base<'a, 'b, 'c, 'd> { //~ ERROR regions=[[+, -, o, *];[];[]] +enum Base<'a, 'b, 'c:'b, 'd> { //~ ERROR regions=[[+, -, o, *];[];[]] Test8A(extern "Rust" fn(&'a int)), Test8B(&'b [int]), Test8C(&'b mut &'c str), } #[rustc_variance] -struct Derived1<'w, 'x, 'y, 'z> { //~ ERROR regions=[[*, o, -, +];[];[]] +struct Derived1<'w, 'x:'y, 'y, 'z> { //~ ERROR regions=[[*, o, -, +];[];[]] f: Base<'z, 'y, 'x, 'w> } #[rustc_variance] // Combine - and + to yield o -struct Derived2<'a, 'b, 'c> { //~ ERROR regions=[[o, o, *];[];[]] +struct Derived2<'a, 'b:'a, 'c> { //~ ERROR regions=[[o, o, *];[];[]] f: Base<'a, 'a, 'b, 'c> } #[rustc_variance] // Combine + and o to yield o (just pay attention to 'a here) -struct Derived3<'a, 'b, 'c> { //~ ERROR regions=[[o, -, *];[];[]] +struct Derived3<'a:'b, 'b, 'c> { //~ ERROR regions=[[o, -, *];[];[]] f: Base<'a, 'b, 'a, 'c> } #[rustc_variance] // Combine + and * to yield + (just pay attention to 'a here) -struct Derived4<'a, 'b, 'c> { //~ ERROR regions=[[+, -, o];[];[]] +struct Derived4<'a, 'b, 'c:'b> { //~ ERROR regions=[[+, -, o];[];[]] f: Base<'a, 'b, 'c, 'a> } |
