Skip to content

Commit 67c22cf

Browse files
committed
---
yaml --- r: 195576 b: refs/heads/master c: 232e79f h: refs/heads/master v: v3
1 parent 8a4aff2 commit 67c22cf

File tree

87 files changed

+3010
-1654
lines changed

Some content is hidden

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

87 files changed

+3010
-1654
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: eac94fa097934e9329c65a3471949b228b098d1d
2+
refs/heads/master: 232e79fb91f4738194cc4d0757ce17895f992fe7
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b3317d68910900f135f9f38e43a7a699bc736b4a
55
refs/heads/try: 961e0358e1a5c0faaef606e31e9965742c1643bf

trunk/src/liballoc/arc.rs

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,38 @@ pub fn weak_count<T>(this: &Arc<T>) -> usize { this.inner().weak.load(SeqCst) -
242242
#[unstable(feature = "alloc")]
243243
pub fn strong_count<T>(this: &Arc<T>) -> usize { this.inner().strong.load(SeqCst) }
244244

245+
246+
/// Try accessing a mutable reference to the contents behind an unique `Arc<T>`.
247+
///
248+
/// The access is granted only if this is the only reference to the object.
249+
/// Otherwise, `None` is returned.
250+
///
251+
/// # Examples
252+
///
253+
/// ```
254+
/// # #![feature(alloc)]
255+
/// use std::alloc::arc;
256+
///
257+
/// let mut four = arc::Arc::new(4);
258+
///
259+
/// arc::unique(&mut four).map(|num| *num = 5);
260+
/// ```
261+
#[inline]
262+
#[unstable(feature = "alloc")]
263+
pub fn unique<T>(this: &mut Arc<T>) -> Option<&mut T> {
264+
if strong_count(this) == 1 && weak_count(this) == 0 {
265+
// This unsafety is ok because we're guaranteed that the pointer
266+
// returned is the *only* pointer that will ever be returned to T. Our
267+
// reference count is guaranteed to be 1 at this point, and we required
268+
// the Arc itself to be `mut`, so we're returning the only possible
269+
// reference to the inner data.
270+
let inner = unsafe { &mut **this._ptr };
271+
Some(&mut inner.data)
272+
}else {
273+
None
274+
}
275+
}
276+
245277
#[stable(feature = "rust1", since = "1.0.0")]
246278
impl<T> Clone for Arc<T> {
247279
/// Makes a clone of the `Arc<T>`.
@@ -312,11 +344,8 @@ impl<T: Send + Sync + Clone> Arc<T> {
312344
self.inner().weak.load(SeqCst) != 1 {
313345
*self = Arc::new((**self).clone())
314346
}
315-
// This unsafety is ok because we're guaranteed that the pointer
316-
// returned is the *only* pointer that will ever be returned to T. Our
317-
// reference count is guaranteed to be 1 at this point, and we required
318-
// the Arc itself to be `mut`, so we're returning the only possible
319-
// reference to the inner data.
347+
// As with `unique()`, the unsafety is ok because our reference was
348+
// either unique to begin with, or became one upon cloning the contents.
320349
let inner = unsafe { &mut **self._ptr };
321350
&mut inner.data
322351
}
@@ -659,7 +688,7 @@ mod tests {
659688
use std::sync::atomic::Ordering::{Acquire, SeqCst};
660689
use std::thread;
661690
use std::vec::Vec;
662-
use super::{Arc, Weak, weak_count, strong_count};
691+
use super::{Arc, Weak, weak_count, strong_count, unique};
663692
use std::sync::Mutex;
664693

665694
struct Canary(*mut atomic::AtomicUsize);
@@ -695,6 +724,21 @@ mod tests {
695724
assert_eq!((*arc_v)[4], 5);
696725
}
697726

727+
#[test]
728+
fn test_arc_unique() {
729+
let mut x = Arc::new(10);
730+
assert!(unique(&mut x).is_some());
731+
{
732+
let y = x.clone();
733+
assert!(unique(&mut x).is_none());
734+
}
735+
{
736+
let z = x.downgrade();
737+
assert!(unique(&mut x).is_none());
738+
}
739+
assert!(unique(&mut x).is_some());
740+
}
741+
698742
#[test]
699743
fn test_cowarc_clone_make_unique() {
700744
let mut cow0 = Arc::new(75);

trunk/src/liballoc/boxed.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub static HEAP: () = ();
8686
/// See the [module-level documentation](../../std/boxed/index.html) for more.
8787
#[lang = "owned_box"]
8888
#[stable(feature = "rust1", since = "1.0.0")]
89+
#[fundamental]
8990
pub struct Box<T>(Unique<T>);
9091

9192
impl<T> Box<T> {
@@ -277,13 +278,6 @@ impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
277278
}
278279
}
279280

280-
#[stable(feature = "rust1", since = "1.0.0")]
281-
impl fmt::Debug for Box<Any> {
282-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
283-
f.pad("Box<Any>")
284-
}
285-
}
286-
287281
#[stable(feature = "rust1", since = "1.0.0")]
288282
impl<T: ?Sized> Deref for Box<T> {
289283
type Target = T;

trunk/src/liballoc/boxed_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ fn test_show() {
5555
let b = Box::new(Test) as Box<Any>;
5656
let a_str = format!("{:?}", a);
5757
let b_str = format!("{:?}", b);
58-
assert_eq!(a_str, "Box<Any>");
59-
assert_eq!(b_str, "Box<Any>");
58+
assert_eq!(a_str, "Any");
59+
assert_eq!(b_str, "Any");
6060

6161
static EIGHT: usize = 8;
6262
static TEST: Test = Test;
6363
let a = &EIGHT as &Any;
6464
let b = &TEST as &Any;
6565
let s = format!("{:?}", a);
66-
assert_eq!(s, "&Any");
66+
assert_eq!(s, "Any");
6767
let s = format!("{:?}", b);
68-
assert_eq!(s, "&Any");
68+
assert_eq!(s, "Any");
6969
}
7070

7171
#[test]

trunk/src/liballoc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
#![feature(no_std)]
7272
#![no_std]
7373
#![feature(allocator)]
74+
#![feature(custom_attribute)]
75+
#![feature(fundamental)]
7476
#![feature(lang_items, unsafe_destructor)]
7577
#![feature(box_syntax)]
7678
#![feature(optin_builtin_traits)]

trunk/src/libcore/any.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
7272
#![stable(feature = "rust1", since = "1.0.0")]
7373

74+
use fmt;
7475
use marker::Send;
7576
use mem::transmute;
7677
use option::Option::{self, Some, None};
@@ -105,6 +106,13 @@ impl<T> Any for T
105106
// Extension methods for Any trait objects.
106107
///////////////////////////////////////////////////////////////////////////////
107108

109+
#[stable(feature = "rust1", since = "1.0.0")]
110+
impl fmt::Debug for Any {
111+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
112+
f.pad("Any")
113+
}
114+
}
115+
108116
impl Any {
109117
/// Returns true if the boxed type is the same as `T`
110118
#[stable(feature = "rust1", since = "1.0.0")]

trunk/src/libcore/fmt/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
#![stable(feature = "rust1", since = "1.0.0")]
1414

15-
use any;
1615
use cell::{Cell, RefCell, Ref, RefMut, BorrowState};
1716
use char::CharExt;
1817
use iter::Iterator;
@@ -997,11 +996,6 @@ macro_rules! tuple {
997996

998997
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
999998

1000-
#[stable(feature = "rust1", since = "1.0.0")]
1001-
impl<'a> Debug for &'a (any::Any+'a) {
1002-
fn fmt(&self, f: &mut Formatter) -> Result { f.pad("&Any") }
1003-
}
1004-
1005999
#[stable(feature = "rust1", since = "1.0.0")]
10061000
impl<T: Debug> Debug for [T] {
10071001
fn fmt(&self, f: &mut Formatter) -> Result {

trunk/src/libcore/iter.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@
4545
//! let mut it = values.into_iter();
4646
//! loop {
4747
//! match it.next() {
48-
//! Some(x) => {
49-
//! println!("{}", x);
50-
//! }
51-
//! None => { break }
48+
//! Some(x) => println!("{}", x),
49+
//! None => break,
5250
//! }
5351
//! }
5452
//! ```

trunk/src/libcore/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@
7070
#![feature(unboxed_closures)]
7171
#![feature(rustc_attrs)]
7272
#![feature(optin_builtin_traits)]
73+
#![feature(fundamental)]
7374
#![feature(concat_idents)]
7475
#![feature(reflect)]
76+
#![feature(custom_attribute)]
7577

7678
#[macro_use]
7779
mod macros;

trunk/src/libcore/marker.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl !Send for Managed { }
4949
#[stable(feature = "rust1", since = "1.0.0")]
5050
#[lang="sized"]
5151
#[rustc_on_unimplemented = "`{Self}` does not have a constant size known at compile-time"]
52+
#[fundamental] // for Default, for example, which requires that `[T]: !Default` be evaluatable
5253
pub trait Sized : MarkerTrait {
5354
// Empty.
5455
}
@@ -346,17 +347,16 @@ impl<T:?Sized> MarkerTrait for T { }
346347
#[stable(feature = "rust1", since = "1.0.0")]
347348
pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
348349

349-
/// `PhantomData` is a way to tell the compiler about fake fields.
350-
/// Phantom data is required whenever type parameters are not used.
351-
/// The idea is that if the compiler encounters a `PhantomData<T>`
352-
/// instance, it will behave *as if* an instance of the type `T` were
353-
/// present for the purpose of various automatic analyses.
350+
/// `PhantomData<T>` allows you to describe that a type acts as if it stores a value of type `T`,
351+
/// even though it does not. This allows you to inform the compiler about certain safety properties
352+
/// of your code.
353+
///
354+
/// Though they both have scary names, `PhantomData<T>` and "phantom types" are unrelated. 👻👻👻
354355
///
355356
/// # Examples
356357
///
357358
/// When handling external resources over a foreign function interface, `PhantomData<T>` can
358-
/// prevent mismatches by enforcing types in the method implementations, although the struct
359-
/// doesn't actually contain values of the resource type.
359+
/// prevent mismatches by enforcing types in the method implementations:
360360
///
361361
/// ```
362362
/// # trait ResType { fn foo(&self); };
@@ -397,11 +397,6 @@ pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
397397
/// commonly necessary if the structure is using an unsafe pointer
398398
/// like `*mut T` whose referent may be dropped when the type is
399399
/// dropped, as a `*mut T` is otherwise not treated as owned.
400-
///
401-
/// FIXME. Better documentation and examples of common patterns needed
402-
/// here! For now, please see [RFC 738][738] for more information.
403-
///
404-
/// [738]: https://github.com/rust-lang/rfcs/blob/master/text/0738-variance.md
405400
#[lang="phantom_data"]
406401
#[stable(feature = "rust1", since = "1.0.0")]
407402
pub struct PhantomData<T:?Sized>;

trunk/src/libcore/ops.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T {
11171117
#[lang="fn"]
11181118
#[stable(feature = "rust1", since = "1.0.0")]
11191119
#[rustc_paren_sugar]
1120+
#[fundamental] // so that regex can rely that `&str: !FnMut`
11201121
pub trait Fn<Args> : FnMut<Args> {
11211122
/// This is called when the call operator is used.
11221123
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
@@ -1126,6 +1127,7 @@ pub trait Fn<Args> : FnMut<Args> {
11261127
#[lang="fn_mut"]
11271128
#[stable(feature = "rust1", since = "1.0.0")]
11281129
#[rustc_paren_sugar]
1130+
#[fundamental] // so that regex can rely that `&str: !FnMut`
11291131
pub trait FnMut<Args> : FnOnce<Args> {
11301132
/// This is called when the call operator is used.
11311133
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
@@ -1135,10 +1137,60 @@ pub trait FnMut<Args> : FnOnce<Args> {
11351137
#[lang="fn_once"]
11361138
#[stable(feature = "rust1", since = "1.0.0")]
11371139
#[rustc_paren_sugar]
1140+
#[fundamental] // so that regex can rely that `&str: !FnMut`
11381141
pub trait FnOnce<Args> {
11391142
/// The returned type after the call operator is used.
11401143
type Output;
11411144

11421145
/// This is called when the call operator is used.
11431146
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
11441147
}
1148+
1149+
#[cfg(not(stage0))]
1150+
mod impls {
1151+
use marker::Sized;
1152+
use super::{Fn, FnMut, FnOnce};
1153+
1154+
impl<'a,A,F:?Sized> Fn<A> for &'a F
1155+
where F : Fn<A>
1156+
{
1157+
extern "rust-call" fn call(&self, args: A) -> F::Output {
1158+
(**self).call(args)
1159+
}
1160+
}
1161+
1162+
impl<'a,A,F:?Sized> FnMut<A> for &'a F
1163+
where F : Fn<A>
1164+
{
1165+
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
1166+
(**self).call(args)
1167+
}
1168+
}
1169+
1170+
impl<'a,A,F:?Sized> FnOnce<A> for &'a F
1171+
where F : Fn<A>
1172+
{
1173+
type Output = F::Output;
1174+
1175+
extern "rust-call" fn call_once(self, args: A) -> F::Output {
1176+
(*self).call(args)
1177+
}
1178+
}
1179+
1180+
impl<'a,A,F:?Sized> FnMut<A> for &'a mut F
1181+
where F : FnMut<A>
1182+
{
1183+
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
1184+
(*self).call_mut(args)
1185+
}
1186+
}
1187+
1188+
impl<'a,A,F:?Sized> FnOnce<A> for &'a mut F
1189+
where F : FnMut<A>
1190+
{
1191+
type Output = F::Output;
1192+
extern "rust-call" fn call_once(mut self, args: A) -> F::Output {
1193+
(*self).call_mut(args)
1194+
}
1195+
}
1196+
}

trunk/src/librustc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub mod middle {
120120
pub mod traits;
121121
pub mod ty;
122122
pub mod ty_fold;
123+
pub mod ty_match;
124+
pub mod ty_relate;
123125
pub mod ty_walk;
124126
pub mod weak_lang_items;
125127
}

trunk/src/librustc/metadata/encoder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ use std::io::prelude::*;
3434
use std::io::{Cursor, SeekFrom};
3535
use syntax::abi;
3636
use syntax::ast::{self, DefId, NodeId};
37-
use syntax::ast_map::{PathElem, PathElems};
38-
use syntax::ast_map;
37+
use syntax::ast_map::{self, LinkedPath, PathElem, PathElems};
3938
use syntax::ast_util::*;
4039
use syntax::ast_util;
4140
use syntax::attr;
@@ -1513,7 +1512,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
15131512
&krate.module,
15141513
&[],
15151514
ast::CRATE_NODE_ID,
1516-
[].iter().cloned().chain(None),
1515+
[].iter().cloned().chain(LinkedPath::empty()),
15171516
syntax::parse::token::special_idents::invalid,
15181517
ast::Public);
15191518

@@ -1874,7 +1873,7 @@ fn encode_misc_info(ecx: &EncodeContext,
18741873
}
18751874

18761875
// Encode reexports for the root module.
1877-
encode_reexports(ecx, rbml_w, 0, [].iter().cloned().chain(None));
1876+
encode_reexports(ecx, rbml_w, 0, [].iter().cloned().chain(LinkedPath::empty()));
18781877

18791878
rbml_w.end_tag();
18801879
rbml_w.end_tag();

trunk/src/librustc/middle/dataflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O
108108
pprust::NodeIdent(_) | pprust::NodeName(_) => 0,
109109
pprust::NodeExpr(expr) => expr.id,
110110
pprust::NodeBlock(blk) => blk.id,
111-
pprust::NodeItem(_) => 0,
111+
pprust::NodeItem(_) | pprust::NodeSubItem(_) => 0,
112112
pprust::NodePat(pat) => pat.id
113113
};
114114

0 commit comments

Comments
 (0)