Skip to content

Commit aae7901

Browse files
committed
auto merge of #16285 : alexcrichton/rust/rename-share, r=huonw
This leaves the `Share` trait at `std::kinds` via a `#[deprecated]` `pub use` statement, but the `NoShare` struct is no longer part of `std::kinds::marker` due to #12660 (the build cannot bootstrap otherwise). All code referencing the `Share` trait should now reference the `Sync` trait, and all code referencing the `NoShare` type should now reference the `NoSync` type. The functionality and meaning of this trait have not changed, only the naming. Closes #16281 [breaking-change]
2 parents 87d2bf4 + 1f760d5 commit aae7901

Some content is hidden

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

59 files changed

+199
-190
lines changed

src/doc/complement-design-faq.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ non-deterministic behavior. Rust provides the tools to make using a GC
5050
possible and even pleasant, but it should not be a requirement for
5151
implementing the language.
5252

53-
## Non-`Share` `static mut` is unsafe
53+
## Non-`Sync` `static mut` is unsafe
5454

55-
Types which are [`Share`][share] are thread-safe when multiple shared
56-
references to them are used concurrently. Types which are not `Share` are not
55+
Types which are [`Sync`][sync] are thread-safe when multiple shared
56+
references to them are used concurrently. Types which are not `Sync` are not
5757
thread-safe, and thus when used in a global require unsafe code to use.
5858

59-
[share]: http://doc.rust-lang.org/core/kinds/trait.Share.html
59+
[sync]: http://doc.rust-lang.org/core/kinds/trait.Sync.html
6060

61-
### If mutable static items that implement `Share` are safe, why is taking &mut SHARABLE unsafe?
61+
### If mutable static items that implement `Sync` are safe, why is taking &mut SHARABLE unsafe?
6262

6363
Having multiple aliasing `&mut T`s is never allowed. Due to the nature of
6464
globals, the borrow checker cannot possibly ensure that a static obeys the

src/doc/guide-unsafe.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,10 @@ Other features provided by lang items include:
699699
- stack unwinding and general failure; the `eh_personality`, `fail_`
700700
and `fail_bounds_checks` lang items.
701701
- the traits in `std::kinds` used to indicate types that satisfy
702-
various kinds; lang items `send`, `share` and `copy`.
702+
various kinds; lang items `send`, `sync` and `copy`.
703703
- the marker types and variance indicators found in
704704
`std::kinds::markers`; lang items `covariant_type`,
705-
`contravariant_lifetime`, `no_share_bound`, etc.
705+
`contravariant_lifetime`, `no_sync_bound`, etc.
706706

707707
Lang items are loaded lazily by the compiler; e.g. if one never uses
708708
`Box` then there is no need to define functions for `exchange_malloc`

src/doc/rust.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,7 @@ A complete list of the built-in language items follows:
21112111
: Has a size known at compile time.
21122112
* `copy`
21132113
: Types that do not move ownership when used by-value.
2114-
* `share`
2114+
* `sync`
21152115
: Able to be safely shared between tasks when aliased.
21162116
* `drop`
21172117
: Have destructors.
@@ -2191,8 +2191,8 @@ These types help drive the compiler's analysis
21912191
: This type does not implement "send", even if eligible
21922192
* `no_copy_bound`
21932193
: This type does not implement "copy", even if eligible
2194-
* `no_share_bound`
2195-
: This type does not implement "share", even if eligible
2194+
* `no_sync_bound`
2195+
: This type does not implement "sync", even if eligible
21962196
* `managed_bound`
21972197
: This type implements "managed"
21982198

src/doc/tutorial.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ and may not be overridden:
21962196
Types are sendable
21972197
unless they contain references.
21982198

2199-
* `Share` - Types that are *threadsafe*.
2199+
* `Sync` - Types that are *threadsafe*.
22002200
These are types that are safe to be used across several threads with access to
22012201
a `&T` pointer. `Mutex<T>` is an example of a *sharable* type with internal mutable data.
22022202

@@ -2250,7 +2250,7 @@ We say that the `Printable` trait _provides_ a `print` method with the
22502250
given signature. This means that we can call `print` on an argument
22512251
of any type that implements the `Printable` trait.
22522252

2253-
Rust's built-in `Send` and `Share` types are examples of traits that
2253+
Rust's built-in `Send` and `Sync` types are examples of traits that
22542254
don't provide any methods.
22552255

22562256
Traits may be implemented for specific types with [impls]. An impl for
@@ -2535,7 +2535,7 @@ select the method to call at runtime.
25352535

25362536
This usage of traits is similar to Java interfaces.
25372537

2538-
There are some built-in bounds, such as `Send` and `Share`, which are properties
2538+
There are some built-in bounds, such as `Send` and `Sync`, which are properties
25392539
of the components of types. By design, trait objects don't know the exact type
25402540
of their contents and so the compiler cannot reason about those properties.
25412541

@@ -2548,7 +2548,7 @@ trait Foo {}
25482548
trait Bar<T> {}
25492549

25502550
fn sendable_foo(f: Box<Foo + Send>) { /* ... */ }
2551-
fn shareable_bar<T: Share>(b: &Bar<T> + Share) { /* ... */ }
2551+
fn sync_bar<T: Sync>(b: &Bar<T> + Sync) { /* ... */ }
25522552
~~~
25532553

25542554
When no colon is specified (such as the type `Box<Foo>`), it is inferred that the

src/etc/vim/syntax/rust.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ syn keyword rustType f64 i8 i16 i32 i64 str Self
7676
" to make it easy to update.
7777

7878
" Core operators {{{3
79-
syn keyword rustTrait Copy Send Sized Share
79+
syn keyword rustTrait Copy Send Sized Sync
8080
syn keyword rustTrait Add Sub Mul Div Rem Neg Not
8181
syn keyword rustTrait BitAnd BitOr BitXor
8282
syn keyword rustTrait Drop Deref DerefMut

src/liballoc/arc.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
use core::atomic;
1717
use core::clone::Clone;
18-
use core::kinds::{Share, Send};
18+
use core::kinds::{Sync, Send};
1919
use core::mem::{min_align_of, size_of, drop};
2020
use core::mem;
2121
use core::ops::{Drop, Deref};
@@ -76,7 +76,7 @@ struct ArcInner<T> {
7676
data: T,
7777
}
7878

79-
impl<T: Share + Send> Arc<T> {
79+
impl<T: Sync + Send> Arc<T> {
8080
/// Create an atomically reference counted wrapper.
8181
#[inline]
8282
#[stable]
@@ -95,8 +95,8 @@ impl<T: Share + Send> Arc<T> {
9595
fn inner(&self) -> &ArcInner<T> {
9696
// This unsafety is ok because while this arc is alive we're guaranteed
9797
// that the inner pointer is valid. Furthermore, we know that the
98-
// `ArcInner` structure itself is `Share` because the inner data is
99-
// `Share` as well, so we're ok loaning out an immutable pointer to
98+
// `ArcInner` structure itself is `Sync` because the inner data is
99+
// `Sync` as well, so we're ok loaning out an immutable pointer to
100100
// these contents.
101101
unsafe { &*self._ptr }
102102
}
@@ -115,7 +115,7 @@ impl<T: Share + Send> Arc<T> {
115115
}
116116

117117
#[unstable = "waiting on stability of Clone"]
118-
impl<T: Share + Send> Clone for Arc<T> {
118+
impl<T: Sync + Send> Clone for Arc<T> {
119119
/// Duplicate an atomically reference counted wrapper.
120120
///
121121
/// The resulting two `Arc` objects will point to the same underlying data
@@ -140,14 +140,14 @@ impl<T: Share + Send> Clone for Arc<T> {
140140
}
141141

142142
#[experimental = "Deref is experimental."]
143-
impl<T: Send + Share> Deref<T> for Arc<T> {
143+
impl<T: Send + Sync> Deref<T> for Arc<T> {
144144
#[inline]
145145
fn deref(&self) -> &T {
146146
&self.inner().data
147147
}
148148
}
149149

150-
impl<T: Send + Share + Clone> Arc<T> {
150+
impl<T: Send + Sync + Clone> Arc<T> {
151151
/// Acquires a mutable pointer to the inner contents by guaranteeing that
152152
/// the reference count is one (no sharing is possible).
153153
///
@@ -175,7 +175,7 @@ impl<T: Send + Share + Clone> Arc<T> {
175175

176176
#[unsafe_destructor]
177177
#[experimental = "waiting on stability of Drop"]
178-
impl<T: Share + Send> Drop for Arc<T> {
178+
impl<T: Sync + Send> Drop for Arc<T> {
179179
fn drop(&mut self) {
180180
// This structure has #[unsafe_no_drop_flag], so this drop glue may run
181181
// more than once (but it is guaranteed to be zeroed after the first if
@@ -219,7 +219,7 @@ impl<T: Share + Send> Drop for Arc<T> {
219219
}
220220

221221
#[experimental = "Weak pointers may not belong in this module."]
222-
impl<T: Share + Send> Weak<T> {
222+
impl<T: Sync + Send> Weak<T> {
223223
/// Attempts to upgrade this weak reference to a strong reference.
224224
///
225225
/// This method will fail to upgrade this reference if the strong reference
@@ -245,7 +245,7 @@ impl<T: Share + Send> Weak<T> {
245245
}
246246

247247
#[experimental = "Weak pointers may not belong in this module."]
248-
impl<T: Share + Send> Clone for Weak<T> {
248+
impl<T: Sync + Send> Clone for Weak<T> {
249249
#[inline]
250250
fn clone(&self) -> Weak<T> {
251251
// See comments in Arc::clone() for why this is relaxed
@@ -256,7 +256,7 @@ impl<T: Share + Send> Clone for Weak<T> {
256256

257257
#[unsafe_destructor]
258258
#[experimental = "Weak pointers may not belong in this module."]
259-
impl<T: Share + Send> Drop for Weak<T> {
259+
impl<T: Sync + Send> Drop for Weak<T> {
260260
fn drop(&mut self) {
261261
// see comments above for why this check is here
262262
if self._ptr.is_null() { return }

src/liballoc/rc.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub struct Rc<T> {
179179
// field accesses of the contained type via Deref
180180
_ptr: *mut RcBox<T>,
181181
_nosend: marker::NoSend,
182-
_noshare: marker::NoShare
182+
_noshare: marker::NoSync
183183
}
184184

185185
#[stable]
@@ -199,7 +199,7 @@ impl<T> Rc<T> {
199199
weak: Cell::new(1)
200200
}),
201201
_nosend: marker::NoSend,
202-
_noshare: marker::NoShare
202+
_noshare: marker::NoSync
203203
}
204204
}
205205
}
@@ -213,7 +213,7 @@ impl<T> Rc<T> {
213213
Weak {
214214
_ptr: self._ptr,
215215
_nosend: marker::NoSend,
216-
_noshare: marker::NoShare
216+
_noshare: marker::NoSync
217217
}
218218
}
219219
}
@@ -348,7 +348,7 @@ impl<T> Clone for Rc<T> {
348348
#[inline]
349349
fn clone(&self) -> Rc<T> {
350350
self.inc_strong();
351-
Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoShare }
351+
Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync }
352352
}
353353
}
354354

@@ -412,7 +412,7 @@ pub struct Weak<T> {
412412
// field accesses of the contained type via Deref
413413
_ptr: *mut RcBox<T>,
414414
_nosend: marker::NoSend,
415-
_noshare: marker::NoShare
415+
_noshare: marker::NoSync
416416
}
417417

418418
#[experimental = "Weak pointers may not belong in this module."]
@@ -423,7 +423,7 @@ impl<T> Weak<T> {
423423
None
424424
} else {
425425
self.inc_strong();
426-
Some(Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoShare })
426+
Some(Rc { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync })
427427
}
428428
}
429429
}
@@ -451,7 +451,7 @@ impl<T> Clone for Weak<T> {
451451
#[inline]
452452
fn clone(&self) -> Weak<T> {
453453
self.inc_weak();
454-
Weak { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoShare }
454+
Weak { _ptr: self._ptr, _nosend: marker::NoSend, _noshare: marker::NoSync }
455455
}
456456
}
457457

src/libcore/cell.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ use option::{None, Option, Some};
165165
#[unstable = "likely to be renamed; otherwise stable"]
166166
pub struct Cell<T> {
167167
value: UnsafeCell<T>,
168-
noshare: marker::NoShare,
168+
noshare: marker::NoSync,
169169
}
170170

171171
#[stable]
@@ -174,7 +174,7 @@ impl<T:Copy> Cell<T> {
174174
pub fn new(value: T) -> Cell<T> {
175175
Cell {
176176
value: UnsafeCell::new(value),
177-
noshare: marker::NoShare,
177+
noshare: marker::NoSync,
178178
}
179179
}
180180

@@ -213,7 +213,7 @@ pub struct RefCell<T> {
213213
value: UnsafeCell<T>,
214214
borrow: Cell<BorrowFlag>,
215215
nocopy: marker::NoCopy,
216-
noshare: marker::NoShare,
216+
noshare: marker::NoSync,
217217
}
218218

219219
// Values [1, MAX-1] represent the number of `Ref` active
@@ -230,7 +230,7 @@ impl<T> RefCell<T> {
230230
value: UnsafeCell::new(value),
231231
borrow: Cell::new(UNUSED),
232232
nocopy: marker::NoCopy,
233-
noshare: marker::NoShare,
233+
noshare: marker::NoSync,
234234
}
235235
}
236236

@@ -430,7 +430,7 @@ impl<'b, T> DerefMut<T> for RefMut<'b, T> {
430430
///
431431
/// struct NotThreadSafe<T> {
432432
/// value: UnsafeCell<T>,
433-
/// marker: marker::NoShare
433+
/// marker: marker::NoSync
434434
/// }
435435
/// ```
436436
///

0 commit comments

Comments
 (0)