Skip to content

Commit a93fbf9

Browse files
committed
librustc: Disallow "mut" from distributing over bindings.
This is the backwards-incompatible part of per-binding-site "mut".
1 parent c096f7d commit a93fbf9

33 files changed

+190
-50
lines changed

doc/rust.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,13 +2859,13 @@ call to the method `make_string`.
28592859
Types in Rust are categorized into kinds, based on various properties of the components of the type.
28602860
The kinds are:
28612861

2862-
`Const`
2862+
`Freeze`
28632863
: Types of this kind are deeply immutable;
28642864
they contain no mutable memory locations directly or indirectly via pointers.
2865-
`Owned`
2865+
`Send`
28662866
: Types of this kind can be safely sent between tasks.
28672867
This kind includes scalars, owning pointers, owned closures, and
2868-
structural types containing only other owned types. All `Owned` types are `Static`.
2868+
structural types containing only other owned types. All `Send` types are `Static`.
28692869
`Static`
28702870
: Types of this kind do not contain any borrowed pointers;
28712871
this can be a useful guarantee for code that breaks borrowing assumptions using [`unsafe` operations](#unsafe-functions).
@@ -2879,7 +2879,7 @@ The kinds are:
28792879
trait provides a single method `finalize` that takes no parameters, and is run
28802880
when values of the type are dropped. Such a method is called a "destructor",
28812881
and are always executed in "top-down" order: a value is completely destroyed
2882-
before any of the values it owns run their destructors. Only `Owned` types
2882+
before any of the values it owns run their destructors. Only `Send` types
28832883
that do not implement `Copy` can implement `Drop`.
28842884

28852885
> **Note:** The `finalize` method may be renamed in future versions of Rust.
@@ -2965,10 +2965,10 @@ frame they are allocated within.
29652965
A task owns all memory it can *safely* reach through local variables,
29662966
as well as managed, owning and borrowed pointers.
29672967

2968-
When a task sends a value that has the `Owned` trait to another task,
2968+
When a task sends a value that has the `Send` trait to another task,
29692969
it loses ownership of the value sent and can no longer refer to it.
29702970
This is statically guaranteed by the combined use of "move semantics",
2971-
and the compiler-checked _meaning_ of the `Owned` trait:
2971+
and the compiler-checked _meaning_ of the `Send` trait:
29722972
it is only instantiated for (transitively) sendable kinds of data constructor and pointers,
29732973
never including managed or borrowed pointers.
29742974

@@ -3113,7 +3113,7 @@ These include:
31133113
- read-only and read-write shared variables with various safe mutual exclusion patterns
31143114
- simple locks and semaphores
31153115

3116-
When such facilities carry values, the values are restricted to the [`Owned` type-kind](#type-kinds).
3116+
When such facilities carry values, the values are restricted to the [`Send` type-kind](#type-kinds).
31173117
Restricting communication interfaces to this kind ensures that no borrowed or managed pointers move between tasks.
31183118
Thus access to an entire data structure can be mediated through its owning "root" value;
31193119
no further locking or copying is required to avoid data races within the substructure of such a value.

doc/tutorial-ffi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub struct Unique<T> {
159159
priv ptr: *mut T
160160
}
161161
162-
impl<T: Owned> Unique<T> {
162+
impl<T: Send> Unique<T> {
163163
pub fn new(value: T) -> Unique<T> {
164164
unsafe {
165165
let ptr = malloc(std::sys::size_of::<T>() as size_t) as *mut T;
@@ -182,7 +182,7 @@ impl<T: Owned> Unique<T> {
182182
}
183183
184184
#[unsafe_destructor]
185-
impl<T: Owned> Drop for Unique<T> {
185+
impl<T: Send> Drop for Unique<T> {
186186
fn finalize(&self) {
187187
unsafe {
188188
let x = intrinsics::init(); // dummy value to swap in

src/libextra/md4.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ pub fn md4(msg: &[u8]) -> Quad {
6060
while i < e {
6161
let (aa, bb, cc, dd) = (a, b, c, d);
6262

63-
let mut (j, base) = (0u, i);
63+
let mut j = 0u;
64+
let mut base = i;
6465
while j < 16u {
6566
x[j] = (msg[base] as u32) + (msg[base + 1u] as u32 << 8u32) +
6667
(msg[base + 2u] as u32 << 16u32) +

src/libextra/net_url.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,9 @@ fn get_authority(rawurl: &str) ->
416416
let mut port = None;
417417

418418
let mut colon_count = 0;
419-
let mut (pos, begin, end) = (0, 2, len);
419+
let mut pos = 0;
420+
let mut begin = 2;
421+
let mut end = len;
420422

421423
for rawurl.iter().enumerate().advance |(i,c)| {
422424
if i < 2 { loop; } // ignore the leading //

src/libextra/num/bigint.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ impl Integer for BigUint {
382382
let mut d = Zero::zero::<BigUint>();
383383
let mut n = 1;
384384
while m >= b {
385-
let mut (d0, d_unit, b_unit) = div_estimate(&m, &b, n);
385+
let (d0, d_unit, b_unit) = div_estimate(&m, &b, n);
386+
let mut d0 = d0;
387+
let mut d_unit = d_unit;
388+
let mut b_unit = b_unit;
386389
let mut prod = b * d0;
387390
while prod > m {
388391
// FIXME(#6050): overloaded operators force moves with generic types
@@ -444,7 +447,8 @@ impl Integer for BigUint {
444447

445448
fn gcd(&self, other: &BigUint) -> BigUint {
446449
// Use Euclid's algorithm
447-
let mut (m, n) = (copy *self, copy *other);
450+
let mut m = copy *self;
451+
let mut n = copy *other;
448452
while !m.is_zero() {
449453
let temp = m;
450454
m = n % temp;

src/libextra/timer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ pub fn recv_timeout<T:Copy + Send>(iotask: &IoTask,
123123
msecs: uint,
124124
wait_po: &Port<T>)
125125
-> Option<T> {
126-
let mut (timeout_po, timeout_ch) = stream::<()>();
126+
let (timeout_po, timeout_ch) = stream::<()>();
127+
let mut timeout_po = timeout_po;
128+
let mut timeout_ch = timeout_ch;
127129
delayed_send(iotask, msecs, &timeout_ch, ());
128130

129131
// XXX: Workaround due to ports and channels not being &mut. They should

src/librustc/middle/trans/cabi_arm.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,14 @@ impl ABIInfo for ARM_ABIInfo {
145145
attrs.push(attr);
146146
}
147147

148-
let mut (ret_ty, ret_attr) = if ret_def {
148+
let (ret_ty, ret_attr) = if ret_def {
149149
classify_ret_ty(rty)
150150
} else {
151151
(LLVMType { cast: false, ty: T_void() }, None)
152152
};
153153

154+
let mut ret_ty = ret_ty;
155+
154156
let sret = ret_attr.is_some();
155157
if sret {
156158
arg_tys.unshift(ret_ty);

src/librustc/middle/trans/cabi_mips.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,14 @@ impl ABIInfo for MIPS_ABIInfo {
195195
atys: &[TypeRef],
196196
rty: TypeRef,
197197
ret_def: bool) -> FnType {
198-
let mut (ret_ty, ret_attr) = if ret_def {
198+
let (ret_ty, ret_attr) = if ret_def {
199199
classify_ret_ty(rty)
200200
} else {
201201
(LLVMType { cast: false, ty: T_void() }, None)
202202
};
203203

204+
let mut ret_ty = ret_ty;
205+
204206
let sret = ret_attr.is_some();
205207
let mut arg_tys = ~[];
206208
let mut attrs = ~[];

src/librustc/middle/trans/cabi_x86_64.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,10 @@ fn x86_64_tys(atys: &[TypeRef],
373373
arg_tys.push(ty);
374374
attrs.push(attr);
375375
}
376-
let mut (ret_ty, ret_attr) = x86_64_ty(rty, is_ret_bysret,
376+
let (ret_ty, ret_attr) = x86_64_ty(rty,
377+
is_ret_bysret,
377378
StructRetAttribute);
379+
let mut ret_ty = ret_ty;
378380
let sret = ret_attr.is_some();
379381
if sret {
380382
arg_tys = vec::append(~[ret_ty], arg_tys);

src/librustc/middle/trans/callee.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,10 @@ pub fn trans_fn_ref_with_vtables(
277277
// Should be either intra-crate or inlined.
278278
assert_eq!(def_id.crate, ast::local_crate);
279279

280-
let mut (val, must_cast) =
280+
let (val, must_cast) =
281281
monomorphize::monomorphic_fn(ccx, def_id, type_params,
282282
vtables, opt_impl_did, Some(ref_id));
283+
let mut val = val;
283284
if must_cast && ref_id != 0 {
284285
// Monotype of the REFERENCE to the function (type params
285286
// are subst'd)

src/librustc/middle/trans/expr.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,12 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
905905
let scaled_ix = Mul(bcx, ix_val, vt.llunit_size);
906906
base::maybe_name_value(bcx.ccx(), scaled_ix, "scaled_ix");
907907

908-
let mut (bcx, base, len) =
908+
let (bcx, base, len) =
909909
base_datum.get_vec_base_and_len(bcx, index_expr.span,
910910
index_expr.id, 0);
911+
let mut bcx = bcx;
912+
let mut base = base;
913+
let mut len = len;
911914

912915
if ty::type_is_str(base_ty) {
913916
// acccount for null terminator in the case of string

src/libstd/io.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,9 @@ impl<T:Reader> ReaderUtil for T {
771771
fn read_le_uint_n(&self, nbytes: uint) -> u64 {
772772
assert!(nbytes > 0 && nbytes <= 8);
773773

774-
let mut (val, pos, i) = (0u64, 0, nbytes);
774+
let mut val = 0u64;
775+
let mut pos = 0;
776+
let mut i = nbytes;
775777
while i > 0 {
776778
val += (self.read_u8() as u64) << pos;
777779
pos += 8;
@@ -787,7 +789,8 @@ impl<T:Reader> ReaderUtil for T {
787789
fn read_be_uint_n(&self, nbytes: uint) -> u64 {
788790
assert!(nbytes > 0 && nbytes <= 8);
789791

790-
let mut (val, i) = (0u64, nbytes);
792+
let mut val = 0u64;
793+
let mut i = nbytes;
791794
while i > 0 {
792795
i -= 1;
793796
val += (self.read_u8() as u64) << i * 8;

src/libstd/num/int_macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ impl Integer for $T {
400400
#[inline(always)]
401401
fn gcd(&self, other: &$T) -> $T {
402402
// Use Euclid's algorithm
403-
let mut (m, n) = (*self, *other);
403+
let mut m = *self;
404+
let mut n = *other;
404405
while m != 0 {
405406
let temp = m;
406407
m = n % temp;

src/libstd/num/uint_macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ impl Integer for $T {
237237
#[inline(always)]
238238
fn gcd(&self, other: &$T) -> $T {
239239
// Use Euclid's algorithm
240-
let mut (m, n) = (*self, *other);
240+
let mut m = *self;
241+
let mut n = *other;
241242
while m != 0 {
242243
let temp = m;
243244
m = n % temp;

src/libstd/rand.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@ impl IsaacRng {
720720
fn isaac(&mut self) {
721721
self.c += 1;
722722
// abbreviations
723-
let mut (a, b) = (self.a, self.b + self.c);
723+
let mut a = self.a;
724+
let mut b = self.b + self.c;
724725

725726
static midpoint: uint = RAND_SIZE as uint / 2;
726727

src/libstd/rand/distributions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ impl Rand for StandardNormal {
8989
// do-while, so the condition should be true on the first
9090
// run, they get overwritten anyway (0 < 1, so these are
9191
// good).
92-
let mut (x, y) = (1.0, 0.0);
92+
let mut x = 1.0;
93+
let mut y = 0.0;
9394

9495
// XXX infinities?
9596
while -2.0*y < x * x {

src/libstd/rt/io/extensions.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ impl<T: Reader> ReaderByteConversions for T {
342342
fn read_le_uint_n(&mut self, nbytes: uint) -> u64 {
343343
assert!(nbytes > 0 && nbytes <= 8);
344344

345-
let mut (val, pos, i) = (0u64, 0, nbytes);
345+
let mut val = 0u64;
346+
let mut pos = 0;
347+
let mut i = nbytes;
346348
while i > 0 {
347349
val += (self.read_u8() as u64) << pos;
348350
pos += 8;
@@ -358,7 +360,8 @@ impl<T: Reader> ReaderByteConversions for T {
358360
fn read_be_uint_n(&mut self, nbytes: uint) -> u64 {
359361
assert!(nbytes > 0 && nbytes <= 8);
360362

361-
let mut (val, i) = (0u64, nbytes);
363+
let mut val = 0u64;
364+
let mut i = nbytes;
362365
while i > 0 {
363366
i -= 1;
364367
val += (self.read_u8() as u64) << i * 8;

src/libstd/rt/uv/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
242242
// XXX: Could go in str::raw
243243
unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
244244
let s = s as *u8;
245-
let mut (curr, len) = (s, 0u);
245+
let mut curr = s;
246+
let mut len = 0u;
246247
while *curr != 0u8 {
247248
len += 1u;
248249
curr = ptr::offset(s, len);

0 commit comments

Comments
 (0)