diff options
| author | bors <bors@rust-lang.org> | 2014-08-28 15:01:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-08-28 15:01:39 +0000 |
| commit | b5165321e48c1fd8422803fb40693afab7939c8c (patch) | |
| tree | a3206dbc34acc88311a3ec676155240681784906 /src/liballoc | |
| parent | 0d3bd7720c50e3ada4bac77331d43926493be4fe (diff) | |
| parent | 1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f (diff) | |
| download | rust-b5165321e48c1fd8422803fb40693afab7939c8c.tar.gz rust-b5165321e48c1fd8422803fb40693afab7939c8c.zip | |
auto merge of #16453 : nikomatsakis/rust/type-bounds-3, r=pcwalton
Implements https://github.com/rust-lang/rfcs/pull/192.
In particular:
1. type parameters can have lifetime bounds and objects can close over borrowed values, presuming that they have suitable bounds.
2. objects must have a bound, though it may be derived from the trait itself or from a `Send` bound.
3. all types must be well-formed.
4. type parameters and lifetime parameters may themselves have lifetimes as bounds. Something like `T:'a` means "the type T outlives 'a`" and something like `'a:'b`" means "'a outlives 'b". Outlives here means "all borrowed data has a lifetime at least as long".
This is a [breaking-change]. The most common things you have to fix after this change are:
1. Introduce lifetime bounds onto type parameters if your type (directly or indirectly) contains a reference. Thus a struct like `struct Ref<'a, T> { x: &'a T }` would be changed to `struct Ref<'a, T:'a> { x: &'a T }`.
2. Introduce lifetime bounds onto lifetime parameters if your type contains a double reference. Thus a type like `struct RefWrapper<'a, 'b> { r: &'a Ref<'b, int> }` (where `Ref` is defined as before) would need to be changed to `struct RefWrapper<'a, 'b:'a> { ... }`.
2. Explicitly give object lifetimes in structure definitions. Most commonly, this means changing something like `Box<Reader>` to `Box<Reader+'static>`, so as to indicate that this is a reader without any borrowed data. (Note: you may wish to just change to `Box<Reader+Send>` while you're at it; it's a more restrictive type, technically, but means you can send the reader between threads.)
The intuition for points 1 and 2 is that a reference must never outlive its referent (the thing it points at). Therefore, if you have a type `&'a T`, we must know that `T` (whatever it is) outlives `'a`. And so on.
Closes #5723.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 6a3e1fa2862..13d4a0a1f0a 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -105,9 +105,9 @@ pub trait BoxAny { } #[stable] -impl BoxAny for Box<Any> { +impl BoxAny for Box<Any+'static> { #[inline] - fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> { + fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any+'static>> { if self.is::<T>() { unsafe { // Get the raw representation of the trait object @@ -132,7 +132,7 @@ impl<T: fmt::Show> fmt::Show for Box<T> { } } -impl fmt::Show for Box<Any> { +impl fmt::Show for Box<Any+'static> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.pad("Box<Any>") } |
