Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #23946

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e05c2f8
trans: Add early-out when translating unreachable controlflow express…
michaelwoerister Mar 5, 2015
45c10db
Clarified and simplified algorithm for increasing size of buffer in
Mar 29, 2015
2982fe3
80 character line limit
Mar 29, 2015
8d3e559
Clearer wording
Mar 29, 2015
240734c
Only zero at most 64k at a time. We still use the doubling
Mar 30, 2015
0939837
Rename the cryptic cres and ures types.
nikomatsakis Mar 9, 2015
4b0edb9
Combine `try` and `commit_if_ok` and make some details of inference
nikomatsakis Mar 10, 2015
7c62640
Refactor unification interface by moving the methods off of inferctxt…
nikomatsakis Feb 15, 2015
c581840
Make union-find helper fns private, change to u32.
nikomatsakis Feb 16, 2015
a6d9930
Extract more `ty` and `infer` dependencies from the unification engine
nikomatsakis Mar 10, 2015
e78550b
Switch to FnvHashMap
nikomatsakis Mar 18, 2015
e301d7c
Remove unused import
nikomatsakis Mar 18, 2015
8403b82
Port over type inference to using the new type relation stuff
nikomatsakis Mar 22, 2015
cead47c
Add a "match" relation that can be used to make recursion check during
nikomatsakis Mar 20, 2015
cdb10b8
A very simple hack to force an autoderef if the callee has type `&mut
nikomatsakis Mar 31, 2015
27b7841
Add blanket impls for references to the `Fn` traits.
nikomatsakis Mar 20, 2015
11111bb
Add tests for blanket impls.
nikomatsakis Mar 31, 2015
a547962
Pretty print ids for assoc items
nrc Mar 24, 2015
bfc2f5d
Improvements to PhantomData<T>'s docs 👻
steveklabnik Apr 1, 2015
0dd0925
Tidying up and reformatting
nrc Mar 29, 2015
39aa668
Added Arc::try_unique
kvark Mar 29, 2015
8ded156
Add examples + documentation for std::path
steveklabnik Apr 1, 2015
4b6248a
Simplify `match` branches in iter.rs example
frewsxcv Apr 1, 2015
03d3ba7
Implement the changes to coherence such that we consider a type to be
nikomatsakis Mar 30, 2015
35c261a
Add `#[fundamental]` annotations into libcore so that `Sized` and the
nikomatsakis Mar 30, 2015
b0af587
Update tests for new coherence rules, and add a swatch of new tests
nikomatsakis Mar 30, 2015
30b2d9e
Fallout in libstd: remove impls now considered to conflict.
nikomatsakis Mar 30, 2015
15b58fe
Fallout in libsyntax/librustc: use newtype'd options for linked lists,
nikomatsakis Mar 30, 2015
02b38a2
Rollup merge of #23066 - michaelwoerister:unreachable-if, r=pnkfelix
Manishearth Apr 1, 2015
1d17e6e
Rollup merge of #23844 - kvark:try_unique, r=alexcrichton
Manishearth Apr 1, 2015
abd747c
Rollup merge of #23847 - bcoopers:read_clarification, r=sfackler
Manishearth Apr 1, 2015
9eb0bab
Rollup merge of #23867 - nikomatsakis:issue-23086-take-3, r=pnkfelix
Manishearth Apr 1, 2015
debac97
Rollup merge of #23895 - nikomatsakis:fn-trait-inheritance-add-impls,…
Manishearth Apr 1, 2015
6a3e844
Rollup merge of #23924 - nrc:unqual-assoc3, r=alexcrichton
Manishearth Apr 1, 2015
2159bbf
Rollup merge of #23925 - steveklabnik:gh22914, r=Gankro
Manishearth Apr 1, 2015
77112bb
Rollup merge of #23927 - frewsxcv:patch-7, r=Manishearth
Manishearth Apr 1, 2015
ec6c2c3
Rollup merge of #23932 - steveklabnik:doc_std_path, r=flaper87
Manishearth Apr 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 50 additions & 6 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,38 @@ pub fn weak_count<T>(this: &Arc<T>) -> usize { this.inner().weak.load(SeqCst) -
#[unstable(feature = "alloc")]
pub fn strong_count<T>(this: &Arc<T>) -> usize { this.inner().strong.load(SeqCst) }


/// Try accessing a mutable reference to the contents behind an unique `Arc<T>`.
///
/// The access is granted only if this is the only reference to the object.
/// Otherwise, `None` is returned.
///
/// # Examples
///
/// ```
/// # #![feature(alloc)]
/// use std::alloc::arc;
///
/// let mut four = arc::Arc::new(4);
///
/// arc::unique(&mut four).map(|num| *num = 5);
/// ```
#[inline]
#[unstable(feature = "alloc")]
pub fn unique<T>(this: &mut Arc<T>) -> Option<&mut T> {
if strong_count(this) == 1 && weak_count(this) == 0 {
// This unsafety is ok because we're guaranteed that the pointer
// returned is the *only* pointer that will ever be returned to T. Our
// reference count is guaranteed to be 1 at this point, and we required
// the Arc itself to be `mut`, so we're returning the only possible
// reference to the inner data.
let inner = unsafe { &mut **this._ptr };
Some(&mut inner.data)
}else {
None
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Clone for Arc<T> {
/// Makes a clone of the `Arc<T>`.
Expand Down Expand Up @@ -312,11 +344,8 @@ impl<T: Send + Sync + Clone> Arc<T> {
self.inner().weak.load(SeqCst) != 1 {
*self = Arc::new((**self).clone())
}
// This unsafety is ok because we're guaranteed that the pointer
// returned is the *only* pointer that will ever be returned to T. Our
// reference count is guaranteed to be 1 at this point, and we required
// the Arc itself to be `mut`, so we're returning the only possible
// reference to the inner data.
// As with `unique()`, the unsafety is ok because our reference was
// either unique to begin with, or became one upon cloning the contents.
let inner = unsafe { &mut **self._ptr };
&mut inner.data
}
Expand Down Expand Up @@ -659,7 +688,7 @@ mod tests {
use std::sync::atomic::Ordering::{Acquire, SeqCst};
use std::thread;
use std::vec::Vec;
use super::{Arc, Weak, weak_count, strong_count};
use super::{Arc, Weak, weak_count, strong_count, unique};
use std::sync::Mutex;

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

#[test]
fn test_arc_unique() {
let mut x = Arc::new(10);
assert!(unique(&mut x).is_some());
{
let y = x.clone();
assert!(unique(&mut x).is_none());
}
{
let z = x.downgrade();
assert!(unique(&mut x).is_none());
}
assert!(unique(&mut x).is_some());
}

#[test]
fn test_cowarc_clone_make_unique() {
let mut cow0 = Arc::new(75);
Expand Down
8 changes: 1 addition & 7 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub static HEAP: () = ();
/// See the [module-level documentation](../../std/boxed/index.html) for more.
#[lang = "owned_box"]
#[stable(feature = "rust1", since = "1.0.0")]
#[fundamental]
pub struct Box<T>(Unique<T>);

impl<T> Box<T> {
Expand Down Expand Up @@ -277,13 +278,6 @@ impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for Box<Any> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Box<Any>")
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Deref for Box<T> {
type Target = T;
Expand Down
8 changes: 4 additions & 4 deletions src/liballoc/boxed_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ fn test_show() {
let b = Box::new(Test) as Box<Any>;
let a_str = format!("{:?}", a);
let b_str = format!("{:?}", b);
assert_eq!(a_str, "Box<Any>");
assert_eq!(b_str, "Box<Any>");
assert_eq!(a_str, "Any");
assert_eq!(b_str, "Any");

static EIGHT: usize = 8;
static TEST: Test = Test;
let a = &EIGHT as &Any;
let b = &TEST as &Any;
let s = format!("{:?}", a);
assert_eq!(s, "&Any");
assert_eq!(s, "Any");
let s = format!("{:?}", b);
assert_eq!(s, "&Any");
assert_eq!(s, "Any");
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
#![feature(no_std)]
#![no_std]
#![feature(allocator)]
#![feature(custom_attribute)]
#![feature(fundamental)]
#![feature(lang_items, unsafe_destructor)]
#![feature(box_syntax)]
#![feature(optin_builtin_traits)]
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

#![stable(feature = "rust1", since = "1.0.0")]

use fmt;
use marker::Send;
use mem::transmute;
use option::Option::{self, Some, None};
Expand Down Expand Up @@ -105,6 +106,13 @@ impl<T> Any for T
// Extension methods for Any trait objects.
///////////////////////////////////////////////////////////////////////////////

#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Debug for Any {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.pad("Any")
}
}

impl Any {
/// Returns true if the boxed type is the same as `T`
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
6 changes: 0 additions & 6 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#![stable(feature = "rust1", since = "1.0.0")]

use any;
use cell::{Cell, RefCell, Ref, RefMut, BorrowState};
use char::CharExt;
use iter::Iterator;
Expand Down Expand Up @@ -997,11 +996,6 @@ macro_rules! tuple {

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

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

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Debug> Debug for [T] {
fn fmt(&self, f: &mut Formatter) -> Result {
Expand Down
6 changes: 2 additions & 4 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@
//! let mut it = values.into_iter();
//! loop {
//! match it.next() {
//! Some(x) => {
//! println!("{}", x);
//! }
//! None => { break }
//! Some(x) => println!("{}", x),
//! None => break,
//! }
//! }
//! ```
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@
#![feature(unboxed_closures)]
#![feature(rustc_attrs)]
#![feature(optin_builtin_traits)]
#![feature(fundamental)]
#![feature(concat_idents)]
#![feature(reflect)]
#![feature(custom_attribute)]

#[macro_use]
mod macros;
Expand Down
19 changes: 7 additions & 12 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl !Send for Managed { }
#[stable(feature = "rust1", since = "1.0.0")]
#[lang="sized"]
#[rustc_on_unimplemented = "`{Self}` does not have a constant size known at compile-time"]
#[fundamental] // for Default, for example, which requires that `[T]: !Default` be evaluatable
pub trait Sized : MarkerTrait {
// Empty.
}
Expand Down Expand Up @@ -346,17 +347,16 @@ impl<T:?Sized> MarkerTrait for T { }
#[stable(feature = "rust1", since = "1.0.0")]
pub trait PhantomFn<A:?Sized,R:?Sized=()> { }

/// `PhantomData` is a way to tell the compiler about fake fields.
/// Phantom data is required whenever type parameters are not used.
/// The idea is that if the compiler encounters a `PhantomData<T>`
/// instance, it will behave *as if* an instance of the type `T` were
/// present for the purpose of various automatic analyses.
/// `PhantomData<T>` allows you to describe that a type acts as if it stores a value of type `T`,
/// even though it does not. This allows you to inform the compiler about certain safety properties
/// of your code.
///
/// Though they both have scary names, `PhantomData<T>` and "phantom types" are unrelated. 👻👻👻
///
/// # Examples
///
/// When handling external resources over a foreign function interface, `PhantomData<T>` can
/// prevent mismatches by enforcing types in the method implementations, although the struct
/// doesn't actually contain values of the resource type.
/// prevent mismatches by enforcing types in the method implementations:
///
/// ```
/// # trait ResType { fn foo(&self); };
Expand Down Expand Up @@ -397,11 +397,6 @@ pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
/// commonly necessary if the structure is using an unsafe pointer
/// like `*mut T` whose referent may be dropped when the type is
/// dropped, as a `*mut T` is otherwise not treated as owned.
///
/// FIXME. Better documentation and examples of common patterns needed
/// here! For now, please see [RFC 738][738] for more information.
///
/// [738]: https://github.com/rust-lang/rfcs/blob/master/text/0738-variance.md
#[lang="phantom_data"]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct PhantomData<T:?Sized>;
Expand Down
52 changes: 52 additions & 0 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,7 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T {
#[lang="fn"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_paren_sugar]
#[fundamental] // so that regex can rely that `&str: !FnMut`
pub trait Fn<Args> : FnMut<Args> {
/// This is called when the call operator is used.
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
Expand All @@ -1126,6 +1127,7 @@ pub trait Fn<Args> : FnMut<Args> {
#[lang="fn_mut"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_paren_sugar]
#[fundamental] // so that regex can rely that `&str: !FnMut`
pub trait FnMut<Args> : FnOnce<Args> {
/// This is called when the call operator is used.
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
Expand All @@ -1135,10 +1137,60 @@ pub trait FnMut<Args> : FnOnce<Args> {
#[lang="fn_once"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_paren_sugar]
#[fundamental] // so that regex can rely that `&str: !FnMut`
pub trait FnOnce<Args> {
/// The returned type after the call operator is used.
type Output;

/// This is called when the call operator is used.
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}

#[cfg(not(stage0))]
mod impls {
use marker::Sized;
use super::{Fn, FnMut, FnOnce};

impl<'a,A,F:?Sized> Fn<A> for &'a F
where F : Fn<A>
{
extern "rust-call" fn call(&self, args: A) -> F::Output {
(**self).call(args)
}
}

impl<'a,A,F:?Sized> FnMut<A> for &'a F
where F : Fn<A>
{
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
(**self).call(args)
}
}

impl<'a,A,F:?Sized> FnOnce<A> for &'a F
where F : Fn<A>
{
type Output = F::Output;

extern "rust-call" fn call_once(self, args: A) -> F::Output {
(*self).call(args)
}
}

impl<'a,A,F:?Sized> FnMut<A> for &'a mut F
where F : FnMut<A>
{
extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
(*self).call_mut(args)
}
}

impl<'a,A,F:?Sized> FnOnce<A> for &'a mut F
where F : FnMut<A>
{
type Output = F::Output;
extern "rust-call" fn call_once(mut self, args: A) -> F::Output {
(*self).call_mut(args)
}
}
}
2 changes: 2 additions & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ pub mod middle {
pub mod traits;
pub mod ty;
pub mod ty_fold;
pub mod ty_match;
pub mod ty_relate;
pub mod ty_walk;
pub mod weak_lang_items;
}
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ use std::io::prelude::*;
use std::io::{Cursor, SeekFrom};
use syntax::abi;
use syntax::ast::{self, DefId, NodeId};
use syntax::ast_map::{PathElem, PathElems};
use syntax::ast_map;
use syntax::ast_map::{self, LinkedPath, PathElem, PathElems};
use syntax::ast_util::*;
use syntax::ast_util;
use syntax::attr;
Expand Down Expand Up @@ -1513,7 +1512,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
&krate.module,
&[],
ast::CRATE_NODE_ID,
[].iter().cloned().chain(None),
[].iter().cloned().chain(LinkedPath::empty()),
syntax::parse::token::special_idents::invalid,
ast::Public);

Expand Down Expand Up @@ -1874,7 +1873,7 @@ fn encode_misc_info(ecx: &EncodeContext,
}

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

rbml_w.end_tag();
rbml_w.end_tag();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O
pprust::NodeIdent(_) | pprust::NodeName(_) => 0,
pprust::NodeExpr(expr) => expr.id,
pprust::NodeBlock(blk) => blk.id,
pprust::NodeItem(_) => 0,
pprust::NodeItem(_) | pprust::NodeSubItem(_) => 0,
pprust::NodePat(pat) => pat.id
};

Expand Down
13 changes: 12 additions & 1 deletion src/librustc/middle/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub enum Def {
/// <T as Trait>::AssocX::AssocY::MethodOrAssocType
/// ^~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~
/// base_def depth = 2
#[derive(Copy, Debug)]
#[derive(Copy, Clone, Debug)]
pub struct PathResolution {
pub base_def: Def,
pub last_private: LastPrivate,
Expand All @@ -85,6 +85,17 @@ impl PathResolution {
pub fn def_id(&self) -> ast::DefId {
self.full_def().def_id()
}

pub fn new(base_def: Def,
last_private: LastPrivate,
depth: usize)
-> PathResolution {
PathResolution {
base_def: base_def,
last_private: last_private,
depth: depth,
}
}
}

// Definition mapping
Expand Down
Loading