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 8 pull requests #40647

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
460bf55
Cleanup.
jseyfried Mar 6, 2017
68c1cc6
Refactor `Attribute` to use `Path` and `TokenStream` instead of `Meta…
jseyfried Mar 3, 2017
839c286
Liberalize attributes.
jseyfried Mar 8, 2017
85e02bd
Add tests.
jseyfried Mar 8, 2017
ff63866
Change how the `0` flag works in format!
Sawyer47 Mar 3, 2017
8065486
Change how the 0 flag works in format! for floats
Sawyer47 Mar 4, 2017
2561dcd
Rename TryFrom's associated type and implement str::parse using TryFrom.
jimmycuadra Mar 5, 2017
50cede0
documented order of conversion between u32 an ipv4addr
Mar 17, 2017
963d4df
minor wording tweak to slice::{as_ptr, as_mut_ptr}
QuietMisdreavus Mar 17, 2017
ec8ecf4
Fix typo in mutex.rs docs
ScottAbbey Mar 17, 2017
2976ddb
Fix a spelling error in HashMap documentation, and slightly reword it…
jswalden Mar 18, 2017
0af3775
translate tuple-variant constructors using MIR
arielb1 Feb 7, 2017
ffee956
move Instance to rustc and use it in the collector
arielb1 Feb 8, 2017
bf80fec
translate function shims using MIR
arielb1 Mar 6, 2017
aac5ba5
resolve instances to ty::Instance directly
arielb1 Mar 7, 2017
65a4266
refactor away callee::Callee and translate virtual calls through a MI…
arielb1 Mar 8, 2017
a5e3c3d
collector: collect functions when they are called/reified
arielb1 Mar 8, 2017
e1f3c67
translate closure shims using MIR
arielb1 Mar 8, 2017
2b9fea1
move the drop expansion code to rustc_mir
arielb1 Mar 9, 2017
26df816
apply pre-trans passes to Shim MIR
arielb1 Mar 9, 2017
f2c7917
translate drop glue using MIR
arielb1 Mar 13, 2017
2661433
Rollup merge of #39628 - arielb1:shimmir, r=eddyb
frewsxcv Mar 19, 2017
52ae596
Rollup merge of #40241 - Sawyer47:fix-39997, r=alexcrichton
frewsxcv Mar 19, 2017
c83f2d8
Rollup merge of #40281 - jimmycuadra:try-from-from-str, r=aturon
frewsxcv Mar 19, 2017
bbb2863
Rollup merge of #40346 - jseyfried:path_and_tokenstream_attr, r=nrc
frewsxcv Mar 19, 2017
4bab562
Rollup merge of #40590 - z1mvader:master, r=steveklabnik
frewsxcv Mar 19, 2017
e6af875
Rollup merge of #40603 - QuietMisdreavus:slice-ptr-docs, r=GuillaumeG…
frewsxcv Mar 19, 2017
38fce52
Rollup merge of #40611 - ScottAbbey:patch-1, r=GuillaumeGomez
frewsxcv Mar 19, 2017
6c95ac0
Rollup merge of #40621 - jswalden:dependant-spelling-fix, r=sfackler
frewsxcv Mar 19, 2017
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
4 changes: 4 additions & 0 deletions src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@
//! like `{:08}` would yield `00000001` for the integer `1`, while the
//! same format would yield `-0000001` for the integer `-1`. Notice that
//! the negative version has one fewer zero than the positive version.
//! Note that padding zeroes are always placed after the sign (if any)
//! and before the digits. When used together with the `#` flag, a similar
//! rule applies: padding zeroes are inserted after the prefix but before
//! the digits.
//!
//! ## Width
//!
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ impl<T> [T] {
/// The caller must ensure that the slice outlives the pointer this
/// function returns, or else it will end up pointing to garbage.
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
/// Modifying the container referenced by this slice may cause its buffer
/// to be reallocated, which would also make any pointers to it invalid.
///
/// # Examples
///
Expand All @@ -463,8 +463,8 @@ impl<T> [T] {
/// The caller must ensure that the slice outlives the pointer this
/// function returns, or else it will end up pointing to garbage.
///
/// Modifying the slice may cause its buffer to be reallocated, which
/// would also make any pointers to it invalid.
/// Modifying the container referenced by this slice may cause its buffer
/// to be reallocated, which would also make any pointers to it invalid.
///
/// # Examples
///
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ impl From<u8> for char {

#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<u32> for char {
type Err = CharTryFromError;
type Error = CharTryFromError;

#[inline]
fn try_from(i: u32) -> Result<Self, Self::Err> {
fn try_from(i: u32) -> Result<Self, Self::Error> {
if (i > MAX as u32) || (i >= 0xD800 && i <= 0xDFFF) {
Err(CharTryFromError(()))
} else {
Expand Down
24 changes: 18 additions & 6 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

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

use str::FromStr;

/// A cheap, reference-to-reference conversion.
///
/// `AsRef` is very similar to, but different than, [`Borrow`]. See
Expand Down Expand Up @@ -212,20 +214,20 @@ pub trait From<T>: Sized {
#[unstable(feature = "try_from", issue = "33417")]
pub trait TryInto<T>: Sized {
/// The type returned in the event of a conversion error.
type Err;
type Error;

/// Performs the conversion.
fn try_into(self) -> Result<T, Self::Err>;
fn try_into(self) -> Result<T, Self::Error>;
}

/// Attempt to construct `Self` via a conversion.
#[unstable(feature = "try_from", issue = "33417")]
pub trait TryFrom<T>: Sized {
/// The type returned in the event of a conversion error.
type Err;
type Error;

/// Performs the conversion.
fn try_from(value: T) -> Result<Self, Self::Err>;
fn try_from(value: T) -> Result<Self, Self::Error>;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -290,9 +292,9 @@ impl<T> From<T> for T {
// TryFrom implies TryInto
#[unstable(feature = "try_from", issue = "33417")]
impl<T, U> TryInto<U> for T where U: TryFrom<T> {
type Err = U::Err;
type Error = U::Error;

fn try_into(self) -> Result<U, U::Err> {
fn try_into(self) -> Result<U, U::Error> {
U::try_from(self)
}
}
Expand Down Expand Up @@ -322,3 +324,13 @@ impl AsRef<str> for str {
self
}
}

// FromStr implies TryFrom<&str>
#[unstable(feature = "try_from", issue = "33417")]
impl<'a, T> TryFrom<&'a str> for T where T: FromStr {
type Error = <T as FromStr>::Err;

fn try_from(s: &'a str) -> Result<T, Self::Error> {
FromStr::from_str(s)
}
}
6 changes: 5 additions & 1 deletion src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ impl<'a> Formatter<'a> {
// is zero
Some(min) if self.sign_aware_zero_pad() => {
self.fill = '0';
self.align = rt::v1::Alignment::Right;
write_prefix(self)?;
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
f.buf.write_str(buf)
Expand Down Expand Up @@ -1153,8 +1154,9 @@ impl<'a> Formatter<'a> {
// for the sign-aware zero padding, we render the sign first and
// behave as if we had no sign from the beginning.
let mut formatted = formatted.clone();
let mut align = self.align;
let old_fill = self.fill;
let old_align = self.align;
let mut align = old_align;
if self.sign_aware_zero_pad() {
// a sign always goes first
let sign = unsafe { str::from_utf8_unchecked(formatted.sign) };
Expand All @@ -1165,6 +1167,7 @@ impl<'a> Formatter<'a> {
width = if width < sign.len() { 0 } else { width - sign.len() };
align = rt::v1::Alignment::Right;
self.fill = '0';
self.align = rt::v1::Alignment::Right;
}

// remaining parts go through the ordinary padding process.
Expand All @@ -1177,6 +1180,7 @@ impl<'a> Formatter<'a> {
})
};
self.fill = old_fill;
self.align = old_align;
ret
} else {
// this is the common case and we take a shortcut
Expand Down
8 changes: 7 additions & 1 deletion src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@
issue = "0")]
#![allow(missing_docs)]

extern "rust-intrinsic" {
#[cfg(not(stage0))]
#[stable(feature = "drop_in_place", since = "1.8.0")]
#[rustc_deprecated(reason = "no longer an intrinsic - use `ptr::drop_in_place` directly",
since = "1.18.0")]
pub use ptr::drop_in_place;

extern "rust-intrinsic" {
// NB: These intrinsics take raw pointers because they mutate aliased
// memory, which is not valid for either `&` or `&mut`.

Expand Down Expand Up @@ -622,6 +627,7 @@ extern "rust-intrinsic" {
pub fn size_of_val<T: ?Sized>(_: &T) -> usize;
pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize;

#[cfg(stage0)]
/// Executes the destructor (if any) of the pointed-to value.
///
/// This has two use cases:
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,7 @@ macro_rules! same_sign_try_from_int_impl {
($storage:ty, $target:ty, $($source:ty),*) => {$(
#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<$source> for $target {
type Err = TryFromIntError;
type Error = TryFromIntError;

fn try_from(u: $source) -> Result<$target, TryFromIntError> {
let min = <$target as FromStrRadixHelper>::min_value() as $storage;
Expand Down Expand Up @@ -2623,7 +2623,7 @@ macro_rules! cross_sign_from_int_impl {
($unsigned:ty, $($signed:ty),*) => {$(
#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<$unsigned> for $signed {
type Err = TryFromIntError;
type Error = TryFromIntError;

fn try_from(u: $unsigned) -> Result<$signed, TryFromIntError> {
let max = <$signed as FromStrRadixHelper>::max_value() as u128;
Expand All @@ -2637,7 +2637,7 @@ macro_rules! cross_sign_from_int_impl {

#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<$signed> for $unsigned {
type Err = TryFromIntError;
type Error = TryFromIntError;

fn try_from(u: $signed) -> Result<$unsigned, TryFromIntError> {
let max = <$unsigned as FromStrRadixHelper>::max_value() as u128;
Expand Down
29 changes: 29 additions & 0 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,38 @@ pub use intrinsics::copy;
#[stable(feature = "rust1", since = "1.0.0")]
pub use intrinsics::write_bytes;

#[cfg(stage0)]
#[stable(feature = "drop_in_place", since = "1.8.0")]
pub use intrinsics::drop_in_place;

#[cfg(not(stage0))]
/// Executes the destructor (if any) of the pointed-to value.
///
/// This has two use cases:
///
/// * It is *required* to use `drop_in_place` to drop unsized types like
/// trait objects, because they can't be read out onto the stack and
/// dropped normally.
///
/// * It is friendlier to the optimizer to do this over `ptr::read` when
/// dropping manually allocated memory (e.g. when writing Box/Rc/Vec),
/// as the compiler doesn't need to prove that it's sound to elide the
/// copy.
///
/// # Undefined Behavior
///
/// This has all the same safety problems as `ptr::read` with respect to
/// invalid pointers, types, and double drops.
#[stable(feature = "drop_in_place", since = "1.8.0")]
#[lang="drop_in_place"]
#[inline]
#[allow(unconditional_recursion)]
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
// Code here does not matter - this is replaced by the
// real drop glue by the compiler.
drop_in_place(to_drop);
}

/// Creates a null raw pointer.
///
/// # Examples
Expand Down
7 changes: 5 additions & 2 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use self::pattern::Pattern;
use self::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};

use char;
use convert::TryFrom;
use fmt;
use iter::{Map, Cloned, FusedIterator};
use mem;
Expand Down Expand Up @@ -1782,7 +1783,7 @@ pub trait StrExt {
#[stable(feature = "core", since = "1.6.0")]
fn is_empty(&self) -> bool;
#[stable(feature = "core", since = "1.6.0")]
fn parse<T: FromStr>(&self) -> Result<T, T::Err>;
fn parse<'a, T: TryFrom<&'a str>>(&'a self) -> Result<T, T::Error>;
}

// truncate `&str` to length at most equal to `max`
Expand Down Expand Up @@ -2081,7 +2082,9 @@ impl StrExt for str {
fn is_empty(&self) -> bool { self.len() == 0 }

#[inline]
fn parse<T: FromStr>(&self) -> Result<T, T::Err> { FromStr::from_str(self) }
fn parse<'a, T>(&'a self) -> Result<T, T::Error> where T: TryFrom<&'a str> {
T::try_from(self)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub enum DepNode<D: Clone + Debug> {
// things read/modify that MIR.
MirKrate,
Mir(D),
MirShim(Vec<D>),

BorrowCheckKrate,
BorrowCheck(D),
Expand Down Expand Up @@ -258,6 +259,10 @@ impl<D: Clone + Debug> DepNode<D> {
IntrinsicCheck(ref d) => op(d).map(IntrinsicCheck),
MatchCheck(ref d) => op(d).map(MatchCheck),
Mir(ref d) => op(d).map(Mir),
MirShim(ref def_ids) => {
let def_ids: Option<Vec<E>> = def_ids.iter().map(op).collect();
def_ids.map(MirShim)
}
BorrowCheck(ref d) => op(d).map(BorrowCheck),
RvalueCheck(ref d) => op(d).map(RvalueCheck),
StabilityCheck(ref d) => op(d).map(StabilityCheck),
Expand Down
11 changes: 6 additions & 5 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ impl<'a> CheckAttrVisitor<'a> {
}

fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
let name: &str = &attr.name().as_str();
match name {
"inline" => self.check_inline(attr, target),
"repr" => self.check_repr(attr, target),
_ => (),
if let Some(name) = attr.name() {
match &*name.as_str() {
"inline" => self.check_inline(attr, target),
"repr" => self.check_repr(attr, target),
_ => (),
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ impl<'a> LoweringContext<'a> {
let attrs = self.lower_attrs(&i.attrs);
let mut vis = self.lower_visibility(&i.vis);
if let ItemKind::MacroDef(ref tts) = i.node {
if i.attrs.iter().any(|attr| attr.name() == "macro_export") {
if i.attrs.iter().any(|attr| attr.path == "macro_export") {
self.exported_macros.push(hir::MacroDef {
name: name, attrs: attrs, id: i.id, span: i.span, body: tts.clone().into(),
});
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,14 @@ pub fn gather_attrs(attrs: &[ast::Attribute]) -> Vec<Result<(ast::Name, Level, S
pub fn gather_attr(attr: &ast::Attribute) -> Vec<Result<(ast::Name, Level, Span), Span>> {
let mut out = vec![];

let level = match Level::from_str(&attr.name().as_str()) {
let level = match attr.name().and_then(|name| Level::from_str(&name.as_str())) {
None => return out,
Some(lvl) => lvl,
};

let meta = unwrap_or!(attr.meta(), return out);
attr::mark_used(attr);

let meta = &attr.value;
let metas = if let Some(metas) = meta.meta_item_list() {
metas
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ language_item_table! {

ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
BoxFreeFnLangItem, "box_free", box_free_fn;
StrDupUniqFnLangItem, "strdup_uniq", strdup_uniq_fn;
DropInPlaceFnLangItem, "drop_in_place", drop_in_place_fn;

StartFnLangItem, "start", start_fn;

Expand All @@ -355,8 +355,6 @@ language_item_table! {
ContravariantLifetimeItem, "contravariant_lifetime", contravariant_lifetime;
InvariantLifetimeItem, "invariant_lifetime", invariant_lifetime;

NoCopyItem, "no_copy_bound", no_copy_bound;

NonZeroItem, "non_zero", non_zero;

DebugTraitLangItem, "debug_trait", debug_trait;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
} else {
// Emit errors for non-staged-api crates.
for attr in attrs {
let tag = attr.name();
let tag = unwrap_or!(attr.name(), continue);
if tag == "unstable" || tag == "stable" || tag == "rustc_deprecated" {
attr::mark_used(attr);
self.tcx.sess.span_err(attr.span(), "stability attributes may not be used \
Expand Down Expand Up @@ -402,7 +402,7 @@ impl<'a, 'tcx> Index<'tcx> {

let mut is_staged_api = false;
for attr in &krate.attrs {
if attr.name() == "stable" || attr.name() == "unstable" {
if attr.path == "stable" || attr.path == "unstable" {
is_staged_api = true;
break
}
Expand Down
18 changes: 17 additions & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_data_structures::control_flow_graph::{GraphPredecessors, GraphSuccesso
use rustc_data_structures::control_flow_graph::ControlFlowGraph;
use hir::def::CtorKind;
use hir::def_id::DefId;
use ty::subst::Substs;
use ty::subst::{Subst, Substs};
use ty::{self, AdtDef, ClosureSubsts, Region, Ty};
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use util::ppaux;
Expand Down Expand Up @@ -982,6 +982,22 @@ impl<'tcx> Debug for Operand<'tcx> {
}
}

impl<'tcx> Operand<'tcx> {
pub fn item<'a>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,
substs: &'tcx Substs<'tcx>,
span: Span)
-> Self
{
Operand::Constant(Constant {
span: span,
ty: tcx.item_type(def_id).subst(tcx, substs),
literal: Literal::Item { def_id, substs }
})
}

}

///////////////////////////////////////////////////////////////////////////
/// Rvalues

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
.filter(|a| a.check_name("rustc_on_unimplemented"))
.next()
{
let err_sp = item.meta().span.substitute_dummy(span);
let err_sp = item.span.substitute_dummy(span);
let trait_str = self.tcx.item_path_str(trait_ref.def_id);
if let Some(istring) = item.value_str() {
let istring = &*istring.as_str();
Expand Down
Loading