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/libsync/comm | |
| 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/libsync/comm')
| -rw-r--r-- | src/libsync/comm/mod.rs | 8 | ||||
| -rw-r--r-- | src/libsync/comm/select.rs | 20 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/libsync/comm/mod.rs b/src/libsync/comm/mod.rs index 16bcdd9bbb6..16f6eea6144 100644 --- a/src/libsync/comm/mod.rs +++ b/src/libsync/comm/mod.rs @@ -386,6 +386,14 @@ pub struct Receiver<T> { /// whenever `next` is called, waiting for a new message, and `None` will be /// returned when the corresponding channel has hung up. #[unstable] +#[cfg(not(stage0))] +pub struct Messages<'a, T:'a> { + rx: &'a Receiver<T> +} + +/// Stage0 only +#[cfg(stage0)] +#[unstable] pub struct Messages<'a, T> { rx: &'a Receiver<T> } diff --git a/src/libsync/comm/select.rs b/src/libsync/comm/select.rs index 737a4bfe299..dc9891dd1ee 100644 --- a/src/libsync/comm/select.rs +++ b/src/libsync/comm/select.rs @@ -76,6 +76,24 @@ pub struct Select { /// A handle to a receiver which is currently a member of a `Select` set of /// receivers. This handle is used to keep the receiver in the set as well as /// interact with the underlying receiver. +#[cfg(not(stage0))] +pub struct Handle<'rx, T:'rx> { + /// The ID of this handle, used to compare against the return value of + /// `Select::wait()` + id: uint, + selector: &'rx Select, + next: *mut Handle<'static, ()>, + prev: *mut Handle<'static, ()>, + added: bool, + packet: &'rx Packet+'rx, + + // due to our fun transmutes, we be sure to place this at the end. (nothing + // previous relies on T) + rx: &'rx Receiver<T>, +} + +/// Stage0 only +#[cfg(stage0)] pub struct Handle<'rx, T> { /// The ID of this handle, used to compare against the return value of /// `Select::wait()` @@ -84,7 +102,7 @@ pub struct Handle<'rx, T> { next: *mut Handle<'static, ()>, prev: *mut Handle<'static, ()>, added: bool, - packet: &'rx Packet, + packet: &'rx Packet+'rx, // due to our fun transmutes, we be sure to place this at the end. (nothing // previous relies on T) |
