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 #35639

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1403df7
Implement From for Cell, RefCell and UnsafeCell
malbarbo Aug 5, 2016
6ca9094
Add --test-threads option to test binaries
jupp0r Aug 6, 2016
9d6fa40
Add regression test for #22894.
frewsxcv Aug 8, 2016
6bc494b
Proc_macro is alive
cgswords Aug 4, 2016
16cc8a7
Implemented a smarter concatenation system that will hopefully produc…
cgswords Aug 2, 2016
045c8c8
std: Optimize panic::catch_unwind slightly
alexcrichton Jul 9, 2016
d77a136
add SetDiscriminant StatementKind to enable deaggregation of enums
scottcarr Aug 4, 2016
d099e30
Introduce `as_slice` method on `std::vec::IntoIter` struct.
frewsxcv Aug 7, 2016
01a766e
Introduce `as_mut_slice` method on `std::vec::IntoIter` struct.
frewsxcv Aug 7, 2016
f76a737
Correct span for pub_restricted field
sanxiyn Aug 8, 2016
ad247ce
Rollup merge of #35348 - scottcarr:discriminant2, r=nikomatsakis
Manishearth Aug 13, 2016
7e2fa43
Rollup merge of #35392 - malbarbo:cell-from, r=brson
Manishearth Aug 13, 2016
c105a05
Rollup merge of #35414 - jupp0r:feature/test-threads-flag, r=alexcric…
Manishearth Aug 13, 2016
78cbbd4
Rollup merge of #35444 - alexcrichton:optimize-catch-unwind, r=brson
Manishearth Aug 13, 2016
d1e286a
Rollup merge of #35447 - frewsxcv:vec-into-iter-as-slice, r=alexcrichton
Manishearth Aug 13, 2016
6e59f49
Rollup merge of #35491 - sanxiyn:pub-restricted-span, r=nikomatsakis
Manishearth Aug 13, 2016
b61adfb
Rollup merge of #35533 - frewsxcv:22984, r=brson
Manishearth Aug 13, 2016
3a86773
Rollup merge of #35538 - cgswords:libproc_macro, r=nrc
Manishearth Aug 13, 2016
cbed977
Rollup merge of #35539 - cgswords:ts_concat, r=nrc
Manishearth Aug 13, 2016
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
3 changes: 2 additions & 1 deletion man/rustc.1
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ which link to the standard library.
.TP
\fBRUST_TEST_THREADS\fR
The test framework Rust provides executes tests in parallel. This variable sets
the maximum number of threads used for this purpose.
the maximum number of threads used for this purpose. This setting is overridden
by the --test-threads option.

.TP
\fBRUST_TEST_NOCAPTURE\fR
Expand Down
8 changes: 5 additions & 3 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_
rustc_data_structures rustc_platform_intrinsics rustc_errors \
rustc_plugin rustc_metadata rustc_passes rustc_save_analysis \
rustc_const_eval rustc_const_math rustc_incremental
HOST_CRATES := syntax syntax_ext syntax_pos $(RUSTC_CRATES) rustdoc fmt_macros \
HOST_CRATES := syntax syntax_ext proc_macro syntax_pos $(RUSTC_CRATES) rustdoc fmt_macros \
flate arena graphviz rbml log serialize
TOOLS := compiletest rustdoc rustc rustbook error_index_generator

Expand Down Expand Up @@ -100,6 +100,7 @@ DEPS_test := std getopts term native:rust_test_helpers

DEPS_syntax := std term serialize log arena libc rustc_bitflags rustc_unicode rustc_errors syntax_pos
DEPS_syntax_ext := syntax syntax_pos rustc_errors fmt_macros
DEPS_proc_macro := syntax syntax_pos rustc_plugin log
DEPS_syntax_pos := serialize

DEPS_rustc_const_math := std syntax log serialize
Expand All @@ -114,8 +115,9 @@ DEPS_rustc_borrowck := rustc log graphviz syntax syntax_pos rustc_errors rustc_m
DEPS_rustc_data_structures := std log serialize
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
rustc_typeck rustc_mir rustc_resolve log syntax serialize rustc_llvm \
rustc_trans rustc_privacy rustc_lint rustc_plugin \
rustc_metadata syntax_ext rustc_passes rustc_save_analysis rustc_const_eval \
rustc_trans rustc_privacy rustc_lint rustc_plugin \
rustc_metadata syntax_ext proc_macro \
rustc_passes rustc_save_analysis rustc_const_eval \
rustc_incremental syntax_pos rustc_errors
DEPS_rustc_errors := log libc serialize syntax_pos
DEPS_rustc_lint := rustc log syntax syntax_pos rustc_const_eval
Expand Down
63 changes: 51 additions & 12 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,13 +1446,12 @@ impl<T> IntoIterator for Vec<T> {
#[inline]
fn into_iter(mut self) -> IntoIter<T> {
unsafe {
let ptr = self.as_mut_ptr();
assume(!ptr.is_null());
let begin = ptr as *const T;
let begin = self.as_mut_ptr();
assume(!begin.is_null());
let end = if mem::size_of::<T>() == 0 {
arith_offset(ptr as *const i8, self.len() as isize) as *const T
arith_offset(begin as *const i8, self.len() as isize) as *const T
} else {
ptr.offset(self.len() as isize) as *const T
begin.offset(self.len() as isize) as *const T
};
let buf = ptr::read(&self.buf);
mem::forget(self);
Expand Down Expand Up @@ -1710,10 +1709,52 @@ impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
_buf: RawVec<T>,
ptr: *const T,
ptr: *mut T,
end: *const T,
}

impl<T> IntoIter<T> {
/// Returns the remaining items of this iterator as a slice.
///
/// # Examples
///
/// ```rust
/// # #![feature(vec_into_iter_as_slice)]
/// let vec = vec!['a', 'b', 'c'];
/// let mut into_iter = vec.into_iter();
/// assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']);
/// let _ = into_iter.next().unwrap();
/// assert_eq!(into_iter.as_slice(), &['b', 'c']);
/// ```
#[unstable(feature = "vec_into_iter_as_slice", issue = "35601")]
pub fn as_slice(&self) -> &[T] {
unsafe {
slice::from_raw_parts(self.ptr, self.len())
}
}

/// Returns the remaining items of this iterator as a mutable slice.
///
/// # Examples
///
/// ```rust
/// # #![feature(vec_into_iter_as_slice)]
/// let vec = vec!['a', 'b', 'c'];
/// let mut into_iter = vec.into_iter();
/// assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']);
/// into_iter.as_mut_slice()[2] = 'z';
/// assert_eq!(into_iter.next().unwrap(), 'a');
/// assert_eq!(into_iter.next().unwrap(), 'b');
/// assert_eq!(into_iter.next().unwrap(), 'z');
/// ```
#[unstable(feature = "vec_into_iter_as_slice", issue = "35601")]
pub fn as_mut_slice(&self) -> &mut [T] {
unsafe {
slice::from_raw_parts_mut(self.ptr, self.len())
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
unsafe impl<T: Send> Send for IntoIter<T> {}
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -1726,14 +1767,14 @@ impl<T> Iterator for IntoIter<T> {
#[inline]
fn next(&mut self) -> Option<T> {
unsafe {
if self.ptr == self.end {
if self.ptr as *const _ == self.end {
None
} else {
if mem::size_of::<T>() == 0 {
// purposefully don't use 'ptr.offset' because for
// vectors with 0-size elements this would return the
// same pointer.
self.ptr = arith_offset(self.ptr as *const i8, 1) as *const T;
self.ptr = arith_offset(self.ptr as *const i8, 1) as *mut T;

// Use a non-null pointer value
Some(ptr::read(EMPTY as *mut T))
Expand Down Expand Up @@ -1776,7 +1817,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
} else {
if mem::size_of::<T>() == 0 {
// See above for why 'ptr.offset' isn't used
self.end = arith_offset(self.end as *const i8, -1) as *const T;
self.end = arith_offset(self.end as *const i8, -1) as *mut T;

// Use a non-null pointer value
Some(ptr::read(EMPTY as *mut T))
Expand All @@ -1796,9 +1837,7 @@ impl<T> ExactSizeIterator for IntoIter<T> {}
#[stable(feature = "vec_into_iter_clone", since = "1.8.0")]
impl<T: Clone> Clone for IntoIter<T> {
fn clone(&self) -> IntoIter<T> {
unsafe {
slice::from_raw_parts(self.ptr, self.len()).to_owned().into_iter()
}
self.as_slice().to_owned().into_iter()
}
}

Expand Down
1 change: 1 addition & 0 deletions src/libcollectionstest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#![feature(unboxed_closures)]
#![feature(unicode)]
#![feature(vec_deque_contains)]
#![feature(vec_into_iter_as_slice)]

extern crate collections;
extern crate test;
Expand Down
23 changes: 23 additions & 0 deletions src/libcollectionstest/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,29 @@ fn test_split_off() {
assert_eq!(vec2, [5, 6]);
}

#[test]
fn test_into_iter_as_slice() {
let vec = vec!['a', 'b', 'c'];
let mut into_iter = vec.into_iter();
assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']);
let _ = into_iter.next().unwrap();
assert_eq!(into_iter.as_slice(), &['b', 'c']);
let _ = into_iter.next().unwrap();
let _ = into_iter.next().unwrap();
assert_eq!(into_iter.as_slice(), &[]);
}

#[test]
fn test_into_iter_as_mut_slice() {
let vec = vec!['a', 'b', 'c'];
let mut into_iter = vec.into_iter();
assert_eq!(into_iter.as_slice(), &['a', 'b', 'c']);
into_iter.as_mut_slice()[0] = 'x';
into_iter.as_mut_slice()[1] = 'y';
assert_eq!(into_iter.next().unwrap(), 'x');
assert_eq!(into_iter.as_slice(), &['y', 'c']);
}

#[test]
fn test_into_iter_count() {
assert_eq!(vec![1, 2, 3].into_iter().count(), 3);
Expand Down
22 changes: 22 additions & 0 deletions src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@

use clone::Clone;
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
use convert::From;
use default::Default;
use fmt::{self, Debug, Display};
use marker::{Copy, PhantomData, Send, Sync, Sized, Unsize};
Expand Down Expand Up @@ -329,6 +330,13 @@ impl<T:Ord + Copy> Ord for Cell<T> {
}
}

#[stable(feature = "cell_from", since = "1.12.0")]
impl<T: Copy> From<T> for Cell<T> {
fn from(t: T) -> Cell<T> {
Cell::new(t)
}
}

/// A mutable memory location with dynamically checked borrow rules
///
/// See the [module-level documentation](index.html) for more.
Expand Down Expand Up @@ -742,6 +750,13 @@ impl<T: ?Sized + Ord> Ord for RefCell<T> {
}
}

#[stable(feature = "cell_from", since = "1.12.0")]
impl<T> From<T> for RefCell<T> {
fn from(t: T) -> RefCell<T> {
RefCell::new(t)
}
}

struct BorrowRef<'b> {
borrow: &'b Cell<BorrowFlag>,
}
Expand Down Expand Up @@ -1064,3 +1079,10 @@ impl<T: Default> Default for UnsafeCell<T> {
UnsafeCell::new(Default::default())
}
}

#[stable(feature = "cell_from", since = "1.12.0")]
impl<T> From<T> for UnsafeCell<T> {
fn from(t: T) -> UnsafeCell<T> {
UnsafeCell::new(t)
}
}
15 changes: 15 additions & 0 deletions src/libproc_macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
authors = ["The Rust Project Developers"]
name = "proc_macro"
version = "0.0.0"

[lib]
name = "proc_macro"
path = "lib.rs"
crate-type = ["dylib"]

[dependencies]
log = { path = "../liblog" }
rustc_plugin = { path = "../librustc_plugin" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
89 changes: 89 additions & 0 deletions src/libproc_macro/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crate syntax;
extern crate syntax_pos;

use syntax::ast::Ident;
use syntax::codemap::DUMMY_SP;
use syntax::parse::token::{self, Token, keywords, str_to_ident};
use syntax::tokenstream::{self, TokenTree, TokenStream};
use std::rc::Rc;

/// A wrapper around `TokenStream::concat` to avoid extra namespace specification and
/// provide TokenStream concatenation as a generic operator.
pub fn concat(ts1: TokenStream, ts2: TokenStream) -> TokenStream {
TokenStream::concat(ts1, ts2)
}

/// Checks if two identifiers have the same name, disregarding context. This allows us to
/// fake 'reserved' keywords.
// FIXME We really want `free-identifier-=?` (a la Dybvig 1993). von Tander 2007 is
// probably the easiest way to do that.
pub fn ident_eq(tident: &TokenTree, id: Ident) -> bool {
let tid = match *tident {
TokenTree::Token(_, Token::Ident(ref id)) => id,
_ => {
return false;
}
};

tid.name == id.name
}

// ____________________________________________________________________________________________
// Conversion operators

/// Convert a `&str` into a Token.
pub fn str_to_token_ident(s: &str) -> Token {
Token::Ident(str_to_ident(s))
}

/// Converts a keyword (from `syntax::parse::token::keywords`) into a Token that
/// corresponds to it.
pub fn keyword_to_token_ident(kw: keywords::Keyword) -> Token {
Token::Ident(str_to_ident(&kw.name().as_str()[..]))
}

// ____________________________________________________________________________________________
// Build Procedures

/// Generically takes a `ts` and delimiter and returns `ts` delimited by the specified
/// delimiter.
pub fn build_delimited(ts: TokenStream, delim: token::DelimToken) -> TokenStream {
let tts = ts.to_tts();
TokenStream::from_tts(vec![TokenTree::Delimited(DUMMY_SP,
Rc::new(tokenstream::Delimited {
delim: delim,
open_span: DUMMY_SP,
tts: tts,
close_span: DUMMY_SP,
}))])
}

/// Takes `ts` and returns `[ts]`.
pub fn build_bracket_delimited(ts: TokenStream) -> TokenStream {
build_delimited(ts, token::DelimToken::Bracket)
}

/// Takes `ts` and returns `{ts}`.
pub fn build_brace_delimited(ts: TokenStream) -> TokenStream {
build_delimited(ts, token::DelimToken::Brace)
}

/// Takes `ts` and returns `(ts)`.
pub fn build_paren_delimited(ts: TokenStream) -> TokenStream {
build_delimited(ts, token::DelimToken::Paren)
}

/// Constructs `()`.
pub fn build_empty_args() -> TokenStream {
build_paren_delimited(TokenStream::mk_empty())
}
Loading