Skip to content

Commit 130c17d

Browse files
committed
Fallout in stdlib, rustdoc, rustc, etc. For most maps, converted uses of
`[]` on maps to `get` in rustc, since stage0 and stage1+ disagree about how to use `[]`.
1 parent be95ff4 commit 130c17d

Some content is hidden

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

59 files changed

+248
-162
lines changed

src/libcollections/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
264264
/// Some(x) => *x = "b",
265265
/// None => (),
266266
/// }
267-
/// assert_eq!(map[1], "b");
267+
/// assert_eq!(map[&1], "b");
268268
/// ```
269269
// See `get` for implementation notes, this is basically a copy-paste with mut's added
270270
#[stable(feature = "rust1", since = "1.0.0")]
@@ -326,7 +326,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
326326
///
327327
/// map.insert(37, "b");
328328
/// assert_eq!(map.insert(37, "c"), Some("b"));
329-
/// assert_eq!(map[37], "c");
329+
/// assert_eq!(map[&37], "c");
330330
/// ```
331331
#[stable(feature = "rust1", since = "1.0.0")]
332332
pub fn insert(&mut self, mut key: K, mut value: V) -> Option<V> {

src/libcollections/btree/node.rs

+61
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ macro_rules! node_slice_impl {
15221522
}
15231523

15241524
/// Returns a sub-slice with elements starting with `min_key`.
1525+
#[cfg(stage0)]
15251526
pub fn slice_from(self, min_key: &K) -> $NodeSlice<'a, K, V> {
15261527
// _______________
15271528
// |_1_|_3_|_5_|_7_|
@@ -1549,7 +1550,37 @@ macro_rules! node_slice_impl {
15491550
}
15501551
}
15511552

1553+
/// Returns a sub-slice with elements starting with `min_key`.
1554+
#[cfg(not(stage0))]
1555+
pub fn slice_from(self, min_key: &K) -> $NodeSlice<'a, K, V> {
1556+
// _______________
1557+
// |_1_|_3_|_5_|_7_|
1558+
// | | | | |
1559+
// 0 0 1 1 2 2 3 3 4 index
1560+
// | | | | |
1561+
// \___|___|___|___/ slice_from(&0); pos = 0
1562+
// \___|___|___/ slice_from(&2); pos = 1
1563+
// |___|___|___/ slice_from(&3); pos = 1; result.head_is_edge = false
1564+
// \___|___/ slice_from(&4); pos = 2
1565+
// \___/ slice_from(&6); pos = 3
1566+
// \|/ slice_from(&999); pos = 4
1567+
let (pos, pos_is_kv) = self.search_linear(min_key);
1568+
$NodeSlice {
1569+
has_edges: self.has_edges,
1570+
edges: if !self.has_edges {
1571+
self.edges
1572+
} else {
1573+
self.edges.$index(pos ..)
1574+
},
1575+
keys: &self.keys[pos ..],
1576+
vals: self.vals.$index(pos ..),
1577+
head_is_edge: !pos_is_kv,
1578+
tail_is_edge: self.tail_is_edge,
1579+
}
1580+
}
1581+
15521582
/// Returns a sub-slice with elements up to and including `max_key`.
1583+
#[cfg(stage0)]
15531584
pub fn slice_to(self, max_key: &K) -> $NodeSlice<'a, K, V> {
15541585
// _______________
15551586
// |_1_|_3_|_5_|_7_|
@@ -1577,6 +1608,36 @@ macro_rules! node_slice_impl {
15771608
tail_is_edge: !pos_is_kv,
15781609
}
15791610
}
1611+
1612+
/// Returns a sub-slice with elements up to and including `max_key`.
1613+
#[cfg(not(stage0))]
1614+
pub fn slice_to(self, max_key: &K) -> $NodeSlice<'a, K, V> {
1615+
// _______________
1616+
// |_1_|_3_|_5_|_7_|
1617+
// | | | | |
1618+
// 0 0 1 1 2 2 3 3 4 index
1619+
// | | | | |
1620+
//\|/ | | | | slice_to(&0); pos = 0
1621+
// \___/ | | | slice_to(&2); pos = 1
1622+
// \___|___| | | slice_to(&3); pos = 1; result.tail_is_edge = false
1623+
// \___|___/ | | slice_to(&4); pos = 2
1624+
// \___|___|___/ | slice_to(&6); pos = 3
1625+
// \___|___|___|___/ slice_to(&999); pos = 4
1626+
let (pos, pos_is_kv) = self.search_linear(max_key);
1627+
let pos = pos + if pos_is_kv { 1 } else { 0 };
1628+
$NodeSlice {
1629+
has_edges: self.has_edges,
1630+
edges: if !self.has_edges {
1631+
self.edges
1632+
} else {
1633+
self.edges.$index(.. (pos + 1))
1634+
},
1635+
keys: &self.keys[..pos],
1636+
vals: self.vals.$index(.. pos),
1637+
head_is_edge: self.head_is_edge,
1638+
tail_is_edge: !pos_is_kv,
1639+
}
1640+
}
15801641
}
15811642

15821643
impl<'a, K: 'a, V: 'a> $NodeSlice<'a, K, V> {

src/librustc/metadata/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl CStore {
111111
}
112112

113113
pub fn get_crate_data(&self, cnum: ast::CrateNum) -> Rc<crate_metadata> {
114-
(*self.metas.borrow())[cnum].clone()
114+
self.metas.borrow().get(&cnum).unwrap().clone()
115115
}
116116

117117
pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> Svh {

src/librustc/metadata/encoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
375375
match ecx.tcx.inherent_impls.borrow().get(&exp.def_id) {
376376
Some(implementations) => {
377377
for base_impl_did in &**implementations {
378-
for &method_did in &*(*impl_items)[*base_impl_did] {
378+
for &method_did in impl_items.get(base_impl_did).unwrap() {
379379
let impl_item = ty::impl_or_trait_item(
380380
ecx.tcx,
381381
method_did.def_id());
@@ -1175,7 +1175,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
11751175
// We need to encode information about the default methods we
11761176
// have inherited, so we drive this based on the impl structure.
11771177
let impl_items = tcx.impl_items.borrow();
1178-
let items = &(*impl_items)[def_id];
1178+
let items = impl_items.get(&def_id).unwrap();
11791179

11801180
add_to_index(item, rbml_w, index);
11811181
rbml_w.start_tag(tag_items_data_item);
@@ -1816,7 +1816,7 @@ struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> {
18161816
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
18171817
fn visit_item(&mut self, item: &ast::Item) {
18181818
if let ast::ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node {
1819-
let def_id = self.ecx.tcx.def_map.borrow()[trait_ref.ref_id].def_id();
1819+
let def_id = self.ecx.tcx.def_map.borrow().get(&trait_ref.ref_id).unwrap().def_id();
18201820

18211821
// Load eagerly if this is an implementation of the Drop trait
18221822
// or if the trait is not defined in this crate.

src/librustc/middle/astencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
12281228
var_id: var_id,
12291229
closure_expr_id: id
12301230
};
1231-
let upvar_capture = tcx.upvar_capture_map.borrow()[upvar_id].clone();
1231+
let upvar_capture = tcx.upvar_capture_map.borrow().get(&upvar_id).unwrap().clone();
12321232
var_id.encode(rbml_w);
12331233
upvar_capture.encode(rbml_w);
12341234
})

src/librustc/middle/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
874874
}
875875

876876
ast::PatEnum(_, ref args) => {
877-
let def = cx.tcx.def_map.borrow()[pat_id].full_def();
877+
let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def();
878878
match def {
879879
DefConst(..) =>
880880
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
@@ -892,7 +892,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
892892

893893
ast::PatStruct(_, ref pattern_fields, _) => {
894894
// Is this a struct or an enum variant?
895-
let def = cx.tcx.def_map.borrow()[pat_id].full_def();
895+
let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def();
896896
let class_id = match def {
897897
DefConst(..) =>
898898
cx.tcx.sess.span_bug(pat_span, "const pattern should've \

src/librustc/middle/const_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<ast::Pat>
150150
ast::PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr, span)).collect()),
151151

152152
ast::ExprCall(ref callee, ref args) => {
153-
let def = tcx.def_map.borrow()[callee.id];
153+
let def = *tcx.def_map.borrow().get(&callee.id).unwrap();
154154
if let Vacant(entry) = tcx.def_map.borrow_mut().entry(expr.id) {
155155
entry.insert(def);
156156
}

src/librustc/middle/dead.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
158158

159159
fn handle_field_pattern_match(&mut self, lhs: &ast::Pat,
160160
pats: &[codemap::Spanned<ast::FieldPat>]) {
161-
let id = match self.tcx.def_map.borrow()[lhs.id].full_def() {
161+
let id = match self.tcx.def_map.borrow().get(&lhs.id).unwrap().full_def() {
162162
def::DefVariant(_, id, _) => id,
163163
_ => {
164164
match ty::ty_to_def_id(ty::node_id_to_type(self.tcx,
@@ -496,7 +496,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
496496
None => (),
497497
Some(impl_list) => {
498498
for impl_did in &**impl_list {
499-
for item_did in &(*impl_items)[*impl_did] {
499+
for item_did in &*impl_items.get(impl_did).unwrap() {
500500
if self.live_symbols.contains(&item_did.def_id()
501501
.node) {
502502
return true;

src/librustc/middle/effect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
141141
match expr.node {
142142
ast::ExprMethodCall(_, _, _) => {
143143
let method_call = MethodCall::expr(expr.id);
144-
let base_type = (*self.tcx.method_map.borrow())[method_call].ty;
144+
let base_type = self.tcx.method_map.borrow().get(&method_call).unwrap().ty;
145145
debug!("effect: method call case, base type is {}",
146146
ppaux::ty_to_string(self.tcx, base_type));
147147
if type_is_unsafe_function(base_type) {

src/librustc/middle/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
10121012

10131013
// Each match binding is effectively an assignment to the
10141014
// binding being produced.
1015-
let def = def_map.borrow()[pat.id].full_def();
1015+
let def = def_map.borrow().get(&pat.id).unwrap().full_def();
10161016
match mc.cat_def(pat.id, pat.span, pat_ty, def) {
10171017
Ok(binding_cmt) => {
10181018
delegate.mutate(pat.id, pat.span, binding_cmt, Init);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
15331533
ConstrainVarSubReg(_, region) => {
15341534
state.result.push(RegionAndOrigin {
15351535
region: region,
1536-
origin: this.constraints.borrow()[edge.data].clone()
1536+
origin: this.constraints.borrow().get(&edge.data).unwrap().clone()
15371537
});
15381538
}
15391539
}

src/librustc/middle/liveness.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
448448
match expr.node {
449449
// live nodes required for uses or definitions of variables:
450450
ast::ExprPath(..) => {
451-
let def = ir.tcx.def_map.borrow()[expr.id].full_def();
451+
let def = ir.tcx.def_map.borrow().get(&expr.id).unwrap().full_def();
452452
debug!("expr {}: path that leads to {:?}", expr.id, def);
453453
if let DefLocal(..) = def {
454454
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
@@ -1302,7 +1302,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
13021302

13031303
fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: u32)
13041304
-> LiveNode {
1305-
match self.ir.tcx.def_map.borrow()[expr.id].full_def() {
1305+
match self.ir.tcx.def_map.borrow().get(&expr.id).unwrap().full_def() {
13061306
DefLocal(nid) => {
13071307
let ln = self.live_node(expr.id, expr.span);
13081308
if acc != 0 {
@@ -1564,7 +1564,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15641564
fn check_lvalue(&mut self, expr: &Expr) {
15651565
match expr.node {
15661566
ast::ExprPath(..) => {
1567-
if let DefLocal(nid) = self.ir.tcx.def_map.borrow()[expr.id].full_def() {
1567+
if let DefLocal(nid) = self.ir.tcx.def_map.borrow().get(&expr.id)
1568+
.unwrap()
1569+
.full_def() {
15681570
// Assignment to an immutable variable or argument: only legal
15691571
// if there is no later assignment. If this local is actually
15701572
// mutable, then check for a reassignment to flag the mutability

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
531531
}
532532

533533
ast::ExprPath(..) => {
534-
let def = self.tcx().def_map.borrow()[expr.id].full_def();
534+
let def = self.tcx().def_map.borrow().get(&expr.id).unwrap().full_def();
535535
self.cat_def(expr.id, expr.span, expr_ty, def)
536536
}
537537

src/librustc/middle/reachable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> {
128128
}
129129
ast::ExprMethodCall(..) => {
130130
let method_call = ty::MethodCall::expr(expr.id);
131-
match (*self.tcx.method_map.borrow())[method_call].origin {
131+
match (*self.tcx.method_map.borrow()).get(&method_call).unwrap().origin {
132132
ty::MethodStatic(def_id) => {
133133
if is_local(def_id) {
134134
if self.def_id_represents_local_inlined_item(def_id) {

src/librustc/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub fn check_item(tcx: &ty::ctxt, item: &ast::Item, warn_about_defns: bool,
319319
// individually as it's possible to have a stable trait with unstable
320320
// items.
321321
ast::ItemImpl(_, _, _, Some(ref t), _, ref impl_items) => {
322-
let trait_did = tcx.def_map.borrow()[t.ref_id].def_id();
322+
let trait_did = tcx.def_map.borrow().get(&t.ref_id).unwrap().def_id();
323323
let trait_items = ty::trait_items(tcx, trait_did);
324324

325325
for impl_item in impl_items {

src/librustc/middle/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,10 @@ fn confirm_impl_candidate<'cx,'tcx>(
854854
let impl_items_map = selcx.tcx().impl_items.borrow();
855855
let impl_or_trait_items_map = selcx.tcx().impl_or_trait_items.borrow();
856856

857-
let impl_items = &impl_items_map[impl_vtable.impl_def_id];
857+
let impl_items = impl_items_map.get(&impl_vtable.impl_def_id).unwrap();
858858
let mut impl_ty = None;
859859
for impl_item in impl_items {
860-
let assoc_type = match impl_or_trait_items_map[impl_item.def_id()] {
860+
let assoc_type = match *impl_or_trait_items_map.get(&impl_item.def_id()).unwrap() {
861861
ty::TypeTraitItem(ref assoc_type) => assoc_type.clone(),
862862
ty::MethodTraitItem(..) => { continue; }
863863
};

src/librustc/middle/ty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2667,22 +2667,22 @@ impl<'tcx> ctxt<'tcx> {
26672667
}
26682668

26692669
pub fn closure_kind(&self, def_id: ast::DefId) -> ty::ClosureKind {
2670-
self.closure_kinds.borrow()[def_id]
2670+
*self.closure_kinds.borrow().get(&def_id).unwrap()
26712671
}
26722672

26732673
pub fn closure_type(&self,
26742674
def_id: ast::DefId,
26752675
substs: &subst::Substs<'tcx>)
26762676
-> ty::ClosureTy<'tcx>
26772677
{
2678-
self.closure_tys.borrow()[def_id].subst(self, substs)
2678+
self.closure_tys.borrow().get(&def_id).unwrap().subst(self, substs)
26792679
}
26802680

26812681
pub fn type_parameter_def(&self,
26822682
node_id: ast::NodeId)
26832683
-> TypeParameterDef<'tcx>
26842684
{
2685-
self.ty_param_defs.borrow()[node_id].clone()
2685+
self.ty_param_defs.borrow().get(&node_id).unwrap().clone()
26862686
}
26872687
}
26882688

@@ -6540,7 +6540,7 @@ impl<'tcx> ctxt<'tcx> {
65406540
}
65416541

65426542
pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
6543-
Some(self.upvar_capture_map.borrow()[upvar_id].clone())
6543+
Some(self.upvar_capture_map.borrow().get(&upvar_id).unwrap().clone())
65446544
}
65456545
}
65466546

src/librustc_borrowck/borrowck/move_data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ impl<'tcx> MoveData<'tcx> {
486486
match path.loan_path.kind {
487487
LpVar(..) | LpUpvar(..) | LpDowncast(..) => {
488488
let kill_scope = path.loan_path.kill_scope(tcx);
489-
let path = self.path_map.borrow()[path.loan_path];
489+
let path = *self.path_map.borrow().get(&path.loan_path).unwrap();
490490
self.kill_moves(path, kill_scope.node_id(), dfcx_moves);
491491
}
492492
LpExtend(..) => {}

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ struct ImproperCTypesVisitor<'a, 'tcx: 'a> {
418418

419419
impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
420420
fn check_def(&mut self, sp: Span, id: ast::NodeId) {
421-
match self.cx.tcx.def_map.borrow()[id].full_def() {
421+
match self.cx.tcx.def_map.borrow().get(&id).unwrap().full_def() {
422422
def::DefPrimTy(ast::TyInt(ast::TyIs(_))) => {
423423
self.cx.span_lint(IMPROPER_CTYPES, sp,
424424
"found rust type `isize` in foreign module, while \

0 commit comments

Comments
 (0)