Skip to content

Commit ba8ce4c

Browse files
committed
rollup merge of #22319: huonw/send-is-not-static
Conflicts: src/libstd/sync/task_pool.rs src/libstd/thread.rs src/libtest/lib.rs src/test/bench/shootout-reverse-complement.rs src/test/bench/shootout-spectralnorm.rs
2 parents 6ac3799 + 7a14f49 commit ba8ce4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+231
-297
lines changed

src/libcore/marker.rs

+18
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,19 @@ use clone::Clone;
3232
reason = "will be overhauled with new lifetime rules; see RFC 458")]
3333
#[lang="send"]
3434
#[rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely"]
35+
#[cfg(stage0)] // SNAP ac134f7 remove after stage0
3536
pub unsafe trait Send: 'static {
3637
// empty.
3738
}
39+
/// Types able to be transferred across thread boundaries.
40+
#[unstable(feature = "core",
41+
reason = "will be overhauled with new lifetime rules; see RFC 458")]
42+
#[lang="send"]
43+
#[rustc_on_unimplemented = "`{Self}` cannot be sent between threads safely"]
44+
#[cfg(not(stage0))]
45+
pub unsafe trait Send {
46+
// empty.
47+
}
3848

3949
/// Types with a constant size known at compile-time.
4050
#[stable(feature = "rust1", since = "1.0.0")]
@@ -424,3 +434,11 @@ pub struct NoCopy;
424434
#[lang="managed_bound"]
425435
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
426436
pub struct Managed;
437+
438+
#[cfg(not(stage0))] // SNAP ac134f7 remove this attribute after the next snapshot
439+
mod impls {
440+
use super::{Send, Sync, Sized};
441+
442+
unsafe impl<'a, T: Sync + ?Sized> Send for &'a T {}
443+
unsafe impl<'a, T: Send + ?Sized> Send for &'a mut T {}
444+
}

src/librustc/middle/traits/select.rs

+3-29
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use self::EvaluationResult::*;
2020
use super::{DerivedObligationCause};
2121
use super::{project};
2222
use super::project::Normalized;
23-
use super::{PredicateObligation, Obligation, TraitObligation, ObligationCause};
23+
use super::{PredicateObligation, TraitObligation, ObligationCause};
2424
use super::{ObligationCauseCode, BuiltinDerivedObligation};
2525
use super::{SelectionError, Unimplemented, Overflow, OutputTypeParameterMismatch};
2626
use super::{Selection};
@@ -34,7 +34,7 @@ use super::{util};
3434
use middle::fast_reject;
3535
use middle::mem_categorization::Typer;
3636
use middle::subst::{Subst, Substs, TypeSpace, VecPerParamSpace};
37-
use middle::ty::{self, AsPredicate, RegionEscape, ToPolyTraitRef, Ty};
37+
use middle::ty::{self, RegionEscape, ToPolyTraitRef, Ty};
3838
use middle::infer;
3939
use middle::infer::{InferCtxt, TypeFreshener};
4040
use middle::ty_fold::TypeFoldable;
@@ -1459,22 +1459,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14591459

14601460
ty::BoundSync |
14611461
ty::BoundSend => {
1462-
// Note: technically, a region pointer is only
1463-
// sendable if it has lifetime
1464-
// `'static`. However, we don't take regions
1465-
// into account when doing trait matching:
1466-
// instead, when we decide that `T : Send`, we
1467-
// will register a separate constraint with
1468-
// the region inferencer that `T : 'static`
1469-
// holds as well (because the trait `Send`
1470-
// requires it). This will ensure that there
1471-
// is no borrowed data in `T` (or else report
1472-
// an inference error). The reason we do it
1473-
// this way is that we do not yet *know* what
1474-
// lifetime the borrowed reference has, since
1475-
// we haven't finished running inference -- in
1476-
// other words, there's a kind of
1477-
// chicken-and-egg problem.
14781462
Ok(If(vec![referent_ty]))
14791463
}
14801464
}
@@ -1817,21 +1801,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18171801
}
18181802
})
18191803
}).collect::<Result<_, _>>();
1820-
let mut obligations = match obligations {
1804+
let obligations = match obligations {
18211805
Ok(o) => o,
18221806
Err(ErrorReported) => Vec::new()
18231807
};
18241808

1825-
// as a special case, `Send` requires `'static`
1826-
if bound == ty::BoundSend {
1827-
obligations.push(Obligation {
1828-
cause: obligation.cause.clone(),
1829-
recursion_depth: obligation.recursion_depth+1,
1830-
predicate: ty::Binder(ty::OutlivesPredicate(obligation.self_ty(),
1831-
ty::ReStatic)).as_predicate(),
1832-
});
1833-
}
1834-
18351809
let obligations = VecPerParamSpace::new(obligations, Vec::new(), Vec::new());
18361810

18371811
debug!("vtable_builtin_data: obligations={}",

src/librustc/util/ppaux.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,8 @@ impl<'tcx> UserString<'tcx> for ty::TyTrait<'tcx> {
697697
}
698698

699699
// Region, if not obviously implied by builtin bounds.
700-
if bounds.region_bound != ty::ReStatic ||
701-
!bounds.builtin_bounds.contains(&ty::BoundSend)
702-
{ // Region bound is implied by builtin bounds:
700+
if bounds.region_bound != ty::ReStatic {
701+
// Region bound is implied by builtin bounds:
703702
components.push(bounds.region_bound.user_string(tcx));
704703
}
705704

src/libstd/old_io/net/pipe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ mod tests {
287287

288288
pub fn smalltest<F,G>(server: F, client: G)
289289
where F : FnOnce(UnixStream), F : Send,
290-
G : FnOnce(UnixStream), G : Send
290+
G : FnOnce(UnixStream), G : Send + 'static
291291
{
292292
let path1 = next_test_unix();
293293
let path2 = path1.clone();

src/libstd/process.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl Child {
458458
/// the parent waits for the child to exit.
459459
pub fn wait_with_output(mut self) -> io::Result<Output> {
460460
drop(self.stdin.take());
461-
fn read<T: Read + Send>(stream: Option<T>) -> Receiver<io::Result<Vec<u8>>> {
461+
fn read<T: Read + Send + 'static>(stream: Option<T>) -> Receiver<io::Result<Vec<u8>>> {
462462
let (tx, rx) = channel();
463463
match stream {
464464
Some(stream) => {

src/libstd/rt/at_exit_imp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use mem;
2020
use thunk::Thunk;
2121
use sys_common::mutex::{Mutex, MUTEX_INIT};
2222

23-
type Queue = Vec<Thunk>;
23+
type Queue = Vec<Thunk<'static>>;
2424

2525
// NB these are specifically not types from `std::sync` as they currently rely
2626
// on poisoning and this module needs to operate at a lower level than requiring
@@ -65,7 +65,7 @@ pub fn cleanup() {
6565
}
6666
}
6767

68-
pub fn push(f: Thunk) {
68+
pub fn push(f: Thunk<'static>) {
6969
unsafe {
7070
LOCK.lock();
7171
init();

src/libstd/rt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int {
148148
///
149149
/// It is forbidden for procedures to register more `at_exit` handlers when they
150150
/// are running, and doing so will lead to a process abort.
151-
pub fn at_exit<F:FnOnce()+Send>(f: F) {
151+
pub fn at_exit<F:FnOnce()+Send+'static>(f: F) {
152152
at_exit_imp::push(Thunk::new(f));
153153
}
154154

src/libstd/rt/unwind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use rt::libunwind as uw;
7474

7575
struct Exception {
7676
uwe: uw::_Unwind_Exception,
77-
cause: Option<Box<Any + Send>>,
77+
cause: Option<Box<Any + Send + 'static>>,
7878
}
7979

8080
pub type Callback = fn(msg: &(Any + Send), file: &'static str, line: uint);
@@ -161,7 +161,7 @@ pub fn panicking() -> bool {
161161
#[inline(never)]
162162
#[no_mangle]
163163
#[allow(private_no_mangle_fns)]
164-
fn rust_panic(cause: Box<Any + Send>) -> ! {
164+
fn rust_panic(cause: Box<Any + Send + 'static>) -> ! {
165165
rtdebug!("begin_unwind()");
166166

167167
unsafe {

src/libstd/sync/future.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub struct Future<A> {
4646
}
4747

4848
enum FutureState<A> {
49-
Pending(Thunk<(),A>),
49+
Pending(Thunk<'static,(),A>),
5050
Evaluating,
5151
Forced(A)
5252
}
@@ -103,7 +103,7 @@ impl<A> Future<A> {
103103
}
104104

105105
pub fn from_fn<F>(f: F) -> Future<A>
106-
where F : FnOnce() -> A, F : Send
106+
where F : FnOnce() -> A, F : Send + 'static
107107
{
108108
/*!
109109
* Create a future from a function.
@@ -117,7 +117,7 @@ impl<A> Future<A> {
117117
}
118118
}
119119

120-
impl<A:Send> Future<A> {
120+
impl<A:Send+'static> Future<A> {
121121
pub fn from_receiver(rx: Receiver<A>) -> Future<A> {
122122
/*!
123123
* Create a future from a port
@@ -132,7 +132,7 @@ impl<A:Send> Future<A> {
132132
}
133133

134134
pub fn spawn<F>(blk: F) -> Future<A>
135-
where F : FnOnce() -> A, F : Send
135+
where F : FnOnce() -> A, F : Send + 'static
136136
{
137137
/*!
138138
* Create a future from a unique closure.

src/libstd/sync/mpsc/mod.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ pub struct Receiver<T> {
345345

346346
// The receiver port can be sent from place to place, so long as it
347347
// is not used to receive non-sendable things.
348-
unsafe impl<T:Send> Send for Receiver<T> { }
348+
unsafe impl<T: Send + 'static> Send for Receiver<T> { }
349349

350350
/// An iterator over messages on a receiver, this iterator will block
351351
/// whenever `next` is called, waiting for a new message, and `None` will be
@@ -364,7 +364,7 @@ pub struct Sender<T> {
364364

365365
// The send port can be sent from place to place, so long as it
366366
// is not used to send non-sendable things.
367-
unsafe impl<T:Send> Send for Sender<T> { }
367+
unsafe impl<T: Send + 'static> Send for Sender<T> { }
368368

369369
/// The sending-half of Rust's synchronous channel type. This half can only be
370370
/// owned by one task, but it can be cloned to send to other tasks.
@@ -373,7 +373,7 @@ pub struct SyncSender<T> {
373373
inner: Arc<UnsafeCell<sync::Packet<T>>>,
374374
}
375375

376-
unsafe impl<T:Send> Send for SyncSender<T> {}
376+
unsafe impl<T: Send + 'static> Send for SyncSender<T> {}
377377

378378
impl<T> !Sync for SyncSender<T> {}
379379

@@ -485,7 +485,7 @@ impl<T> UnsafeFlavor<T> for Receiver<T> {
485485
/// println!("{:?}", rx.recv().unwrap());
486486
/// ```
487487
#[stable(feature = "rust1", since = "1.0.0")]
488-
pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
488+
pub fn channel<T: Send + 'static>() -> (Sender<T>, Receiver<T>) {
489489
let a = Arc::new(UnsafeCell::new(oneshot::Packet::new()));
490490
(Sender::new(Flavor::Oneshot(a.clone())), Receiver::new(Flavor::Oneshot(a)))
491491
}
@@ -525,7 +525,7 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
525525
/// assert_eq!(rx.recv().unwrap(), 2);
526526
/// ```
527527
#[stable(feature = "rust1", since = "1.0.0")]
528-
pub fn sync_channel<T: Send>(bound: uint) -> (SyncSender<T>, Receiver<T>) {
528+
pub fn sync_channel<T: Send + 'static>(bound: uint) -> (SyncSender<T>, Receiver<T>) {
529529
let a = Arc::new(UnsafeCell::new(sync::Packet::new(bound)));
530530
(SyncSender::new(a.clone()), Receiver::new(Flavor::Sync(a)))
531531
}
@@ -534,7 +534,7 @@ pub fn sync_channel<T: Send>(bound: uint) -> (SyncSender<T>, Receiver<T>) {
534534
// Sender
535535
////////////////////////////////////////////////////////////////////////////////
536536

537-
impl<T: Send> Sender<T> {
537+
impl<T: Send + 'static> Sender<T> {
538538
fn new(inner: Flavor<T>) -> Sender<T> {
539539
Sender {
540540
inner: UnsafeCell::new(inner),
@@ -616,7 +616,7 @@ impl<T: Send> Sender<T> {
616616
}
617617

618618
#[stable(feature = "rust1", since = "1.0.0")]
619-
impl<T: Send> Clone for Sender<T> {
619+
impl<T: Send + 'static> Clone for Sender<T> {
620620
fn clone(&self) -> Sender<T> {
621621
let (packet, sleeper, guard) = match *unsafe { self.inner() } {
622622
Flavor::Oneshot(ref p) => {
@@ -662,7 +662,7 @@ impl<T: Send> Clone for Sender<T> {
662662

663663
#[unsafe_destructor]
664664
#[stable(feature = "rust1", since = "1.0.0")]
665-
impl<T: Send> Drop for Sender<T> {
665+
impl<T: Send + 'static> Drop for Sender<T> {
666666
fn drop(&mut self) {
667667
match *unsafe { self.inner_mut() } {
668668
Flavor::Oneshot(ref mut p) => unsafe { (*p.get()).drop_chan(); },
@@ -677,7 +677,7 @@ impl<T: Send> Drop for Sender<T> {
677677
// SyncSender
678678
////////////////////////////////////////////////////////////////////////////////
679679

680-
impl<T: Send> SyncSender<T> {
680+
impl<T: Send + 'static> SyncSender<T> {
681681
fn new(inner: Arc<UnsafeCell<sync::Packet<T>>>) -> SyncSender<T> {
682682
SyncSender { inner: inner }
683683
}
@@ -717,7 +717,7 @@ impl<T: Send> SyncSender<T> {
717717
}
718718

719719
#[stable(feature = "rust1", since = "1.0.0")]
720-
impl<T: Send> Clone for SyncSender<T> {
720+
impl<T: Send + 'static> Clone for SyncSender<T> {
721721
fn clone(&self) -> SyncSender<T> {
722722
unsafe { (*self.inner.get()).clone_chan(); }
723723
return SyncSender::new(self.inner.clone());
@@ -726,7 +726,7 @@ impl<T: Send> Clone for SyncSender<T> {
726726

727727
#[unsafe_destructor]
728728
#[stable(feature = "rust1", since = "1.0.0")]
729-
impl<T: Send> Drop for SyncSender<T> {
729+
impl<T: Send + 'static> Drop for SyncSender<T> {
730730
fn drop(&mut self) {
731731
unsafe { (*self.inner.get()).drop_chan(); }
732732
}
@@ -736,7 +736,7 @@ impl<T: Send> Drop for SyncSender<T> {
736736
// Receiver
737737
////////////////////////////////////////////////////////////////////////////////
738738

739-
impl<T: Send> Receiver<T> {
739+
impl<T: Send + 'static> Receiver<T> {
740740
fn new(inner: Flavor<T>) -> Receiver<T> {
741741
Receiver { inner: UnsafeCell::new(inner) }
742742
}
@@ -855,7 +855,7 @@ impl<T: Send> Receiver<T> {
855855
}
856856
}
857857

858-
impl<T: Send> select::Packet for Receiver<T> {
858+
impl<T: Send + 'static> select::Packet for Receiver<T> {
859859
fn can_recv(&self) -> bool {
860860
loop {
861861
let new_port = match *unsafe { self.inner() } {
@@ -942,15 +942,15 @@ impl<T: Send> select::Packet for Receiver<T> {
942942
}
943943

944944
#[stable(feature = "rust1", since = "1.0.0")]
945-
impl<'a, T: Send> Iterator for Iter<'a, T> {
945+
impl<'a, T: Send + 'static> Iterator for Iter<'a, T> {
946946
type Item = T;
947947

948948
fn next(&mut self) -> Option<T> { self.rx.recv().ok() }
949949
}
950950

951951
#[unsafe_destructor]
952952
#[stable(feature = "rust1", since = "1.0.0")]
953-
impl<T: Send> Drop for Receiver<T> {
953+
impl<T: Send + 'static> Drop for Receiver<T> {
954954
fn drop(&mut self) {
955955
match *unsafe { self.inner_mut() } {
956956
Flavor::Oneshot(ref mut p) => unsafe { (*p.get()).drop_port(); },

src/libstd/sync/mpsc/mpsc_queue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub struct Queue<T> {
7878
}
7979

8080
unsafe impl<T:Send> Send for Queue<T> { }
81-
unsafe impl<T:Send> Sync for Queue<T> { }
81+
unsafe impl<T: Send + 'static> Sync for Queue<T> { }
8282

8383
impl<T> Node<T> {
8484
unsafe fn new(v: Option<T>) -> *mut Node<T> {
@@ -89,7 +89,7 @@ impl<T> Node<T> {
8989
}
9090
}
9191

92-
impl<T: Send> Queue<T> {
92+
impl<T: Send + 'static> Queue<T> {
9393
/// Creates a new queue that is safe to share among multiple producers and
9494
/// one consumer.
9595
pub fn new() -> Queue<T> {
@@ -140,7 +140,7 @@ impl<T: Send> Queue<T> {
140140

141141
#[unsafe_destructor]
142142
#[stable(feature = "rust1", since = "1.0.0")]
143-
impl<T: Send> Drop for Queue<T> {
143+
impl<T: Send + 'static> Drop for Queue<T> {
144144
fn drop(&mut self) {
145145
unsafe {
146146
let mut cur = *self.tail.get();

src/libstd/sync/mpsc/oneshot.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ enum MyUpgrade<T> {
8888
GoUp(Receiver<T>),
8989
}
9090

91-
impl<T: Send> Packet<T> {
91+
impl<T: Send + 'static> Packet<T> {
9292
pub fn new() -> Packet<T> {
9393
Packet {
9494
data: None,
@@ -368,7 +368,7 @@ impl<T: Send> Packet<T> {
368368
}
369369

370370
#[unsafe_destructor]
371-
impl<T: Send> Drop for Packet<T> {
371+
impl<T: Send + 'static> Drop for Packet<T> {
372372
fn drop(&mut self) {
373373
assert_eq!(self.state.load(Ordering::SeqCst), DISCONNECTED);
374374
}

0 commit comments

Comments
 (0)