Skip to content

Commit 785a8a6

Browse files
committed
Auto merge of #30410 - Manishearth:rollup, r=Manishearth
- Successful merges: #30320, #30368, #30372, #30376, #30388, #30392 - Failed merges: #30354, #30389
2 parents ce7bc51 + f0361a0 commit 785a8a6

Some content is hidden

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

64 files changed

+455
-270
lines changed

src/libcollections/btree/set.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ use Bound;
2626

2727
/// A set based on a B-Tree.
2828
///
29-
/// See BTreeMap's documentation for a detailed discussion of this collection's performance
29+
/// See [`BTreeMap`]'s documentation for a detailed discussion of this collection's performance
3030
/// benefits and drawbacks.
3131
///
3232
/// It is a logic error for an item to be modified in such a way that the item's ordering relative
33-
/// to any other item, as determined by the `Ord` trait, changes while it is in the set. This is
34-
/// normally only possible through `Cell`, `RefCell`, global state, I/O, or unsafe code.
33+
/// to any other item, as determined by the [`Ord`] trait, changes while it is in the set. This is
34+
/// normally only possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code.
35+
///
36+
/// [`BTreeMap`]: ../struct.BTreeMap.html
37+
/// [`Ord`]: ../../core/cmp/trait.Ord.html
38+
/// [`Cell`]: ../../std/cell/struct.Cell.html
39+
/// [`RefCell`]: ../../std/cell/struct.RefCell.html
3540
#[derive(Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
3641
#[stable(feature = "rust1", since = "1.0.0")]
3742
pub struct BTreeSet<T> {

src/librustc/middle/check_static_recursion.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ pub fn check_crate<'ast>(sess: &Session,
9999
ast_map: ast_map,
100100
discriminant_map: RefCell::new(NodeMap()),
101101
};
102-
krate.visit_all_items(&mut visitor);
103-
sess.abort_if_errors();
102+
sess.abort_if_new_errors(|| {
103+
krate.visit_all_items(&mut visitor);
104+
});
104105
}
105106

106107
struct CheckItemRecursionVisitor<'a, 'ast: 'a> {

src/librustc/middle/def.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub enum Def {
5252
DefStruct(DefId),
5353
DefLabel(ast::NodeId),
5454
DefMethod(DefId),
55+
DefErr,
5556
}
5657

5758
/// The result of resolving a path.
@@ -124,7 +125,7 @@ impl Def {
124125
DefVariant(..) | DefTy(..) | DefAssociatedTy(..) |
125126
DefTyParam(..) | DefUse(..) | DefStruct(..) | DefTrait(..) |
126127
DefMethod(..) | DefConst(..) | DefAssociatedConst(..) |
127-
DefPrimTy(..) | DefLabel(..) | DefSelfTy(..) => {
128+
DefPrimTy(..) | DefLabel(..) | DefSelfTy(..) | DefErr => {
128129
panic!("attempted .def_id() on invalid {:?}", self)
129130
}
130131
}
@@ -142,7 +143,8 @@ impl Def {
142143

143144
DefLabel(..) |
144145
DefPrimTy(..) |
145-
DefSelfTy(..) => {
146+
DefSelfTy(..) |
147+
DefErr => {
146148
panic!("attempted .def_id() on invalid def: {:?}", self)
147149
}
148150
}

src/librustc/middle/infer/region_inference/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub use self::RegionResolutionError::*;
1818
pub use self::VarValue::*;
1919

2020
use super::{RegionVariableOrigin, SubregionOrigin, TypeTrace, MiscVariable};
21+
use super::unify_key;
2122

2223
use rustc_data_structures::graph::{self, Direction, NodeIndex};
2324
use rustc_data_structures::unify::{self, UnificationTable};
@@ -345,10 +346,13 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
345346
}
346347

347348
pub fn new_region_var(&self, origin: RegionVariableOrigin) -> RegionVid {
348-
let id = self.num_vars();
349+
let vid = RegionVid { index: self.num_vars() };
349350
self.var_origins.borrow_mut().push(origin.clone());
350-
let vid = self.unification_table.borrow_mut().new_key(());
351-
assert_eq!(vid.index, id);
351+
352+
let u_vid = self.unification_table.borrow_mut().new_key(
353+
unify_key::RegionVidKey { min_vid: vid }
354+
);
355+
assert_eq!(vid, u_vid);
352356
if self.in_snapshot() {
353357
self.undo_log.borrow_mut().push(AddVar(vid));
354358
}
@@ -581,7 +585,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
581585
}
582586

583587
pub fn opportunistic_resolve_var(&self, rid: RegionVid) -> ty::Region {
584-
ty::ReVar(self.unification_table.borrow_mut().find(rid))
588+
ty::ReVar(self.unification_table.borrow_mut().find_value(rid).min_vid)
585589
}
586590

587591
fn combine_map(&self, t: CombineMapType) -> &RefCell<CombineMap> {

src/librustc/middle/infer/unify_key.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use syntax::ast;
1212
use middle::ty::{self, IntVarValue, Ty};
13-
use rustc_data_structures::unify::UnifyKey;
13+
use rustc_data_structures::unify::{Combine, UnifyKey};
1414

1515
pub trait ToType<'tcx> {
1616
fn to_type(&self, tcx: &ty::ctxt<'tcx>) -> Ty<'tcx>;
@@ -23,8 +23,28 @@ impl UnifyKey for ty::IntVid {
2323
fn tag(_: Option<ty::IntVid>) -> &'static str { "IntVid" }
2424
}
2525

26+
#[derive(PartialEq, Copy, Clone, Debug)]
27+
pub struct RegionVidKey {
28+
/// The minimum region vid in the unification set. This is needed
29+
/// to have a canonical name for a type to prevent infinite
30+
/// recursion.
31+
pub min_vid: ty::RegionVid
32+
}
33+
34+
impl Combine for RegionVidKey {
35+
fn combine(&self, other: &RegionVidKey) -> RegionVidKey {
36+
let min_vid = if self.min_vid.index < other.min_vid.index {
37+
self.min_vid
38+
} else {
39+
other.min_vid
40+
};
41+
42+
RegionVidKey { min_vid: min_vid }
43+
}
44+
}
45+
2646
impl UnifyKey for ty::RegionVid {
27-
type Value = ();
47+
type Value = RegionVidKey;
2848
fn index(&self) -> u32 { self.index }
2949
fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid { index: i } }
3050
fn tag(_: Option<ty::RegionVid>) -> &'static str { "RegionVid" }

src/librustc/middle/mem_categorization.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
609609
note: NoteNone
610610
}))
611611
}
612+
613+
def::DefErr => panic!("DefErr in memory categorization")
612614
}
613615
}
614616

@@ -1196,7 +1198,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
11961198
(*op)(self, cmt.clone(), pat);
11971199

11981200
let opt_def = if let Some(path_res) = self.tcx().def_map.borrow().get(&pat.id) {
1199-
if path_res.depth != 0 {
1201+
if path_res.depth != 0 || path_res.base_def == def::DefErr {
12001202
// Since patterns can be associated constants
12011203
// which are resolved during typeck, we might have
12021204
// some unresolved patterns reaching this stage
@@ -1261,7 +1263,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
12611263
_ => {
12621264
self.tcx().sess.span_bug(
12631265
pat.span,
1264-
"enum pattern didn't resolve to enum or struct");
1266+
&format!("enum pattern didn't resolve to enum or struct {:?}", opt_def));
12651267
}
12661268
}
12671269
}

src/librustc/middle/resolve_lifetime.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,16 @@ static ROOT_SCOPE: ScopeChain<'static> = RootScope;
9595

9696
pub fn krate(sess: &Session, krate: &hir::Crate, def_map: &DefMap) -> NamedRegionMap {
9797
let mut named_region_map = NodeMap();
98-
krate.visit_all_items(&mut LifetimeContext {
99-
sess: sess,
100-
named_region_map: &mut named_region_map,
101-
scope: &ROOT_SCOPE,
102-
def_map: def_map,
103-
trait_ref_hack: false,
104-
labels_in_fn: vec![],
98+
sess.abort_if_new_errors(|| {
99+
krate.visit_all_items(&mut LifetimeContext {
100+
sess: sess,
101+
named_region_map: &mut named_region_map,
102+
scope: &ROOT_SCOPE,
103+
def_map: def_map,
104+
trait_ref_hack: false,
105+
labels_in_fn: vec![],
106+
});
105107
});
106-
sess.abort_if_errors();
107108
named_region_map
108109
}
109110

src/librustc/middle/ty/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2100,9 +2100,8 @@ impl<'tcx> ctxt<'tcx> {
21002100
}) => {
21012101
true
21022102
}
2103-
2103+
Some(&def::PathResolution { base_def: def::DefErr, .. })=> true,
21042104
Some(..) => false,
2105-
21062105
None => self.sess.span_bug(expr.span, &format!(
21072106
"no def for path {}", expr.id))
21082107
}

src/librustc/session/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ impl Session {
156156
_ => {}
157157
}
158158
}
159+
pub fn abort_if_new_errors<F>(&self, mut f: F)
160+
where F: FnMut()
161+
{
162+
let count = self.err_count();
163+
f();
164+
if self.err_count() > count {
165+
self.abort_if_errors();
166+
}
167+
}
159168
pub fn span_warn(&self, sp: Span, msg: &str) {
160169
if self.can_print_warnings {
161170
self.diagnostic().span_warn(sp, msg)

src/librustc_borrowck/borrowck/gather_loans/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ use rustc_front::hir::{Expr, FnDecl, Block, Pat};
3333
use rustc_front::intravisit;
3434
use rustc_front::intravisit::Visitor;
3535

36+
use self::restrictions::RestrictionResult;
37+
3638
mod lifetime;
3739
mod restrictions;
3840
mod gather_moves;
@@ -354,12 +356,12 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
354356

355357
// Create the loan record (if needed).
356358
let loan = match restr {
357-
restrictions::Safe => {
359+
RestrictionResult::Safe => {
358360
// No restrictions---no loan record necessary
359361
return;
360362
}
361363

362-
restrictions::SafeIf(loan_path, restricted_paths) => {
364+
RestrictionResult::SafeIf(loan_path, restricted_paths) => {
363365
let loan_scope = match loan_region {
364366
ty::ReScope(scope) => scope,
365367

src/librustc_borrowck/borrowck/gather_loans/restrictions.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
//! Computes the restrictions that result from a borrow.
1212
13-
pub use self::RestrictionResult::*;
14-
1513
use borrowck::*;
1614
use rustc::middle::expr_use_visitor as euv;
1715
use rustc::middle::mem_categorization as mc;
@@ -69,19 +67,19 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
6967
// are inherently non-aliasable, they can only be
7068
// accessed later through the borrow itself and hence
7169
// must inherently comply with its terms.
72-
Safe
70+
RestrictionResult::Safe
7371
}
7472

7573
Categorization::Local(local_id) => {
7674
// R-Variable, locally declared
7775
let lp = new_lp(LpVar(local_id));
78-
SafeIf(lp.clone(), vec![lp])
76+
RestrictionResult::SafeIf(lp.clone(), vec![lp])
7977
}
8078

8179
Categorization::Upvar(mc::Upvar { id, .. }) => {
8280
// R-Variable, captured into closure
8381
let lp = new_lp(LpUpvar(id));
84-
SafeIf(lp.clone(), vec![lp])
82+
RestrictionResult::SafeIf(lp.clone(), vec![lp])
8583
}
8684

8785
Categorization::Downcast(cmt_base, _) => {
@@ -106,7 +104,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
106104
}
107105

108106
Categorization::StaticItem => {
109-
Safe
107+
RestrictionResult::Safe
110108
}
111109

112110
Categorization::Deref(cmt_base, _, pk) => {
@@ -133,11 +131,11 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
133131
cmt: cmt_base,
134132
code: err_borrowed_pointer_too_short(
135133
self.loan_region, lt)});
136-
return Safe;
134+
return RestrictionResult::Safe;
137135
}
138136

139137
match bk {
140-
ty::ImmBorrow => Safe,
138+
ty::ImmBorrow => RestrictionResult::Safe,
141139
ty::MutBorrow | ty::UniqueImmBorrow => {
142140
// R-Deref-Mut-Borrowed
143141
//
@@ -150,7 +148,7 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
150148
}
151149
}
152150
// Borrowck is not relevant for raw pointers
153-
mc::UnsafePtr(..) => Safe
151+
mc::UnsafePtr(..) => RestrictionResult::Safe
154152
}
155153
}
156154
}
@@ -161,12 +159,12 @@ impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> {
161159
cmt: &mc::cmt<'tcx>,
162160
elem: LoanPathElem) -> RestrictionResult<'tcx> {
163161
match result {
164-
Safe => Safe,
165-
SafeIf(base_lp, mut base_vec) => {
162+
RestrictionResult::Safe => RestrictionResult::Safe,
163+
RestrictionResult::SafeIf(base_lp, mut base_vec) => {
166164
let v = LpExtend(base_lp, cmt.mutbl, elem);
167165
let lp = Rc::new(LoanPath::new(v, cmt.ty));
168166
base_vec.push(lp.clone());
169-
SafeIf(lp, base_vec)
167+
RestrictionResult::SafeIf(lp, base_vec)
170168
}
171169
}
172170
}

src/librustc_data_structures/unify/mod.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ pub trait UnifyKey : Copy + Clone + Debug + PartialEq {
3737
fn tag(k: Option<Self>) -> &'static str;
3838
}
3939

40+
/// This trait is implemented for unify values that can be
41+
/// combined. This relation should be a monoid.
42+
pub trait Combine {
43+
fn combine(&self, other: &Self) -> Self;
44+
}
45+
46+
impl Combine for () {
47+
fn combine(&self, _other: &()) {}
48+
}
49+
4050
/// Value of a unification key. We implement Tarjan's union-find
4151
/// algorithm: when two keys are unified, one of them is converted
4252
/// into a "redirect" pointing at the other. These redirects form a
@@ -243,23 +253,28 @@ impl<K:UnifyKey> sv::SnapshotVecDelegate for Delegate<K> {
243253
///////////////////////////////////////////////////////////////////////////
244254
// Base union-find algorithm, where we are just making sets
245255

246-
impl<'tcx,K> UnificationTable<K>
247-
where K : UnifyKey<Value=()>,
256+
impl<'tcx,K:UnifyKey> UnificationTable<K>
257+
where K::Value: Combine
248258
{
249259
pub fn union(&mut self, a_id: K, b_id: K) {
250260
let node_a = self.get(a_id);
251261
let node_b = self.get(b_id);
252262
let a_id = node_a.key();
253263
let b_id = node_b.key();
254264
if a_id != b_id {
255-
self.unify(node_a, node_b, ());
265+
let new_value = node_a.value.combine(&node_b.value);
266+
self.unify(node_a, node_b, new_value);
256267
}
257268
}
258269

259270
pub fn find(&mut self, id: K) -> K {
260271
self.get(id).key()
261272
}
262273

274+
pub fn find_value(&mut self, id: K) -> K::Value {
275+
self.get(id).value
276+
}
277+
263278
pub fn unioned(&mut self, a_id: K, b_id: K) -> bool {
264279
self.find(a_id) == self.find(b_id)
265280
}

src/librustc_metadata/astencode.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ impl tr for def::Def {
407407
def::DefUpvar(did1, nid1, index, nid2)
408408
}
409409
def::DefStruct(did) => def::DefStruct(did.tr(dcx)),
410-
def::DefLabel(nid) => def::DefLabel(dcx.tr_id(nid))
410+
def::DefLabel(nid) => def::DefLabel(dcx.tr_id(nid)),
411+
def::DefErr => def::DefErr,
411412
}
412413
}
413414
}

src/librustc_resolve/build_reduced_graph.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
709709
DefUse(..) |
710710
DefUpvar(..) |
711711
DefLabel(..) |
712-
DefSelfTy(..) => {
712+
DefSelfTy(..) |
713+
DefErr => {
713714
panic!("didn't expect `{:?}`", def);
714715
}
715716
}

0 commit comments

Comments
 (0)