Skip to content

Commit

Permalink
Auto merge of #28689 - Manishearth:rollup, r=Manishearth
Browse files Browse the repository at this point in the history
- Successful merges: #28664, #28673, #28681, #28682, #28688
- Failed merges:
  • Loading branch information
bors committed Sep 27, 2015
2 parents 219eca1 + c34f3ea commit 638b260
Show file tree
Hide file tree
Showing 47 changed files with 195 additions and 122 deletions.
11 changes: 1 addition & 10 deletions src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,7 @@ impl<E> Clone for EnumSet<E> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<E:CLike + fmt::Debug> fmt::Debug for EnumSet<E> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
try!(write!(fmt, "{{"));
let mut first = true;
for e in self {
if !first {
try!(write!(fmt, ", "));
}
try!(write!(fmt, "{:?}", e));
first = false;
}
write!(fmt, "}}")
fmt.debug_set().entries(self).finish()
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,6 @@ impl str {
///
/// # Examples
/// ```
/// #![feature(str_split_at)]
///
/// let s = "Löwe 老虎 Léopard";
/// let first_space = s.find(' ').unwrap_or(s.len());
/// let (a, b) = s.split_at(first_space);
Expand Down
2 changes: 0 additions & 2 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,6 @@ impl<T> Vec<T> {
/// # Examples
///
/// ```
/// #![feature(split_off)]
///
/// let mut vec = vec![1,2,3];
/// let vec2 = vec.split_off(1);
/// assert_eq!(vec, [1]);
Expand Down
13 changes: 1 addition & 12 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,6 @@ impl<T> VecDeque<T> {
/// # Examples
///
/// ```
/// #![feature(split_off)]
///
/// use std::collections::VecDeque;
///
/// let mut buf: VecDeque<_> = vec![1,2,3].into_iter().collect();
Expand Down Expand Up @@ -1406,8 +1404,6 @@ impl<T> VecDeque<T> {
/// # Examples
///
/// ```
/// #![feature(vec_deque_retain)]
///
/// use std::collections::VecDeque;
///
/// let mut buf = VecDeque::new();
Expand Down Expand Up @@ -1787,14 +1783,7 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for VecDeque<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: fmt::Debug> fmt::Debug for VecDeque<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(write!(f, "["));

for (i, e) in self.iter().enumerate() {
if i != 0 { try!(write!(f, ", ")); }
try!(write!(f, "{:?}", *e));
}

write!(f, "]")
f.debug_list().entries(self).finish()
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/libcollectionstest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

#![feature(ascii)]
#![feature(append)]
#![feature(binary_heap_extras)]
#![feature(box_syntax)]
#![feature(btree_range)]
Expand All @@ -29,18 +28,14 @@
#![feature(set_recovery)]
#![feature(slice_bytes)]
#![feature(slice_splits)]
#![feature(split_off)]
#![feature(step_by)]
#![feature(str_char)]
#![feature(str_escape)]
#![feature(str_match_indices)]
#![feature(str_split_at)]
#![feature(str_utf16)]
#![feature(box_str)]
#![feature(test)]
#![feature(unboxed_closures)]
#![feature(unicode)]
#![feature(vec_deque_retain)]
#![feature(vec_push_all)]

#[macro_use] extern crate log;
Expand Down
7 changes: 6 additions & 1 deletion src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use std::rc::Rc;
use syntax::ast;
use syntax::codemap;
use syntax::codemap::{Span, DUMMY_SP};
use util::nodemap::{FnvHashMap, NodeMap};
use util::nodemap::{FnvHashMap, FnvHashSet, NodeMap};

use self::combine::CombineFields;
use self::region_inference::{RegionVarBindings, RegionSnapshot};
Expand Down Expand Up @@ -92,6 +92,10 @@ pub struct InferCtxt<'a, 'tcx: 'a> {

pub fulfillment_cx: RefCell<traits::FulfillmentContext<'tcx>>,

// the set of predicates on which errors have been reported, to
// avoid reporting the same error twice.
pub reported_trait_errors: RefCell<FnvHashSet<traits::TraitErrorKey<'tcx>>>,

// This is a temporary field used for toggling on normalization in the inference context,
// as we move towards the approach described here:
// https://internals.rust-lang.org/t/flattening-the-contexts-for-fun-and-profit/2293
Expand Down Expand Up @@ -374,6 +378,7 @@ pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>,
region_vars: RegionVarBindings::new(tcx),
parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()),
fulfillment_cx: RefCell::new(traits::FulfillmentContext::new(errors_will_be_reported)),
reported_trait_errors: RefCell::new(FnvHashSet()),
normalize: false,
err_count_on_creation: tcx.sess.err_count()
}
Expand Down
14 changes: 9 additions & 5 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,17 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
// this properly would result in the necessity of computing *type*
// reachability, which might result in a compile time loss.
fn mark_destructors_reachable(&mut self) {
for adt in self.tcx.adt_defs() {
if let Some(destructor_def_id) = adt.destructor() {
if destructor_def_id.is_local() {
self.reachable_symbols.insert(destructor_def_id.node);
let drop_trait = match self.tcx.lang_items.drop_trait() {
Some(id) => self.tcx.lookup_trait_def(id), None => { return }
};
drop_trait.for_each_impl(self.tcx, |drop_impl| {
for destructor in &self.tcx.impl_items.borrow()[&drop_impl] {
let destructor_did = destructor.def_id();
if destructor_did.is_local() {
self.reachable_symbols.insert(destructor_did.node);
}
}
}
})
}
}

Expand Down
36 changes: 34 additions & 2 deletions src/librustc/middle/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,32 @@ use middle::def_id::DefId;
use middle::infer::InferCtxt;
use middle::ty::{self, ToPredicate, HasTypeFlags, ToPolyTraitRef, TraitRef, Ty};
use middle::ty::fold::TypeFoldable;
use std::collections::HashMap;
use util::nodemap::{FnvHashMap, FnvHashSet};

use std::fmt;
use syntax::codemap::Span;
use syntax::attr::{AttributeMethods, AttrMetaMethods};

#[derive(Debug, PartialEq, Eq, Hash)]
pub struct TraitErrorKey<'tcx> {
is_warning: bool,
span: Span,
predicate: ty::Predicate<'tcx>
}

impl<'tcx> TraitErrorKey<'tcx> {
fn from_error<'a>(infcx: &InferCtxt<'a, 'tcx>,
e: &FulfillmentError<'tcx>) -> Self {
let predicate =
infcx.resolve_type_vars_if_possible(&e.obligation.predicate);
TraitErrorKey {
is_warning: is_warning(&e.obligation),
span: e.obligation.cause.span,
predicate: infcx.tcx.erase_regions(&predicate)
}
}
}

pub fn report_fulfillment_errors<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
errors: &Vec<FulfillmentError<'tcx>>) {
for error in errors {
Expand All @@ -42,6 +63,13 @@ pub fn report_fulfillment_errors<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,

fn report_fulfillment_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
error: &FulfillmentError<'tcx>) {
let error_key = TraitErrorKey::from_error(infcx, error);
debug!("report_fulfillment_errors({:?}) - key={:?}",
error, error_key);
if !infcx.reported_trait_errors.borrow_mut().insert(error_key) {
debug!("report_fulfillment_errors: skipping duplicate");
return;
}
match error.code {
FulfillmentErrorCode::CodeSelectionError(ref e) => {
report_selection_error(infcx, &error.obligation, e);
Expand Down Expand Up @@ -97,7 +125,7 @@ fn report_on_unimplemented<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
(gen.name.as_str().to_string(),
trait_ref.substs.types.get(param, i)
.to_string())
}).collect::<HashMap<String, String>>();
}).collect::<FnvHashMap<String, String>>();
generic_map.insert("Self".to_string(),
trait_ref.self_ty().to_string());
let parser = Parser::new(&istring);
Expand Down Expand Up @@ -308,7 +336,11 @@ pub fn report_object_safety_error<'tcx>(tcx: &ty::ctxt<'tcx>,
"the trait `{}` cannot be made into an object",
tcx.item_path_str(trait_def_id));

let mut reported_violations = FnvHashSet();
for violation in violations {
if !reported_violations.insert(violation.clone()) {
continue;
}
match violation {
ObjectSafetyViolation::SizedSelf => {
tcx.sess.fileline_note(
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/middle/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ pub struct FulfillmentContext<'tcx> {
// than the `SelectionCache`: it avoids duplicate errors and
// permits recursive obligations, which are often generated from
// traits like `Send` et al.
//
// Note that because of type inference, a predicate can still
// occur twice in the predicates list, for example when 2
// initially-distinct type variables are unified after being
// inserted. Deduplicating the predicate set on selection had a
// significant performance cost the last time I checked.
duplicate_set: FulfilledPredicates<'tcx>,

// A list of all obligations that have been registered with this
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/middle/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ use middle::subst;
use middle::ty::{self, HasTypeFlags, Ty};
use middle::ty::fold::TypeFoldable;
use middle::infer::{self, fixup_err_to_string, InferCtxt};

use std::rc::Rc;
use syntax::ast;
use syntax::codemap::{Span, DUMMY_SP};

pub use self::error_reporting::TraitErrorKey;
pub use self::error_reporting::report_fulfillment_errors;
pub use self::error_reporting::report_overflow_error;
pub use self::error_reporting::report_selection_error;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use middle::ty::{self, ToPolyTraitRef, Ty};
use std::rc::Rc;
use syntax::ast;

#[derive(Debug)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ObjectSafetyViolation<'tcx> {
/// Self : Sized declared on the trait
SizedSelf,
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@ pub struct ctxt<'tcx> {
/// True if the variance has been computed yet; false otherwise.
pub variance_computed: Cell<bool>,

/// A method will be in this list if and only if it is a destructor.
pub destructors: RefCell<DefIdSet>,

/// Maps a DefId of a type to a list of its inherent impls.
/// Contains implementations of methods that are inherent to a type.
/// Methods in these implementations don't need to be exported.
Expand Down Expand Up @@ -475,7 +472,6 @@ impl<'tcx> ctxt<'tcx> {
normalized_cache: RefCell::new(FnvHashMap()),
lang_items: lang_items,
provided_method_sources: RefCell::new(DefIdMap()),
destructors: RefCell::new(DefIdSet()),
inherent_impls: RefCell::new(DefIdMap()),
impl_items: RefCell::new(DefIdMap()),
used_unsafe: RefCell::new(NodeSet()),
Expand Down
20 changes: 14 additions & 6 deletions src/librustc/middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ impl<'tcx> Method<'tcx> {
}
}

impl<'tcx> PartialEq for Method<'tcx> {
#[inline]
fn eq(&self, other: &Self) -> bool { self.def_id == other.def_id }
}

impl<'tcx> Eq for Method<'tcx> {}

impl<'tcx> Hash for Method<'tcx> {
#[inline]
fn hash<H: Hasher>(&self, s: &mut H) {
self.def_id.hash(s)
}
}

#[derive(Clone, Copy, Debug)]
pub struct AssociatedConst<'tcx> {
pub name: Name,
Expand Down Expand Up @@ -1681,7 +1695,6 @@ impl<'tcx, 'container> AdtDefData<'tcx, 'container> {
}

pub fn set_destructor(&self, dtor: DefId) {
assert!(self.destructor.get().is_none());
self.destructor.set(Some(dtor));
}

Expand Down Expand Up @@ -2315,11 +2328,6 @@ impl<'tcx> ctxt<'tcx> {
self.lookup_adt_def_master(did)
}

/// Return the list of all interned ADT definitions
pub fn adt_defs(&self) -> Vec<AdtDef<'tcx>> {
self.adt_defs.borrow().values().cloned().collect()
}

/// Given the did of an item, returns its full set of predicates.
pub fn lookup_predicates(&self, did: DefId) -> GenericPredicates<'tcx> {
lookup_locally_or_in_crate_store(
Expand Down
1 change: 0 additions & 1 deletion src/librustc_front/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#![feature(staged_api)]
#![feature(str_char)]
#![feature(filling_drop)]
#![cfg_attr(test, feature(test))]

extern crate serialize;
#[macro_use] extern crate log;
Expand Down
19 changes: 9 additions & 10 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,15 +1210,14 @@ impl LintPass for DropWithReprExtern {

impl LateLintPass for DropWithReprExtern {
fn check_crate(&mut self, ctx: &LateContext, _: &hir::Crate) {
for dtor_did in ctx.tcx.destructors.borrow().iter() {
let (drop_impl_did, dtor_self_type) =
if dtor_did.is_local() {
let impl_did = ctx.tcx.map.get_parent_did(dtor_did.node);
let ty = ctx.tcx.lookup_item_type(impl_did).ty;
(impl_did, ty)
} else {
continue;
};
let drop_trait = match ctx.tcx.lang_items.drop_trait() {
Some(id) => ctx.tcx.lookup_trait_def(id), None => { return }
};
drop_trait.for_each_impl(ctx.tcx, |drop_impl_did| {
if !drop_impl_did.is_local() {
return;
}
let dtor_self_type = ctx.tcx.lookup_item_type(drop_impl_did).ty;

match dtor_self_type.sty {
ty::TyEnum(self_type_def, _) |
Expand All @@ -1244,6 +1243,6 @@ impl LateLintPass for DropWithReprExtern {
}
_ => {}
}
}
})
}
}
7 changes: 5 additions & 2 deletions src/librustc_trans/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,13 @@ impl<'a> ArchiveBuilder<'a> {

/// Adds all of the contents of a native library to this archive. This will
/// search in the relevant locations for a library named `name`.
pub fn add_native_library(&mut self, name: &str) -> io::Result<()> {
pub fn add_native_library(&mut self, name: &str) {
let location = find_library(name, &self.config.lib_search_paths,
self.config.sess);
self.add_archive(&location, name, |_| false)
self.add_archive(&location, name, |_| false).unwrap_or_else(|e| {
self.config.sess.fatal(&format!("failed to add native library {}: {}",
location.to_string_lossy(), e));
});
}

/// Adds all of the contents of the rlib at the specified path to this
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ fn link_rlib<'a>(sess: &'a Session,

for &(ref l, kind) in sess.cstore.get_used_libraries().borrow().iter() {
match kind {
cstore::NativeStatic => ab.add_native_library(&l).unwrap(),
cstore::NativeStatic => ab.add_native_library(&l),
cstore::NativeFramework | cstore::NativeUnknown => {}
}
}
Expand Down Expand Up @@ -792,7 +792,7 @@ fn link_staticlib(sess: &Session, objects: &[PathBuf], out_filename: &Path,
ab.build();
}
if !sess.target.target.options.no_compiler_rt {
ab.add_native_library("compiler-rt").unwrap();
ab.add_native_library("compiler-rt");
}

let mut all_native_libs = vec![];
Expand Down
8 changes: 1 addition & 7 deletions src/librustc_typeck/check/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,13 +620,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
ty::TraitContainer(trait_def_id) => {
callee::check_legal_trait_for_method_call(self.fcx.ccx, self.span, trait_def_id)
}
ty::ImplContainer(..) => {
// Since `drop` is a trait method, we expect that any
// potential calls to it will wind up in the other
// arm. But just to be sure, check that the method id
// does not appear in the list of destructors.
assert!(!self.tcx().destructors.borrow().contains(&pick.item.def_id()));
}
ty::ImplContainer(..) => {}
}
}

Expand Down
Loading

0 comments on commit 638b260

Please sign in to comment.