Skip to content

Commit 533f198

Browse files
committed
---
yaml --- r: 105435 b: refs/heads/master c: af93684 h: refs/heads/master i: 105433: f01e82b 105431: d328d3f v: v3
1 parent 9405725 commit 533f198

File tree

10 files changed

+58
-49
lines changed

10 files changed

+58
-49
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 695114ea2c1ae147dcf1c3ac690a75ecf928b8b2
2+
refs/heads/master: af9368452d8578af219713b34f7e3be4bd085186
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b8601a3d8b91ad3b653d143307611f2f5c75617e
55
refs/heads/try: db814977d07bd798feb24f6b74c00800ef458a13

trunk/src/librustc/middle/borrowck/check_loans.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ impl<'a> CheckLoanCtxt<'a> {
522522
None => {
523523
return true;
524524
}
525+
Some(mc::AliasableStaticMut) => {
526+
return true;
527+
}
525528
Some(cause) => {
526529
this.bccx.report_aliasability_violation(
527530
expr.span,

trunk/src/librustc/middle/check_const.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
156156
}
157157
}
158158
}
159+
ExprVstore(_, ExprVstoreMutSlice) |
159160
ExprVstore(_, ExprVstoreSlice) |
160161
ExprVec(_, MutImmutable) |
161162
ExprAddrOf(MutImmutable, _) |

trunk/src/librustc/middle/check_static.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ impl<'a> Visitor<bool> for CheckStaticVisitor<'a> {
107107
ast::ExprVstore(_, ast::ExprVstoreSlice) => {
108108
visit::walk_expr(self, e, is_const);
109109
}
110+
ast::ExprVstore(_, ast::ExprVstoreMutSlice) => {
111+
self.tcx.sess.span_err(e.span,
112+
"static items are not allowed to have mutable slices");
113+
},
110114
ast::ExprUnary(ast::UnBox, _) => {
111115
self.tcx.sess.span_err(e.span,
112116
"static items are not allowed to have managed pointers");

trunk/src/librustc/middle/trans/consts.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111

1212
use back::abi;
13-
use lib::llvm::{llvm, ConstFCmp, ConstICmp, SetLinkage, PrivateLinkage, ValueRef, Bool, True};
13+
use lib::llvm::{llvm, ConstFCmp, ConstICmp, SetLinkage, PrivateLinkage, ValueRef, Bool, True,
14+
False};
1415
use lib::llvm::{IntEQ, IntNE, IntUGT, IntUGE, IntULT, IntULE, IntSGT, IntSGE, IntSLT, IntSLE,
1516
RealOEQ, RealOGT, RealOGE, RealOLT, RealOLE, RealONE};
1617

@@ -574,7 +575,8 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
574575
is_local);
575576
(v, inlineable)
576577
}
577-
ast::ExprVstore(sub, ast::ExprVstoreSlice) => {
578+
ast::ExprVstore(sub, store @ ast::ExprVstoreSlice) |
579+
ast::ExprVstore(sub, store @ ast::ExprVstoreMutSlice) => {
578580
match sub.node {
579581
ast::ExprLit(ref lit) => {
580582
match lit.node {
@@ -592,7 +594,8 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
592594
llvm::LLVMAddGlobal(cx.llmod, llty.to_ref(), name)
593595
});
594596
llvm::LLVMSetInitializer(gv, cv);
595-
llvm::LLVMSetGlobalConstant(gv, True);
597+
llvm::LLVMSetGlobalConstant(gv,
598+
if store == ast::ExprVstoreMutSlice { False } else { True });
596599
SetLinkage(gv, PrivateLinkage);
597600
let p = const_ptrcast(cx, gv, llunitty);
598601
(C_struct(cx, [p, C_uint(cx, es.len())], false), false)

trunk/src/libstd/str.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,9 +1376,8 @@ pub mod raw {
13761376

13771377
#[lang="strdup_uniq"]
13781378
#[cfg(not(test))]
1379-
#[allow(missing_doc)]
13801379
#[inline]
1381-
pub unsafe fn strdup_uniq(ptr: *u8, len: uint) -> ~str {
1380+
unsafe fn strdup_uniq(ptr: *u8, len: uint) -> ~str {
13821381
from_buf_len(ptr, len)
13831382
}
13841383

trunk/src/libstd/sync/atomics.rs

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ use std::kinds::marker;
2727
use option::{Option,Some,None};
2828
use ops::Drop;
2929

30-
/**
31-
* A simple atomic flag, that can be set and cleared. The most basic atomic type.
32-
*/
33-
pub struct AtomicFlag {
34-
priv v: int,
35-
priv nopod: marker::NoPod
36-
}
37-
3830
/**
3931
* An atomic boolean type.
4032
*/
@@ -92,36 +84,11 @@ pub enum Ordering {
9284
SeqCst
9385
}
9486

95-
pub static INIT_ATOMIC_FLAG : AtomicFlag = AtomicFlag { v: 0, nopod: marker::NoPod };
9687
pub static INIT_ATOMIC_BOOL : AtomicBool = AtomicBool { v: 0, nopod: marker::NoPod };
9788
pub static INIT_ATOMIC_INT : AtomicInt = AtomicInt { v: 0, nopod: marker::NoPod };
9889
pub static INIT_ATOMIC_UINT : AtomicUint = AtomicUint { v: 0, nopod: marker::NoPod };
9990
pub static INIT_ATOMIC_U64 : AtomicU64 = AtomicU64 { v: 0, nopod: marker::NoPod };
10091

101-
impl AtomicFlag {
102-
103-
pub fn new() -> AtomicFlag {
104-
AtomicFlag { v: 0, nopod: marker::NoPod}
105-
}
106-
107-
/**
108-
* Clears the atomic flag
109-
*/
110-
#[inline]
111-
pub fn clear(&mut self, order: Ordering) {
112-
unsafe {atomic_store(&mut self.v, 0, order)}
113-
}
114-
115-
/**
116-
* Sets the flag if it was previously unset, returns the previous value of the
117-
* flag.
118-
*/
119-
#[inline]
120-
pub fn test_and_set(&mut self, order: Ordering) -> bool {
121-
unsafe { atomic_compare_and_swap(&mut self.v, 0, 1, order) > 0 }
122-
}
123-
}
124-
12592
impl AtomicBool {
12693
pub fn new(v: bool) -> AtomicBool {
12794
AtomicBool { v: if v { 1 } else { 0 }, nopod: marker::NoPod }
@@ -539,13 +506,13 @@ mod test {
539506
use super::*;
540507

541508
#[test]
542-
fn flag() {
543-
let mut flg = AtomicFlag::new();
544-
assert!(!flg.test_and_set(SeqCst));
545-
assert!(flg.test_and_set(SeqCst));
509+
fn bool_() {
510+
let mut a = AtomicBool::new(false);
511+
assert_eq!(a.compare_and_swap(false, true, SeqCst), false);
512+
assert_eq!(a.compare_and_swap(false, true, SeqCst), true);
546513

547-
flg.clear(SeqCst);
548-
assert!(!flg.test_and_set(SeqCst));
514+
a.store(false, SeqCst);
515+
assert_eq!(a.compare_and_swap(false, true, SeqCst), false);
549516
}
550517

551518
#[test]
@@ -595,15 +562,13 @@ mod test {
595562
assert_eq!(a.load(SeqCst),false);
596563
}
597564

598-
static mut S_FLAG : AtomicFlag = INIT_ATOMIC_FLAG;
599565
static mut S_BOOL : AtomicBool = INIT_ATOMIC_BOOL;
600566
static mut S_INT : AtomicInt = INIT_ATOMIC_INT;
601567
static mut S_UINT : AtomicUint = INIT_ATOMIC_UINT;
602568

603569
#[test]
604570
fn static_init() {
605571
unsafe {
606-
assert!(!S_FLAG.test_and_set(SeqCst));
607572
assert!(!S_BOOL.load(SeqCst));
608573
assert!(S_INT.load(SeqCst) == 0);
609574
assert!(S_UINT.load(SeqCst) == 0);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Checks that immutable static items can't have mutable slices
12+
13+
static TEST: &'static mut [int] = &mut [];
14+
//~^ ERROR static items are not allowed to have mutable slices
15+
16+
pub fn main() { }

trunk/src/test/compile-fail/std-uncopyable-atomics.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ use std::sync::atomics::*;
1616
use std::ptr;
1717

1818
fn main() {
19-
let x = INIT_ATOMIC_FLAG; //~ ERROR cannot move out of static item
20-
let x = *&x; //~ ERROR: cannot move out of dereference
2119
let x = INIT_ATOMIC_BOOL; //~ ERROR cannot move out of static item
2220
let x = *&x; //~ ERROR: cannot move out of dereference
2321
let x = INIT_ATOMIC_INT; //~ ERROR cannot move out of static item
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Checks that mutable static items can have mutable slices
12+
13+
static mut TEST: &'static mut [int] = &mut [1];
14+
15+
pub fn main() {
16+
unsafe {
17+
TEST[0] += 1;
18+
assert_eq!(TEST[0], 2);
19+
}
20+
}

0 commit comments

Comments
 (0)