Skip to content

Commit

Permalink
Fallout in stdlib, rustdoc, rustc, etc. For most maps, converted uses of
Browse files Browse the repository at this point in the history
`[]` on maps to `get` in rustc, since stage0 and stage1+ disagree about
how to use `[]`.
  • Loading branch information
nikomatsakis committed Mar 23, 2015
1 parent b4d4daf commit 8e58af4
Show file tree
Hide file tree
Showing 57 changed files with 245 additions and 159 deletions.
4 changes: 2 additions & 2 deletions src/libcollections/btree/map.rs
Expand Up @@ -264,7 +264,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// Some(x) => *x = "b",
/// None => (),
/// }
/// assert_eq!(map[1], "b");
/// assert_eq!(map[&1], "b");
/// ```
// See `get` for implementation notes, this is basically a copy-paste with mut's added
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -326,7 +326,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
///
/// map.insert(37, "b");
/// assert_eq!(map.insert(37, "c"), Some("b"));
/// assert_eq!(map[37], "c");
/// assert_eq!(map[&37], "c");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn insert(&mut self, mut key: K, mut value: V) -> Option<V> {
Expand Down
61 changes: 61 additions & 0 deletions src/libcollections/btree/node.rs
Expand Up @@ -1522,6 +1522,7 @@ macro_rules! node_slice_impl {
}

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

/// Returns a sub-slice with elements starting with `min_key`.
#[cfg(not(stage0))]
pub fn slice_from(self, min_key: &K) -> $NodeSlice<'a, K, V> {
// _______________
// |_1_|_3_|_5_|_7_|
// | | | | |
// 0 0 1 1 2 2 3 3 4 index
// | | | | |
// \___|___|___|___/ slice_from(&0); pos = 0
// \___|___|___/ slice_from(&2); pos = 1
// |___|___|___/ slice_from(&3); pos = 1; result.head_is_edge = false
// \___|___/ slice_from(&4); pos = 2
// \___/ slice_from(&6); pos = 3
// \|/ slice_from(&999); pos = 4
let (pos, pos_is_kv) = self.search_linear(min_key);
$NodeSlice {
has_edges: self.has_edges,
edges: if !self.has_edges {
self.edges
} else {
self.edges.$index(pos ..)
},
keys: &self.keys[pos ..],
vals: self.vals.$index(pos ..),
head_is_edge: !pos_is_kv,
tail_is_edge: self.tail_is_edge,
}
}

/// Returns a sub-slice with elements up to and including `max_key`.
#[cfg(stage0)]
pub fn slice_to(self, max_key: &K) -> $NodeSlice<'a, K, V> {
// _______________
// |_1_|_3_|_5_|_7_|
Expand Down Expand Up @@ -1577,6 +1608,36 @@ macro_rules! node_slice_impl {
tail_is_edge: !pos_is_kv,
}
}

/// Returns a sub-slice with elements up to and including `max_key`.
#[cfg(not(stage0))]
pub fn slice_to(self, max_key: &K) -> $NodeSlice<'a, K, V> {
// _______________
// |_1_|_3_|_5_|_7_|
// | | | | |
// 0 0 1 1 2 2 3 3 4 index
// | | | | |
//\|/ | | | | slice_to(&0); pos = 0
// \___/ | | | slice_to(&2); pos = 1
// \___|___| | | slice_to(&3); pos = 1; result.tail_is_edge = false
// \___|___/ | | slice_to(&4); pos = 2
// \___|___|___/ | slice_to(&6); pos = 3
// \___|___|___|___/ slice_to(&999); pos = 4
let (pos, pos_is_kv) = self.search_linear(max_key);
let pos = pos + if pos_is_kv { 1 } else { 0 };
$NodeSlice {
has_edges: self.has_edges,
edges: if !self.has_edges {
self.edges
} else {
self.edges.$index(.. (pos + 1))
},
keys: &self.keys[..pos],
vals: self.vals.$index(.. pos),
head_is_edge: self.head_is_edge,
tail_is_edge: !pos_is_kv,
}
}
}

impl<'a, K: 'a, V: 'a> $NodeSlice<'a, K, V> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/cstore.rs
Expand Up @@ -111,7 +111,7 @@ impl CStore {
}

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

pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> Svh {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/encoder.rs
Expand Up @@ -375,7 +375,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
match ecx.tcx.inherent_impls.borrow().get(&exp.def_id) {
Some(implementations) => {
for base_impl_did in &**implementations {
for &method_did in &*(*impl_items)[*base_impl_did] {
for &method_did in impl_items.get(base_impl_did).unwrap() {
let impl_item = ty::impl_or_trait_item(
ecx.tcx,
method_did.def_id());
Expand Down Expand Up @@ -1175,7 +1175,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
// We need to encode information about the default methods we
// have inherited, so we drive this based on the impl structure.
let impl_items = tcx.impl_items.borrow();
let items = &(*impl_items)[def_id];
let items = impl_items.get(&def_id).unwrap();

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

// Load eagerly if this is an implementation of the Drop trait
// or if the trait is not defined in this crate.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/astencode.rs
Expand Up @@ -1228,7 +1228,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
var_id: var_id,
closure_expr_id: id
};
let upvar_capture = tcx.upvar_capture_map.borrow()[upvar_id].clone();
let upvar_capture = tcx.upvar_capture_map.borrow().get(&upvar_id).unwrap().clone();
var_id.encode(rbml_w);
upvar_capture.encode(rbml_w);
})
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/check_match.rs
Expand Up @@ -874,7 +874,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
}

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

ast::PatStruct(_, ref pattern_fields, _) => {
// Is this a struct or an enum variant?
let def = cx.tcx.def_map.borrow()[pat_id].full_def();
let def = cx.tcx.def_map.borrow().get(&pat_id).unwrap().full_def();
let class_id = match def {
DefConst(..) =>
cx.tcx.sess.span_bug(pat_span, "const pattern should've \
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/const_eval.rs
Expand Up @@ -150,7 +150,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<ast::Pat>
ast::PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr, span)).collect()),

ast::ExprCall(ref callee, ref args) => {
let def = tcx.def_map.borrow()[callee.id];
let def = *tcx.def_map.borrow().get(&callee.id).unwrap();
if let Vacant(entry) = tcx.def_map.borrow_mut().entry(expr.id) {
entry.insert(def);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/dead.rs
Expand Up @@ -158,7 +158,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {

fn handle_field_pattern_match(&mut self, lhs: &ast::Pat,
pats: &[codemap::Spanned<ast::FieldPat>]) {
let id = match self.tcx.def_map.borrow()[lhs.id].full_def() {
let id = match self.tcx.def_map.borrow().get(&lhs.id).unwrap().full_def() {
def::DefVariant(_, id, _) => id,
_ => {
match ty::ty_to_def_id(ty::node_id_to_type(self.tcx,
Expand Down Expand Up @@ -496,7 +496,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
None => (),
Some(impl_list) => {
for impl_did in &**impl_list {
for item_did in &(*impl_items)[*impl_did] {
for item_did in &*impl_items.get(impl_did).unwrap() {
if self.live_symbols.contains(&item_did.def_id()
.node) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/effect.rs
Expand Up @@ -141,7 +141,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
match expr.node {
ast::ExprMethodCall(_, _, _) => {
let method_call = MethodCall::expr(expr.id);
let base_type = (*self.tcx.method_map.borrow())[method_call].ty;
let base_type = self.tcx.method_map.borrow().get(&method_call).unwrap().ty;
debug!("effect: method call case, base type is {}",
ppaux::ty_to_string(self.tcx, base_type));
if type_is_unsafe_function(base_type) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/expr_use_visitor.rs
Expand Up @@ -1012,7 +1012,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {

// Each match binding is effectively an assignment to the
// binding being produced.
let def = def_map.borrow()[pat.id].full_def();
let def = def_map.borrow().get(&pat.id).unwrap().full_def();
match mc.cat_def(pat.id, pat.span, pat_ty, def) {
Ok(binding_cmt) => {
delegate.mutate(pat.id, pat.span, binding_cmt, Init);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/infer/region_inference/mod.rs
Expand Up @@ -1533,7 +1533,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
ConstrainVarSubReg(_, region) => {
state.result.push(RegionAndOrigin {
region: region,
origin: this.constraints.borrow()[edge.data].clone()
origin: this.constraints.borrow().get(&edge.data).unwrap().clone()
});
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/librustc/middle/liveness.rs
Expand Up @@ -448,7 +448,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
match expr.node {
// live nodes required for uses or definitions of variables:
ast::ExprPath(..) => {
let def = ir.tcx.def_map.borrow()[expr.id].full_def();
let def = ir.tcx.def_map.borrow().get(&expr.id).unwrap().full_def();
debug!("expr {}: path that leads to {:?}", expr.id, def);
if let DefLocal(..) = def {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
Expand Down Expand Up @@ -1302,7 +1302,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {

fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: u32)
-> LiveNode {
match self.ir.tcx.def_map.borrow()[expr.id].full_def() {
match self.ir.tcx.def_map.borrow().get(&expr.id).unwrap().full_def() {
DefLocal(nid) => {
let ln = self.live_node(expr.id, expr.span);
if acc != 0 {
Expand Down Expand Up @@ -1564,7 +1564,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn check_lvalue(&mut self, expr: &Expr) {
match expr.node {
ast::ExprPath(..) => {
if let DefLocal(nid) = self.ir.tcx.def_map.borrow()[expr.id].full_def() {
if let DefLocal(nid) = self.ir.tcx.def_map.borrow().get(&expr.id)
.unwrap()
.full_def() {
// Assignment to an immutable variable or argument: only legal
// if there is no later assignment. If this local is actually
// mutable, then check for a reassignment to flag the mutability
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/mem_categorization.rs
Expand Up @@ -531,7 +531,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/reachable.rs
Expand Up @@ -128,7 +128,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> {
}
ast::ExprMethodCall(..) => {
let method_call = ty::MethodCall::expr(expr.id);
match (*self.tcx.method_map.borrow())[method_call].origin {
match (*self.tcx.method_map.borrow()).get(&method_call).unwrap().origin {
ty::MethodStatic(def_id) => {
if is_local(def_id) {
if self.def_id_represents_local_inlined_item(def_id) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/stability.rs
Expand Up @@ -319,7 +319,7 @@ pub fn check_item(tcx: &ty::ctxt, item: &ast::Item, warn_about_defns: bool,
// individually as it's possible to have a stable trait with unstable
// items.
ast::ItemImpl(_, _, _, Some(ref t), _, ref impl_items) => {
let trait_did = tcx.def_map.borrow()[t.ref_id].def_id();
let trait_did = tcx.def_map.borrow().get(&t.ref_id).unwrap().def_id();
let trait_items = ty::trait_items(tcx, trait_did);

for impl_item in impl_items {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/traits/project.rs
Expand Up @@ -854,10 +854,10 @@ fn confirm_impl_candidate<'cx,'tcx>(
let impl_items_map = selcx.tcx().impl_items.borrow();
let impl_or_trait_items_map = selcx.tcx().impl_or_trait_items.borrow();

let impl_items = &impl_items_map[impl_vtable.impl_def_id];
let impl_items = impl_items_map.get(&impl_vtable.impl_def_id).unwrap();
let mut impl_ty = None;
for impl_item in impl_items {
let assoc_type = match impl_or_trait_items_map[impl_item.def_id()] {
let assoc_type = match *impl_or_trait_items_map.get(&impl_item.def_id()).unwrap() {
ty::TypeTraitItem(ref assoc_type) => assoc_type.clone(),
ty::MethodTraitItem(..) => { continue; }
};
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/ty.rs
Expand Up @@ -2667,22 +2667,22 @@ impl<'tcx> ctxt<'tcx> {
}

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

pub fn closure_type(&self,
def_id: ast::DefId,
substs: &subst::Substs<'tcx>)
-> ty::ClosureTy<'tcx>
{
self.closure_tys.borrow()[def_id].subst(self, substs)
self.closure_tys.borrow().get(&def_id).unwrap().subst(self, substs)
}

pub fn type_parameter_def(&self,
node_id: ast::NodeId)
-> TypeParameterDef<'tcx>
{
self.ty_param_defs.borrow()[node_id].clone()
self.ty_param_defs.borrow().get(&node_id).unwrap().clone()
}
}

Expand Down Expand Up @@ -6540,7 +6540,7 @@ impl<'tcx> ctxt<'tcx> {
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/move_data.rs
Expand Up @@ -486,7 +486,7 @@ impl<'tcx> MoveData<'tcx> {
match path.loan_path.kind {
LpVar(..) | LpUpvar(..) | LpDowncast(..) => {
let kill_scope = path.loan_path.kill_scope(tcx);
let path = self.path_map.borrow()[path.loan_path];
let path = *self.path_map.borrow().get(&path.loan_path).unwrap();
self.kill_moves(path, kill_scope.node_id(), dfcx_moves);
}
LpExtend(..) => {}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Expand Up @@ -418,7 +418,7 @@ struct ImproperCTypesVisitor<'a, 'tcx: 'a> {

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

0 comments on commit 8e58af4

Please sign in to comment.