1
Fork 0

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 `[]`.
This commit is contained in:
Niko Matsakis 2015-03-21 21:15:47 -04:00
parent b4d4daf007
commit 8e58af4004
57 changed files with 245 additions and 159 deletions

View file

@ -264,7 +264,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// Some(x) => *x = "b", /// Some(x) => *x = "b",
/// None => (), /// 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 // See `get` for implementation notes, this is basically a copy-paste with mut's added
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -326,7 +326,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// ///
/// map.insert(37, "b"); /// map.insert(37, "b");
/// assert_eq!(map.insert(37, "c"), Some("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")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn insert(&mut self, mut key: K, mut value: V) -> Option<V> { pub fn insert(&mut self, mut key: K, mut value: V) -> Option<V> {

View file

@ -1522,6 +1522,7 @@ macro_rules! node_slice_impl {
} }
/// Returns a sub-slice with elements starting with `min_key`. /// Returns a sub-slice with elements starting with `min_key`.
#[cfg(stage0)]
pub fn slice_from(self, min_key: &K) -> $NodeSlice<'a, K, V> { pub fn slice_from(self, min_key: &K) -> $NodeSlice<'a, K, V> {
// _______________ // _______________
// |_1_|_3_|_5_|_7_| // |_1_|_3_|_5_|_7_|
@ -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`. /// 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> { pub fn slice_to(self, max_key: &K) -> $NodeSlice<'a, K, V> {
// _______________ // _______________
// |_1_|_3_|_5_|_7_| // |_1_|_3_|_5_|_7_|
@ -1577,6 +1608,36 @@ macro_rules! node_slice_impl {
tail_is_edge: !pos_is_kv, 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> { impl<'a, K: 'a, V: 'a> $NodeSlice<'a, K, V> {

View file

@ -111,7 +111,7 @@ impl CStore {
} }
pub fn get_crate_data(&self, cnum: ast::CrateNum) -> Rc<crate_metadata> { 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 { pub fn get_crate_hash(&self, cnum: ast::CrateNum) -> Svh {

View file

@ -375,7 +375,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
match ecx.tcx.inherent_impls.borrow().get(&exp.def_id) { match ecx.tcx.inherent_impls.borrow().get(&exp.def_id) {
Some(implementations) => { Some(implementations) => {
for base_impl_did in &**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( let impl_item = ty::impl_or_trait_item(
ecx.tcx, ecx.tcx,
method_did.def_id()); method_did.def_id());
@ -1175,7 +1175,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
// We need to encode information about the default methods we // We need to encode information about the default methods we
// have inherited, so we drive this based on the impl structure. // have inherited, so we drive this based on the impl structure.
let impl_items = tcx.impl_items.borrow(); 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); add_to_index(item, rbml_w, index);
rbml_w.start_tag(tag_items_data_item); rbml_w.start_tag(tag_items_data_item);
@ -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> { impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
fn visit_item(&mut self, item: &ast::Item) { fn visit_item(&mut self, item: &ast::Item) {
if let ast::ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node { 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 // Load eagerly if this is an implementation of the Drop trait
// or if the trait is not defined in this crate. // or if the trait is not defined in this crate.

View file

@ -1228,7 +1228,7 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
var_id: var_id, var_id: var_id,
closure_expr_id: 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); var_id.encode(rbml_w);
upvar_capture.encode(rbml_w); upvar_capture.encode(rbml_w);
}) })

View file

@ -874,7 +874,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
} }
ast::PatEnum(_, ref args) => { 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 { match def {
DefConst(..) => DefConst(..) =>
cx.tcx.sess.span_bug(pat_span, "const pattern should've \ cx.tcx.sess.span_bug(pat_span, "const pattern should've \
@ -892,7 +892,7 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
ast::PatStruct(_, ref pattern_fields, _) => { ast::PatStruct(_, ref pattern_fields, _) => {
// Is this a struct or an enum variant? // 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 { let class_id = match def {
DefConst(..) => DefConst(..) =>
cx.tcx.sess.span_bug(pat_span, "const pattern should've \ cx.tcx.sess.span_bug(pat_span, "const pattern should've \

View file

@ -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::PatTup(exprs.iter().map(|expr| const_expr_to_pat(tcx, &**expr, span)).collect()),
ast::ExprCall(ref callee, ref args) => { 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) { if let Vacant(entry) = tcx.def_map.borrow_mut().entry(expr.id) {
entry.insert(def); entry.insert(def);
} }

View file

@ -158,7 +158,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
fn handle_field_pattern_match(&mut self, lhs: &ast::Pat, fn handle_field_pattern_match(&mut self, lhs: &ast::Pat,
pats: &[codemap::Spanned<ast::FieldPat>]) { 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, def::DefVariant(_, id, _) => id,
_ => { _ => {
match ty::ty_to_def_id(ty::node_id_to_type(self.tcx, match ty::ty_to_def_id(ty::node_id_to_type(self.tcx,
@ -496,7 +496,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
None => (), None => (),
Some(impl_list) => { Some(impl_list) => {
for impl_did in &**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() if self.live_symbols.contains(&item_did.def_id()
.node) { .node) {
return true; return true;

View file

@ -141,7 +141,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
match expr.node { match expr.node {
ast::ExprMethodCall(_, _, _) => { ast::ExprMethodCall(_, _, _) => {
let method_call = MethodCall::expr(expr.id); 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 {}", debug!("effect: method call case, base type is {}",
ppaux::ty_to_string(self.tcx, base_type)); ppaux::ty_to_string(self.tcx, base_type));
if type_is_unsafe_function(base_type) { if type_is_unsafe_function(base_type) {

View file

@ -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 // Each match binding is effectively an assignment to the
// binding being produced. // 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) { match mc.cat_def(pat.id, pat.span, pat_ty, def) {
Ok(binding_cmt) => { Ok(binding_cmt) => {
delegate.mutate(pat.id, pat.span, binding_cmt, Init); delegate.mutate(pat.id, pat.span, binding_cmt, Init);

View file

@ -1533,7 +1533,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
ConstrainVarSubReg(_, region) => { ConstrainVarSubReg(_, region) => {
state.result.push(RegionAndOrigin { state.result.push(RegionAndOrigin {
region: region, region: region,
origin: this.constraints.borrow()[edge.data].clone() origin: this.constraints.borrow().get(&edge.data).unwrap().clone()
}); });
} }
} }

View file

@ -448,7 +448,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
match expr.node { match expr.node {
// live nodes required for uses or definitions of variables: // live nodes required for uses or definitions of variables:
ast::ExprPath(..) => { 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); debug!("expr {}: path that leads to {:?}", expr.id, def);
if let DefLocal(..) = def { if let DefLocal(..) = def {
ir.add_live_node_for_node(expr.id, ExprNode(expr.span)); ir.add_live_node_for_node(expr.id, ExprNode(expr.span));
@ -1302,7 +1302,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: u32) fn access_path(&mut self, expr: &Expr, succ: LiveNode, acc: u32)
-> LiveNode { -> 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) => { DefLocal(nid) => {
let ln = self.live_node(expr.id, expr.span); let ln = self.live_node(expr.id, expr.span);
if acc != 0 { if acc != 0 {
@ -1564,7 +1564,9 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
fn check_lvalue(&mut self, expr: &Expr) { fn check_lvalue(&mut self, expr: &Expr) {
match expr.node { match expr.node {
ast::ExprPath(..) => { 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 // Assignment to an immutable variable or argument: only legal
// if there is no later assignment. If this local is actually // if there is no later assignment. If this local is actually
// mutable, then check for a reassignment to flag the mutability // mutable, then check for a reassignment to flag the mutability

View file

@ -531,7 +531,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
} }
ast::ExprPath(..) => { 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) self.cat_def(expr.id, expr.span, expr_ty, def)
} }

View file

@ -128,7 +128,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ReachableContext<'a, 'tcx> {
} }
ast::ExprMethodCall(..) => { ast::ExprMethodCall(..) => {
let method_call = ty::MethodCall::expr(expr.id); 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) => { ty::MethodStatic(def_id) => {
if is_local(def_id) { if is_local(def_id) {
if self.def_id_represents_local_inlined_item(def_id) { if self.def_id_represents_local_inlined_item(def_id) {

View file

@ -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 // individually as it's possible to have a stable trait with unstable
// items. // items.
ast::ItemImpl(_, _, _, Some(ref t), _, ref impl_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); let trait_items = ty::trait_items(tcx, trait_did);
for impl_item in impl_items { for impl_item in impl_items {

View file

@ -854,10 +854,10 @@ fn confirm_impl_candidate<'cx,'tcx>(
let impl_items_map = selcx.tcx().impl_items.borrow(); let impl_items_map = selcx.tcx().impl_items.borrow();
let impl_or_trait_items_map = selcx.tcx().impl_or_trait_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; let mut impl_ty = None;
for impl_item in impl_items { 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::TypeTraitItem(ref assoc_type) => assoc_type.clone(),
ty::MethodTraitItem(..) => { continue; } ty::MethodTraitItem(..) => { continue; }
}; };

View file

@ -2667,7 +2667,7 @@ impl<'tcx> ctxt<'tcx> {
} }
pub fn closure_kind(&self, def_id: ast::DefId) -> ty::ClosureKind { 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, pub fn closure_type(&self,
@ -2675,14 +2675,14 @@ impl<'tcx> ctxt<'tcx> {
substs: &subst::Substs<'tcx>) substs: &subst::Substs<'tcx>)
-> ty::ClosureTy<'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, pub fn type_parameter_def(&self,
node_id: ast::NodeId) node_id: ast::NodeId)
-> TypeParameterDef<'tcx> -> TypeParameterDef<'tcx>
{ {
self.ty_param_defs.borrow()[node_id].clone() self.ty_param_defs.borrow().get(&node_id).unwrap().clone()
} }
} }
@ -6540,7 +6540,7 @@ impl<'tcx> ctxt<'tcx> {
} }
pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> { 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())
} }
} }

View file

@ -486,7 +486,7 @@ impl<'tcx> MoveData<'tcx> {
match path.loan_path.kind { match path.loan_path.kind {
LpVar(..) | LpUpvar(..) | LpDowncast(..) => { LpVar(..) | LpUpvar(..) | LpDowncast(..) => {
let kill_scope = path.loan_path.kill_scope(tcx); 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); self.kill_moves(path, kill_scope.node_id(), dfcx_moves);
} }
LpExtend(..) => {} LpExtend(..) => {}

View file

@ -418,7 +418,7 @@ struct ImproperCTypesVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_def(&mut self, sp: Span, id: ast::NodeId) { 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(_))) => { def::DefPrimTy(ast::TyInt(ast::TyIs(_))) => {
self.cx.span_lint(IMPROPER_CTYPES, sp, self.cx.span_lint(IMPROPER_CTYPES, sp,
"found rust type `isize` in foreign module, while \ "found rust type `isize` in foreign module, while \

View file

@ -253,7 +253,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
ast::ItemImpl(_, _, _, _, ref ty, ref impl_items) => { ast::ItemImpl(_, _, _, _, ref ty, ref impl_items) => {
let public_ty = match ty.node { let public_ty = match ty.node {
ast::TyPath(..) => { ast::TyPath(..) => {
match self.tcx.def_map.borrow()[ty.id].full_def() { match self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def() {
def::DefPrimTy(..) => true, def::DefPrimTy(..) => true,
def => { def => {
let did = def.def_id(); let did = def.def_id();
@ -317,7 +317,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
ast::ItemTy(ref ty, _) if public_first => { ast::ItemTy(ref ty, _) if public_first => {
if let ast::TyPath(..) = ty.node { if let ast::TyPath(..) = ty.node {
match self.tcx.def_map.borrow()[ty.id].full_def() { match self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def() {
def::DefPrimTy(..) | def::DefTyParam(..) => {}, def::DefPrimTy(..) | def::DefTyParam(..) => {},
def => { def => {
let did = def.def_id(); let did = def.def_id();
@ -349,7 +349,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
// crate module gets processed as well. // crate module gets processed as well.
if self.prev_exported { if self.prev_exported {
assert!(self.export_map.contains_key(&id), "wut {}", id); assert!(self.export_map.contains_key(&id), "wut {}", id);
for export in &self.export_map[id] { for export in self.export_map.get(&id).unwrap() {
if is_local(export.def_id) { if is_local(export.def_id) {
self.reexports.insert(export.def_id.node); self.reexports.insert(export.def_id.node);
} }
@ -525,7 +525,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
// if we've reached the root, then everything was allowable and this // if we've reached the root, then everything was allowable and this
// access is public. // access is public.
if closest_private_id == ast::CRATE_NODE_ID { return Allowable } if closest_private_id == ast::CRATE_NODE_ID { return Allowable }
closest_private_id = self.parents[closest_private_id]; closest_private_id = *self.parents.get(&closest_private_id).unwrap();
// If we reached the top, then we were public all the way down and // If we reached the top, then we were public all the way down and
// we can allow this access. // we can allow this access.
@ -543,7 +543,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
/// whether the node is accessible by the current module that iteration is /// whether the node is accessible by the current module that iteration is
/// inside. /// inside.
fn private_accessible(&self, id: ast::NodeId) -> bool { fn private_accessible(&self, id: ast::NodeId) -> bool {
let parent = self.parents[id]; let parent = *self.parents.get(&id).unwrap();
debug!("privacy - accessible parent {}", self.nodestr(parent)); debug!("privacy - accessible parent {}", self.nodestr(parent));
// After finding `did`'s closest private member, we roll ourselves back // After finding `did`'s closest private member, we roll ourselves back
@ -567,7 +567,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
_ => {} _ => {}
} }
cur = self.parents[cur]; cur = *self.parents.get(&cur).unwrap();
} }
} }
@ -622,7 +622,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
ast::TyPath(..) => {} ast::TyPath(..) => {}
_ => return Some((err_span, err_msg, None)), _ => return Some((err_span, err_msg, None)),
}; };
let def = self.tcx.def_map.borrow()[ty.id].full_def(); let def = self.tcx.def_map.borrow().get(&ty.id).unwrap().full_def();
let did = def.def_id(); let did = def.def_id();
assert!(is_local(did)); assert!(is_local(did));
match self.tcx.map.get(did.node) { match self.tcx.map.get(did.node) {
@ -708,7 +708,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
// Checks that a path is in scope. // Checks that a path is in scope.
fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Ident) { fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Ident) {
debug!("privacy - path {}", self.nodestr(path_id)); debug!("privacy - path {}", self.nodestr(path_id));
let path_res = self.tcx.def_map.borrow()[path_id]; let path_res = *self.tcx.def_map.borrow().get(&path_id).unwrap();
let ck = |tyname: &str| { let ck = |tyname: &str| {
let ck_public = |def: ast::DefId| { let ck_public = |def: ast::DefId| {
debug!("privacy - ck_public {:?}", def); debug!("privacy - ck_public {:?}", def);
@ -881,7 +881,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
} }
} }
ty::ty_enum(_, _) => { ty::ty_enum(_, _) => {
match self.tcx.def_map.borrow()[expr.id].full_def() { match self.tcx.def_map.borrow().get(&expr.id).unwrap().full_def() {
def::DefVariant(_, variant_id, _) => { def::DefVariant(_, variant_id, _) => {
for field in fields { for field in fields {
self.check_field(expr.span, variant_id, self.check_field(expr.span, variant_id,

View file

@ -1141,9 +1141,9 @@ fn add_upstream_rust_crates(cmd: &mut Command, sess: &Session,
// involves just passing the right -l flag. // involves just passing the right -l flag.
let data = if dylib { let data = if dylib {
&trans.crate_formats[config::CrateTypeDylib] trans.crate_formats.get(&config::CrateTypeDylib).unwrap()
} else { } else {
&trans.crate_formats[config::CrateTypeExecutable] trans.crate_formats.get(&config::CrateTypeExecutable).unwrap()
}; };
// Invoke get_used_crates to ensure that we get a topological sorting of // Invoke get_used_crates to ensure that we get a topological sorting of

View file

@ -219,7 +219,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
self.sess.bug(&format!("def_map has no key for {} in lookup_type_ref", self.sess.bug(&format!("def_map has no key for {} in lookup_type_ref",
ref_id)); ref_id));
} }
let def = self.analysis.ty_cx.def_map.borrow()[ref_id].full_def(); let def = self.analysis.ty_cx.def_map.borrow().get(&ref_id).unwrap().full_def();
match def { match def {
def::DefPrimTy(_) => None, def::DefPrimTy(_) => None,
_ => Some(def.def_id()), _ => Some(def.def_id()),
@ -232,7 +232,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
self.sess.span_bug(span, &format!("def_map has no key for {} in lookup_def_kind", self.sess.span_bug(span, &format!("def_map has no key for {} in lookup_def_kind",
ref_id)); ref_id));
} }
let def = def_map[ref_id].full_def(); let def = def_map.get(&ref_id).unwrap().full_def();
match def { match def {
def::DefMod(_) | def::DefMod(_) |
def::DefForeignMod(_) => Some(recorder::ModRef), def::DefForeignMod(_) => Some(recorder::ModRef),
@ -269,8 +269,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
self.collecting = false; self.collecting = false;
let span_utils = self.span.clone(); let span_utils = self.span.clone();
for &(id, ref p, _, _) in &self.collected_paths { for &(id, ref p, _, _) in &self.collected_paths {
let typ = ppaux::ty_to_string(&self.analysis.ty_cx, let typ =
(*self.analysis.ty_cx.node_types.borrow())[id]); ppaux::ty_to_string(
&self.analysis.ty_cx,
*self.analysis.ty_cx.node_types.borrow().get(&id).unwrap());
// get the span only for the name of the variable (I hope the path is only ever a // get the span only for the name of the variable (I hope the path is only ever a
// variable name, but who knows?) // variable name, but who knows?)
self.fmt.formal_str(p.span, self.fmt.formal_str(p.span,
@ -431,8 +433,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
ast::NamedField(ident, _) => { ast::NamedField(ident, _) => {
let name = get_ident(ident); let name = get_ident(ident);
let qualname = format!("{}::{}", qualname, name); let qualname = format!("{}::{}", qualname, name);
let typ = ppaux::ty_to_string(&self.analysis.ty_cx, let typ =
(*self.analysis.ty_cx.node_types.borrow())[field.node.id]); ppaux::ty_to_string(
&self.analysis.ty_cx,
*self.analysis.ty_cx.node_types.borrow().get(&field.node.id).unwrap());
match self.span.sub_span_before_token(field.span, token::Colon) { match self.span.sub_span_before_token(field.span, token::Colon) {
Some(sub_span) => self.fmt.field_str(field.span, Some(sub_span) => self.fmt.field_str(field.span,
Some(sub_span), Some(sub_span),
@ -789,7 +793,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
self.sess.span_bug(span, self.sess.span_bug(span,
&format!("def_map has no key for {} in visit_expr", id)); &format!("def_map has no key for {} in visit_expr", id));
} }
let def = def_map[id].full_def(); let def = def_map.get(&id).unwrap().full_def();
let sub_span = self.span.span_for_last_ident(span); let sub_span = self.span.span_for_last_ident(span);
match def { match def {
def::DefUpvar(..) | def::DefUpvar(..) |
@ -832,7 +836,8 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
.ty_cx .ty_cx
.impl_items .impl_items
.borrow(); .borrow();
Some((*impl_items)[def_id] Some(impl_items.get(&def_id)
.unwrap()
.iter() .iter()
.find(|mr| { .find(|mr| {
ty::impl_or_trait_item( ty::impl_or_trait_item(
@ -941,7 +946,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
ex: &ast::Expr, ex: &ast::Expr,
args: &Vec<P<ast::Expr>>) { args: &Vec<P<ast::Expr>>) {
let method_map = self.analysis.ty_cx.method_map.borrow(); let method_map = self.analysis.ty_cx.method_map.borrow();
let method_callee = &(*method_map)[ty::MethodCall::expr(ex.id)]; let method_callee = method_map.get(&ty::MethodCall::expr(ex.id)).unwrap();
let (def_id, decl_id) = match method_callee.origin { let (def_id, decl_id) = match method_callee.origin {
ty::MethodStatic(def_id) | ty::MethodStatic(def_id) |
ty::MethodStaticClosure(def_id) => { ty::MethodStaticClosure(def_id) => {
@ -1001,7 +1006,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
self.collected_paths.push((p.id, path.clone(), false, recorder::StructRef)); self.collected_paths.push((p.id, path.clone(), false, recorder::StructRef));
visit::walk_path(self, path); visit::walk_path(self, path);
let def = self.analysis.ty_cx.def_map.borrow()[p.id].full_def(); let def = self.analysis.ty_cx.def_map.borrow().get(&p.id).unwrap().full_def();
let struct_def = match def { let struct_def = match def {
def::DefConst(..) => None, def::DefConst(..) => None,
def::DefVariant(_, variant_id, _) => Some(variant_id), def::DefVariant(_, variant_id, _) => Some(variant_id),
@ -1113,7 +1118,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
let glob_map = &self.analysis.glob_map; let glob_map = &self.analysis.glob_map;
let glob_map = glob_map.as_ref().unwrap(); let glob_map = glob_map.as_ref().unwrap();
if glob_map.contains_key(&item.id) { if glob_map.contains_key(&item.id) {
for n in &glob_map[item.id] { for n in glob_map.get(&item.id).unwrap() {
if name_string.len() > 0 { if name_string.len() > 0 {
name_string.push_str(", "); name_string.push_str(", ");
} }
@ -1406,7 +1411,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
&format!("def_map has no key for {} in visit_arm", &format!("def_map has no key for {} in visit_arm",
id)); id));
} }
let def = def_map[id].full_def(); let def = def_map.get(&id).unwrap().full_def();
match def { match def {
def::DefLocal(id) => { def::DefLocal(id) => {
let value = if *immut { let value = if *immut {
@ -1467,7 +1472,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
for &(id, ref p, ref immut, _) in &self.collected_paths { for &(id, ref p, ref immut, _) in &self.collected_paths {
let value = if *immut { value.to_string() } else { "<mutable>".to_string() }; let value = if *immut { value.to_string() } else { "<mutable>".to_string() };
let types = self.analysis.ty_cx.node_types.borrow(); let types = self.analysis.ty_cx.node_types.borrow();
let typ = ppaux::ty_to_string(&self.analysis.ty_cx, (*types)[id]); let typ = ppaux::ty_to_string(&self.analysis.ty_cx, *types.get(&id).unwrap());
// Get the span only for the name of the variable (I hope the path // Get the span only for the name of the variable (I hope the path
// is only ever a variable name, but who knows?). // is only ever a variable name, but who knows?).
let sub_span = self.span.span_for_last_ident(p.span); let sub_span = self.span.span_for_last_ident(p.span);

View file

@ -1017,7 +1017,7 @@ fn compile_submatch<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
None => { None => {
let data = &m[0].data; let data = &m[0].data;
for &(ref ident, ref value_ptr) in &m[0].bound_ptrs { for &(ref ident, ref value_ptr) in &m[0].bound_ptrs {
let binfo = data.bindings_map[*ident]; let binfo = *data.bindings_map.get(ident).unwrap();
call_lifetime_start(bcx, binfo.llmatch); call_lifetime_start(bcx, binfo.llmatch);
if binfo.trmode == TrByRef && type_is_fat_ptr(bcx.tcx(), binfo.ty) { if binfo.trmode == TrByRef && type_is_fat_ptr(bcx.tcx(), binfo.ty) {
expr::copy_fat_ptr(bcx, *value_ptr, binfo.llmatch); expr::copy_fat_ptr(bcx, *value_ptr, binfo.llmatch);

View file

@ -269,7 +269,7 @@ pub fn self_type_for_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
} }
pub fn kind_for_closure(ccx: &CrateContext, closure_id: ast::DefId) -> ty::ClosureKind { pub fn kind_for_closure(ccx: &CrateContext, closure_id: ast::DefId) -> ty::ClosureKind {
ccx.tcx().closure_kinds.borrow()[closure_id] *ccx.tcx().closure_kinds.borrow().get(&closure_id).unwrap()
} }
pub fn decl_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, pub fn decl_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
@ -2322,7 +2322,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
static"); static");
} }
let v = ccx.static_values().borrow()[item.id].clone(); let v = ccx.static_values().borrow().get(&item.id).unwrap().clone();
unsafe { unsafe {
if !(llvm::LLVMConstIntGetZExtValue(v) != 0) { if !(llvm::LLVMConstIntGetZExtValue(v) != 0) {
ccx.sess().span_fatal(expr.span, "static assertion failed"); ccx.sess().span_fatal(expr.span, "static assertion failed");

View file

@ -511,7 +511,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
let ref_ty = match node { let ref_ty = match node {
ExprId(id) => ty::node_id_to_type(tcx, id), ExprId(id) => ty::node_id_to_type(tcx, id),
MethodCallKey(method_call) => { MethodCallKey(method_call) => {
(*tcx.method_map.borrow())[method_call].ty tcx.method_map.borrow().get(&method_call).unwrap().ty
} }
}; };
let ref_ty = monomorphize::apply_param_substs(tcx, let ref_ty = monomorphize::apply_param_substs(tcx,

View file

@ -709,7 +709,7 @@ impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> {
} }
fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> { fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
Some(self.tcx().upvar_capture_map.borrow()[upvar_id].clone()) Some(self.tcx().upvar_capture_map.borrow().get(&upvar_id).unwrap().clone())
} }
fn type_moves_by_default(&self, span: Span, ty: Ty<'tcx>) -> bool { fn type_moves_by_default(&self, span: Span, ty: Ty<'tcx>) -> bool {
@ -1213,7 +1213,7 @@ pub fn node_id_substs<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ty::node_id_item_substs(tcx, id).substs ty::node_id_item_substs(tcx, id).substs
} }
MethodCallKey(method_call) => { MethodCallKey(method_call) => {
(*tcx.method_map.borrow())[method_call].substs.clone() tcx.method_map.borrow().get(&method_call).unwrap().substs.clone()
} }
}; };

View file

@ -187,7 +187,7 @@ pub fn get_const_expr_as_global<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// Special-case constants to cache a common global for all uses. // Special-case constants to cache a common global for all uses.
match expr.node { match expr.node {
ast::ExprPath(..) => { ast::ExprPath(..) => {
let def = ccx.tcx().def_map.borrow()[expr.id].full_def(); let def = ccx.tcx().def_map.borrow().get(&expr.id).unwrap().full_def();
match def { match def {
def::DefConst(def_id) => { def::DefConst(def_id) => {
if !ccx.tcx().adjustments.borrow().contains_key(&expr.id) { if !ccx.tcx().adjustments.borrow().contains_key(&expr.id) {
@ -665,7 +665,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
} }
} }
ast::ExprPath(..) => { ast::ExprPath(..) => {
let def = cx.tcx().def_map.borrow()[e.id].full_def(); let def = cx.tcx().def_map.borrow().get(&e.id).unwrap().full_def();
match def { match def {
def::DefFn(..) | def::DefMethod(..) => { def::DefFn(..) | def::DefMethod(..) => {
expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val
@ -751,7 +751,7 @@ pub fn trans_static(ccx: &CrateContext, m: ast::Mutability, id: ast::NodeId) {
let g = base::get_item_val(ccx, id); let g = base::get_item_val(ccx, id);
// At this point, get_item_val has already translated the // At this point, get_item_val has already translated the
// constant's initializer to determine its LLVM type. // constant's initializer to determine its LLVM type.
let v = ccx.static_values().borrow()[id].clone(); let v = ccx.static_values().borrow().get(&id).unwrap().clone();
// boolean SSA values are i1, but they have to be stored in i8 slots, // boolean SSA values are i1, but they have to be stored in i8 slots,
// otherwise some LLVM optimization passes don't work as expected // otherwise some LLVM optimization passes don't work as expected
let v = if llvm::LLVMTypeOf(v) == Type::i1(ccx).to_ref() { let v = if llvm::LLVMTypeOf(v) == Type::i1(ccx).to_ref() {

View file

@ -126,7 +126,7 @@ pub fn trans_into<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
return datum.store_to_dest(bcx, dest, expr.id); return datum.store_to_dest(bcx, dest, expr.id);
} }
let qualif = bcx.tcx().const_qualif_map.borrow()[expr.id]; let qualif = *bcx.tcx().const_qualif_map.borrow().get(&expr.id).unwrap();
if !qualif.intersects(check_const::NOT_CONST | check_const::NEEDS_DROP) { if !qualif.intersects(check_const::NOT_CONST | check_const::NEEDS_DROP) {
if !qualif.intersects(check_const::PREFER_IN_PLACE) { if !qualif.intersects(check_const::PREFER_IN_PLACE) {
if let SaveIn(lldest) = dest { if let SaveIn(lldest) = dest {
@ -209,7 +209,7 @@ pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let mut bcx = bcx; let mut bcx = bcx;
let fcx = bcx.fcx; let fcx = bcx.fcx;
let qualif = bcx.tcx().const_qualif_map.borrow()[expr.id]; let qualif = *bcx.tcx().const_qualif_map.borrow().get(&expr.id).unwrap();
let adjusted_global = !qualif.intersects(check_const::NON_STATIC_BORROWS); let adjusted_global = !qualif.intersects(check_const::NON_STATIC_BORROWS);
let global = if !qualif.intersects(check_const::NOT_CONST | check_const::NEEDS_DROP) { let global = if !qualif.intersects(check_const::NOT_CONST | check_const::NEEDS_DROP) {
let global = consts::get_const_expr_as_global(bcx.ccx(), expr, qualif, let global = consts::get_const_expr_as_global(bcx.ccx(), expr, qualif,
@ -1405,7 +1405,7 @@ pub fn with_field_tys<'tcx, R, F>(tcx: &ty::ctxt<'tcx>,
ty.repr(tcx))); ty.repr(tcx)));
} }
Some(node_id) => { Some(node_id) => {
let def = tcx.def_map.borrow()[node_id].full_def(); let def = tcx.def_map.borrow().get(&node_id).unwrap().full_def();
match def { match def {
def::DefVariant(enum_id, variant_id, _) => { def::DefVariant(enum_id, variant_id, _) => {
let variant_info = ty::enum_variant_with_id(tcx, enum_id, variant_id); let variant_info = ty::enum_variant_with_id(tcx, enum_id, variant_id);
@ -1961,7 +1961,7 @@ fn trans_overloaded_op<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
dest: Option<Dest>, dest: Option<Dest>,
autoref: bool) autoref: bool)
-> Result<'blk, 'tcx> { -> Result<'blk, 'tcx> {
let method_ty = (*bcx.tcx().method_map.borrow())[method_call].ty; let method_ty = bcx.tcx().method_map.borrow().get(&method_call).unwrap().ty;
callee::trans_call_inner(bcx, callee::trans_call_inner(bcx,
expr.debug_loc(), expr.debug_loc(),
monomorphize_type(bcx, method_ty), monomorphize_type(bcx, method_ty),
@ -1982,9 +1982,11 @@ fn trans_overloaded_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
dest: Option<Dest>) dest: Option<Dest>)
-> Block<'blk, 'tcx> { -> Block<'blk, 'tcx> {
let method_call = MethodCall::expr(expr.id); let method_call = MethodCall::expr(expr.id);
let method_type = (*bcx.tcx() let method_type = bcx.tcx()
.method_map .method_map
.borrow())[method_call] .borrow()
.get(&method_call)
.unwrap()
.ty; .ty;
let mut all_args = vec!(callee); let mut all_args = vec!(callee);
all_args.extend(args.iter().map(|e| &**e)); all_args.extend(args.iter().map(|e| &**e));

View file

@ -1046,7 +1046,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
return (tcx.types.err, ty_path_def); return (tcx.types.err, ty_path_def);
}; };
let ty_param_name = tcx.ty_param_defs.borrow()[ty_param_node_id].name; let ty_param_name = tcx.ty_param_defs.borrow().get(&ty_param_node_id).unwrap().name;
let bounds = match this.get_type_parameter_bounds(span, ty_param_node_id) { let bounds = match this.get_type_parameter_bounds(span, ty_param_node_id) {
Ok(v) => v, Ok(v) => v,

View file

@ -119,7 +119,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
demand::eqtype(fcx, pat.span, expected, lhs_ty); demand::eqtype(fcx, pat.span, expected, lhs_ty);
} }
ast::PatEnum(..) | ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => { ast::PatEnum(..) | ast::PatIdent(..) if pat_is_const(&tcx.def_map, pat) => {
let const_did = tcx.def_map.borrow()[pat.id].def_id(); let const_did = tcx.def_map.borrow().get(&pat.id).unwrap().def_id();
let const_scheme = ty::lookup_item_type(tcx, const_did); let const_scheme = ty::lookup_item_type(tcx, const_did);
assert!(const_scheme.generics.is_empty()); assert!(const_scheme.generics.is_empty());
let const_ty = pcx.fcx.instantiate_type_scheme(pat.span, let const_ty = pcx.fcx.instantiate_type_scheme(pat.span,
@ -163,7 +163,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
// if there are multiple arms, make sure they all agree on // if there are multiple arms, make sure they all agree on
// what the type of the binding `x` ought to be // what the type of the binding `x` ought to be
let canon_id = pcx.map[path.node]; let canon_id = *pcx.map.get(&path.node).unwrap();
if canon_id != pat.id { if canon_id != pat.id {
let ct = fcx.local_ty(pat.span, canon_id); let ct = fcx.local_ty(pat.span, canon_id);
demand::eqtype(fcx, pat.span, ct, typ); demand::eqtype(fcx, pat.span, ct, typ);
@ -449,7 +449,7 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx ast::Pat,
let fcx = pcx.fcx; let fcx = pcx.fcx;
let tcx = pcx.fcx.ccx.tcx; let tcx = pcx.fcx.ccx.tcx;
let def = tcx.def_map.borrow()[pat.id].full_def(); let def = tcx.def_map.borrow().get(&pat.id).unwrap().full_def();
let (enum_def_id, variant_def_id) = match def { let (enum_def_id, variant_def_id) = match def {
def::DefTrait(_) => { def::DefTrait(_) => {
let name = pprust::path_to_string(path); let name = pprust::path_to_string(path);
@ -518,7 +518,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
let fcx = pcx.fcx; let fcx = pcx.fcx;
let tcx = pcx.fcx.ccx.tcx; let tcx = pcx.fcx.ccx.tcx;
let def = tcx.def_map.borrow()[pat.id].full_def(); let def = tcx.def_map.borrow().get(&pat.id).unwrap().full_def();
let enum_def = def.variant_def_ids() let enum_def = def.variant_def_ids()
.map_or_else(|| def.def_id(), |(enum_def, _)| enum_def); .map_or_else(|| def.def_id(), |(enum_def, _)| enum_def);

View file

@ -368,7 +368,7 @@ impl<'a, 'tcx> ty::ClosureTyper<'tcx> for FnCtxt<'a, 'tcx> {
substs: &subst::Substs<'tcx>) substs: &subst::Substs<'tcx>)
-> ty::ClosureTy<'tcx> -> ty::ClosureTy<'tcx>
{ {
self.inh.closure_tys.borrow()[def_id].subst(self.tcx(), substs) self.inh.closure_tys.borrow().get(&def_id).unwrap().subst(self.tcx(), substs)
} }
fn closure_upvars(&self, fn closure_upvars(&self,
@ -549,7 +549,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
debug!("Local variable {} is assigned type {}", debug!("Local variable {} is assigned type {}",
self.fcx.pat_to_string(&*local.pat), self.fcx.pat_to_string(&*local.pat),
self.fcx.infcx().ty_to_string( self.fcx.infcx().ty_to_string(
self.fcx.inh.locals.borrow()[local.id].clone())); self.fcx.inh.locals.borrow().get(&local.id).unwrap().clone()));
visit::walk_local(self, local); visit::walk_local(self, local);
} }
@ -565,7 +565,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
debug!("Pattern binding {} is assigned to {} with type {}", debug!("Pattern binding {} is assigned to {} with type {}",
token::get_ident(path1.node), token::get_ident(path1.node),
self.fcx.infcx().ty_to_string( self.fcx.infcx().ty_to_string(
self.fcx.inh.locals.borrow()[p.id].clone()), self.fcx.inh.locals.borrow().get(&p.id).unwrap().clone()),
var_ty.repr(self.fcx.tcx())); var_ty.repr(self.fcx.tcx()));
} }
} }
@ -3327,7 +3327,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
let mut missing_fields = Vec::new(); let mut missing_fields = Vec::new();
for class_field in field_types { for class_field in field_types {
let name = class_field.name; let name = class_field.name;
let (_, seen) = class_field_map[name]; let (_, seen) = *class_field_map.get(&name).unwrap();
if !seen { if !seen {
missing_fields.push( missing_fields.push(
format!("`{}`", &token::get_name(name))) format!("`{}`", &token::get_name(name)))
@ -4428,7 +4428,7 @@ fn check_const<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
let inh = static_inherited_fields(ccx); let inh = static_inherited_fields(ccx);
let rty = ty::node_id_to_type(ccx.tcx, id); let rty = ty::node_id_to_type(ccx.tcx, id);
let fcx = blank_fn_ctxt(ccx, &inh, ty::FnConverging(rty), e.id); let fcx = blank_fn_ctxt(ccx, &inh, ty::FnConverging(rty), e.id);
let declty = (*fcx.ccx.tcx.tcache.borrow())[local_def(id)].ty; let declty = fcx.ccx.tcx.tcache.borrow().get(&local_def(id)).unwrap().ty;
check_const_with_ty(&fcx, sp, e, declty); check_const_with_ty(&fcx, sp, e, declty);
} }

View file

@ -448,7 +448,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
let closure_def_id = ast_util::local_def(closure_id); let closure_def_id = ast_util::local_def(closure_id);
let mut closure_kinds = self.fcx.inh.closure_kinds.borrow_mut(); let mut closure_kinds = self.fcx.inh.closure_kinds.borrow_mut();
let existing_kind = closure_kinds[closure_def_id]; let existing_kind = *closure_kinds.get(&closure_def_id).unwrap();
debug!("adjust_closure_kind: closure_id={}, existing_kind={:?}, new_kind={:?}", debug!("adjust_closure_kind: closure_id={}, existing_kind={:?}, new_kind={:?}",
closure_id, existing_kind, new_kind); closure_id, existing_kind, new_kind);

View file

@ -269,7 +269,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
fn get_self_type_for_implementation(&self, impl_did: DefId) fn get_self_type_for_implementation(&self, impl_did: DefId)
-> TypeScheme<'tcx> { -> TypeScheme<'tcx> {
self.crate_context.tcx.tcache.borrow()[impl_did].clone() self.crate_context.tcx.tcache.borrow().get(&impl_did).unwrap().clone()
} }
// Converts an implementation in the AST to a vector of items. // Converts an implementation in the AST to a vector of items.
@ -387,7 +387,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
}; };
for &impl_did in &*trait_impls.borrow() { for &impl_did in &*trait_impls.borrow() {
let items = &(*impl_items)[impl_did]; let items = impl_items.get(&impl_did).unwrap();
if items.len() < 1 { if items.len() < 1 {
// We'll error out later. For now, just don't ICE. // We'll error out later. For now, just don't ICE.
continue; continue;

View file

@ -194,7 +194,7 @@ impl<'a,'tcx> CrateCtxt<'a,'tcx> {
fn method_ty(&self, method_id: ast::NodeId) -> Rc<ty::Method<'tcx>> { fn method_ty(&self, method_id: ast::NodeId) -> Rc<ty::Method<'tcx>> {
let def_id = local_def(method_id); let def_id = local_def(method_id);
match self.tcx.impl_or_trait_items.borrow()[def_id] { match *self.tcx.impl_or_trait_items.borrow().get(&def_id).unwrap() {
ty::MethodTraitItem(ref mty) => mty.clone(), ty::MethodTraitItem(ref mty) => mty.clone(),
ty::TypeTraitItem(..) => { ty::TypeTraitItem(..) => {
self.tcx.sess.bug(&format!("method with id {} has the wrong type", method_id)); self.tcx.sess.bug(&format!("method with id {} has the wrong type", method_id));
@ -545,7 +545,7 @@ fn is_param<'tcx>(tcx: &ty::ctxt<'tcx>,
-> bool -> bool
{ {
if let ast::TyPath(None, _) = ast_ty.node { if let ast::TyPath(None, _) = ast_ty.node {
let path_res = tcx.def_map.borrow()[ast_ty.id]; let path_res = *tcx.def_map.borrow().get(&ast_ty.id).unwrap();
match path_res.base_def { match path_res.base_def {
def::DefSelfTy(node_id) => def::DefSelfTy(node_id) =>
path_res.depth == 0 && node_id == param_id, path_res.depth == 0 && node_id == param_id,
@ -1040,9 +1040,13 @@ fn convert_struct<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
tcx.predicates.borrow_mut().insert(local_def(ctor_id), predicates); tcx.predicates.borrow_mut().insert(local_def(ctor_id), predicates);
} else if struct_def.fields[0].node.kind.is_unnamed() { } else if struct_def.fields[0].node.kind.is_unnamed() {
// Tuple-like. // Tuple-like.
let inputs: Vec<_> = struct_def.fields.iter().map( let inputs: Vec<_> =
|field| (*tcx.tcache.borrow())[ struct_def.fields
local_def(field.node.id)].ty).collect(); .iter()
.map(|field| tcx.tcache.borrow().get(&local_def(field.node.id))
.unwrap()
.ty)
.collect();
let ctor_fn_ty = ty::mk_ctor_fn(tcx, let ctor_fn_ty = ty::mk_ctor_fn(tcx,
local_def(ctor_id), local_def(ctor_id),
&inputs[..], &inputs[..],

View file

@ -290,7 +290,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: ast::DefId, p: &clean::Path,
if ast_util::is_local(did) || cache.inlined.contains(&did) { if ast_util::is_local(did) || cache.inlined.contains(&did) {
Some(repeat("../").take(loc.len()).collect::<String>()) Some(repeat("../").take(loc.len()).collect::<String>())
} else { } else {
match cache.extern_locations[did.krate] { match cache.extern_locations[&did.krate] {
render::Remote(ref s) => Some(s.to_string()), render::Remote(ref s) => Some(s.to_string()),
render::Local => { render::Local => {
Some(repeat("../").take(loc.len()).collect::<String>()) Some(repeat("../").take(loc.len()).collect::<String>())
@ -404,11 +404,11 @@ fn primitive_link(f: &mut fmt::Formatter,
needs_termination = true; needs_termination = true;
} }
Some(&cnum) => { Some(&cnum) => {
let path = &m.paths[ast::DefId { let path = &m.paths[&ast::DefId {
krate: cnum, krate: cnum,
node: ast::CRATE_NODE_ID, node: ast::CRATE_NODE_ID,
}]; }];
let loc = match m.extern_locations[cnum] { let loc = match m.extern_locations[&cnum] {
render::Remote(ref s) => Some(s.to_string()), render::Remote(ref s) => Some(s.to_string()),
render::Local => { render::Local => {
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len()); let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());

View file

@ -1404,8 +1404,8 @@ impl<'a> Item<'a> {
// located, then we return `None`. // located, then we return `None`.
} else { } else {
let cache = cache(); let cache = cache();
let path = &cache.external_paths[self.item.def_id]; let path = &cache.external_paths[&self.item.def_id];
let root = match cache.extern_locations[self.item.def_id.krate] { let root = match cache.extern_locations[&self.item.def_id.krate] {
Remote(ref s) => s.to_string(), Remote(ref s) => s.to_string(),
Local => self.cx.root_path.clone(), Local => self.cx.root_path.clone(),
Unknown => return None, Unknown => return None,
@ -1863,7 +1863,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
path = if ast_util::is_local(it.def_id) { path = if ast_util::is_local(it.def_id) {
cx.current.connect("/") cx.current.connect("/")
} else { } else {
let path = &cache.external_paths[it.def_id]; let path = &cache.external_paths[&it.def_id];
path[..path.len() - 1].connect("/") path[..path.len() - 1].connect("/")
}, },
ty = shortty(it).to_static_str(), ty = shortty(it).to_static_str(),

View file

@ -196,7 +196,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
Some(tcx) => tcx, Some(tcx) => tcx,
None => return false None => return false
}; };
let def = tcx.def_map.borrow()[id].def_id(); let def = tcx.def_map.borrow()[&id].def_id();
if !ast_util::is_local(def) { return false } if !ast_util::is_local(def) { return false }
let analysis = match self.analysis { let analysis = match self.analysis {
Some(analysis) => analysis, None => return false Some(analysis) => analysis, None => return false

View file

@ -745,7 +745,7 @@ mod dynamic_tests {
thread_local!(static FOO: RefCell<HashMap<i32, i32>> = map()); thread_local!(static FOO: RefCell<HashMap<i32, i32>> = map());
FOO.with(|map| { FOO.with(|map| {
assert_eq!(map.borrow()[1], 2); assert_eq!(map.borrow()[&1], 2);
}); });
} }

View file

@ -513,7 +513,7 @@ impl<'a, 'b> Context<'a, 'b> {
let lname = self.ecx.ident_of(&format!("__arg{}", let lname = self.ecx.ident_of(&format!("__arg{}",
*name)); *name));
pats.push(self.ecx.pat_ident(e.span, lname)); pats.push(self.ecx.pat_ident(e.span, lname));
names[self.name_positions[*name]] = names[*self.name_positions.get(name).unwrap()] =
Some(Context::format_arg(self.ecx, e.span, arg_ty, Some(Context::format_arg(self.ecx, e.span, arg_ty,
self.ecx.expr_ident(e.span, lname))); self.ecx.expr_ident(e.span, lname)));
heads.push(self.ecx.expr_addr_of(e.span, e)); heads.push(self.ecx.expr_addr_of(e.span, e));

View file

@ -236,7 +236,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
argument_gram); argument_gram);
// Extract the arguments: // Extract the arguments:
let lhses = match *argument_map[lhs_nm] { let lhses = match **argument_map.get(&lhs_nm).unwrap() {
MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(),
_ => cx.span_bug(def.span, "wrong-structured lhs") _ => cx.span_bug(def.span, "wrong-structured lhs")
}; };
@ -245,7 +245,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt,
check_lhs_nt_follows(cx, &**lhs, def.span); check_lhs_nt_follows(cx, &**lhs, def.span);
} }
let rhses = match *argument_map[rhs_nm] { let rhses = match **argument_map.get(&rhs_nm).unwrap() {
MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(),
_ => cx.span_bug(def.span, "wrong-structured rhs") _ => cx.span_bug(def.span, "wrong-structured rhs")
}; };

View file

@ -19,6 +19,6 @@ pub type header_map = HashMap<String, Rc<RefCell<Vec<Rc<String>>>>>;
// the unused ty param is necessary so this gets monomorphized // the unused ty param is necessary so this gets monomorphized
pub fn request<T>(req: &header_map) { pub fn request<T>(req: &header_map) {
let data = req["METHOD".to_string()].clone(); let data = req[&"METHOD".to_string()].clone();
let _x = data.borrow().clone()[0].clone(); let _x = data.borrow().clone()[0].clone();
} }

View file

@ -33,7 +33,7 @@ fn expand_mbe_matches(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
let mac_expr = match TokenTree::parse(cx, &mbe_matcher[..], args) { let mac_expr = match TokenTree::parse(cx, &mbe_matcher[..], args) {
Success(map) => { Success(map) => {
match (&*map[str_to_ident("matched")], &*map[str_to_ident("pat")]) { match (&*map[&str_to_ident("matched")], &*map[&str_to_ident("pat")]) {
(&MatchedNonterminal(NtExpr(ref matched_expr)), (&MatchedNonterminal(NtExpr(ref matched_expr)),
&MatchedSeq(ref pats, seq_sp)) => { &MatchedSeq(ref pats, seq_sp)) => {
let pats: Vec<P<Pat>> = pats.iter().map(|pat_nt| let pats: Vec<P<Pat>> = pats.iter().map(|pat_nt|

View file

@ -19,7 +19,7 @@ struct MyVec<T> { x: T }
impl<T> Index<usize> for MyVec<T> { impl<T> Index<usize> for MyVec<T> {
type Output = T; type Output = T;
fn index(&self, _: &usize) -> &T { fn index(&self, _: usize) -> &T {
&self.x &self.x
} }
} }

View file

@ -18,6 +18,7 @@ struct Foo {
y: isize, y: isize,
} }
#[cfg(stage0)]
impl Index<String> for Foo { impl Index<String> for Foo {
type Output = isize; type Output = isize;
@ -30,8 +31,20 @@ impl Index<String> for Foo {
} }
} }
impl IndexMut<String> for Foo { impl<'a> Index<&'a String> for Foo {
fn index_mut<'a>(&'a mut self, z: &String) -> &'a mut isize { type Output = isize;
fn index(&self, z: &String) -> &isize {
if *z == "x" {
&self.x
} else {
&self.y
}
}
}
impl<'a> IndexMut<&'a String> for Foo {
fn index_mut(&mut self, z: &String) -> &mut isize {
if *z == "x" { if *z == "x" {
&mut self.x &mut self.x
} else { } else {
@ -41,13 +54,13 @@ impl IndexMut<String> for Foo {
} }
fn test1(mut f: Box<Foo>, s: String) { fn test1(mut f: Box<Foo>, s: String) {
let _p = &mut f[s]; let _p = &mut f[&s];
let _q = &f[s]; //~ ERROR cannot borrow let _q = &f[&s]; //~ ERROR cannot borrow
} }
fn test2(mut f: Box<Foo>, s: String) { fn test2(mut f: Box<Foo>, s: String) {
let _p = &mut f[s]; let _p = &mut f[&s];
let _q = &mut f[s]; //~ ERROR cannot borrow let _q = &mut f[&s]; //~ ERROR cannot borrow
} }
struct Bar { struct Bar {
@ -55,37 +68,37 @@ struct Bar {
} }
fn test3(mut f: Box<Bar>, s: String) { fn test3(mut f: Box<Bar>, s: String) {
let _p = &mut f.foo[s]; let _p = &mut f.foo[&s];
let _q = &mut f.foo[s]; //~ ERROR cannot borrow let _q = &mut f.foo[&s]; //~ ERROR cannot borrow
} }
fn test4(mut f: Box<Bar>, s: String) { fn test4(mut f: Box<Bar>, s: String) {
let _p = &f.foo[s]; let _p = &f.foo[&s];
let _q = &f.foo[s]; let _q = &f.foo[&s];
} }
fn test5(mut f: Box<Bar>, s: String) { fn test5(mut f: Box<Bar>, s: String) {
let _p = &f.foo[s]; let _p = &f.foo[&s];
let _q = &mut f.foo[s]; //~ ERROR cannot borrow let _q = &mut f.foo[&s]; //~ ERROR cannot borrow
} }
fn test6(mut f: Box<Bar>, g: Foo, s: String) { fn test6(mut f: Box<Bar>, g: Foo, s: String) {
let _p = &f.foo[s]; let _p = &f.foo[&s];
f.foo = g; //~ ERROR cannot assign f.foo = g; //~ ERROR cannot assign
} }
fn test7(mut f: Box<Bar>, g: Bar, s: String) { fn test7(mut f: Box<Bar>, g: Bar, s: String) {
let _p = &f.foo[s]; let _p = &f.foo[&s];
*f = g; //~ ERROR cannot assign *f = g; //~ ERROR cannot assign
} }
fn test8(mut f: Box<Bar>, g: Foo, s: String) { fn test8(mut f: Box<Bar>, g: Foo, s: String) {
let _p = &mut f.foo[s]; let _p = &mut f.foo[&s];
f.foo = g; //~ ERROR cannot assign f.foo = g; //~ ERROR cannot assign
} }
fn test9(mut f: Box<Bar>, g: Bar, s: String) { fn test9(mut f: Box<Bar>, g: Bar, s: String) {
let _p = &mut f.foo[s]; let _p = &mut f.foo[&s];
*f = g; //~ ERROR cannot assign *f = g; //~ ERROR cannot assign
} }

View file

@ -20,7 +20,7 @@ struct S;
impl Index<usize> for S { impl Index<usize> for S {
type Output = str; type Output = str;
fn index<'a>(&'a self, _: &usize) -> &'a str { fn index(&self, _: usize) -> &str {
"hello" "hello"
} }
} }
@ -31,7 +31,7 @@ struct T;
impl Index<usize> for T { impl Index<usize> for T {
type Output = Debug + 'static; type Output = Debug + 'static;
fn index<'a>(&'a self, idx: &usize) -> &'a (Debug + 'static) { fn index<'a>(&'a self, idx: usize) -> &'a (Debug + 'static) {
static x: usize = 42; static x: usize = 42;
&x &x
} }

View file

@ -19,7 +19,7 @@ struct S;
impl Index<uint> for S { impl Index<uint> for S {
type Output = str; type Output = str;
fn index<'a>(&'a self, _: &uint) -> &'a str { fn index<'a>(&'a self, _: uint) -> &'a str {
"hello" "hello"
} }
} }
@ -29,7 +29,7 @@ struct T;
impl Index<uint> for T { impl Index<uint> for T {
type Output = Debug + 'static; type Output = Debug + 'static;
fn index<'a>(&'a self, idx: &uint) -> &'a (Debug + 'static) { fn index<'a>(&'a self, idx: uint) -> &'a (Debug + 'static) {
static X: uint = 42; static X: uint = 42;
&X as &(Debug + 'static) &X as &(Debug + 'static)
} }

View file

@ -29,7 +29,7 @@ impl<T> Mat<T> {
impl<T> Index<(uint, uint)> for Mat<T> { impl<T> Index<(uint, uint)> for Mat<T> {
type Output = T; type Output = T;
fn index<'a>(&'a self, &(row, col): &(uint, uint)) -> &'a T { fn index<'a>(&'a self, (row, col): (uint, uint)) -> &'a T {
&self.data[row * self.cols + col] &self.data[row * self.cols + col]
} }
} }
@ -37,7 +37,7 @@ impl<T> Index<(uint, uint)> for Mat<T> {
impl<'a, T> Index<(uint, uint)> for &'a Mat<T> { impl<'a, T> Index<(uint, uint)> for &'a Mat<T> {
type Output = T; type Output = T;
fn index<'b>(&'b self, index: &(uint, uint)) -> &'b T { fn index<'b>(&'b self, index: (uint, uint)) -> &'b T {
(*self).index(index) (*self).index(index)
} }
} }
@ -47,8 +47,8 @@ struct Row<M> { mat: M, row: uint, }
impl<T, M: Index<(uint, uint), Output=T>> Index<uint> for Row<M> { impl<T, M: Index<(uint, uint), Output=T>> Index<uint> for Row<M> {
type Output = T; type Output = T;
fn index<'a>(&'a self, col: &uint) -> &'a T { fn index<'a>(&'a self, col: uint) -> &'a T {
&self.mat[(self.row, *col)] &self.mat[(self.row, col)]
} }
} }
@ -56,7 +56,7 @@ fn main() {
let m = Mat::new(vec!(1, 2, 3, 4, 5, 6), 3); let m = Mat::new(vec!(1, 2, 3, 4, 5, 6), 3);
let r = m.row(1); let r = m.row(1);
assert!(r.index(&2) == &6); assert!(r.index(2) == &6);
assert!(r[2] == 6); assert!(r[2] == 6);
assert!(r[2] == 6); assert!(r[2] == 6);
assert!(6 == r[2]); assert!(6 == r[2]);

View file

@ -16,7 +16,7 @@ extern crate collections;
use std::collections::HashMap; use std::collections::HashMap;
fn add_interfaces(managed_ip: String, device: HashMap<String, int>) { fn add_interfaces(managed_ip: String, device: HashMap<String, int>) {
println!("{}, {}", managed_ip, device["interfaces".to_string()]); println!("{}, {}", managed_ip, device["interfaces"]);
} }
pub fn main() {} pub fn main() {}

View file

@ -56,8 +56,7 @@ fn add_interface(_store: int, managed_ip: String, data: json::Json) -> (String,
fn add_interfaces(store: int, managed_ip: String, device: HashMap<String, json::Json>) fn add_interfaces(store: int, managed_ip: String, device: HashMap<String, json::Json>)
-> Vec<(String, object)> { -> Vec<(String, object)> {
match device["interfaces".to_string()] match device["interfaces"] {
{
Json::Array(ref interfaces) => Json::Array(ref interfaces) =>
{ {
interfaces.iter().map(|interface| { interfaces.iter().map(|interface| {
@ -67,7 +66,7 @@ fn add_interfaces(store: int, managed_ip: String, device: HashMap<String, json::
_ => _ =>
{ {
println!("Expected list for {} interfaces, found {}", managed_ip, println!("Expected list for {} interfaces, found {}", managed_ip,
device["interfaces".to_string()]); device["interfaces"]);
Vec::new() Vec::new()
} }
} }

View file

@ -17,7 +17,7 @@ fn bar(a: foo::map) {
if false { if false {
panic!(); panic!();
} else { } else {
let _b = &(*a)[2]; let _b = &(*a)[&2];
} }
} }

View file

@ -21,6 +21,6 @@ pub fn main() {
let mut m: HashMap<int, A> = HashMap::new(); let mut m: HashMap<int, A> = HashMap::new();
m.insert(1, A(0, 0)); m.insert(1, A(0, 0));
let A(ref _a, ref _b) = m[1]; let A(ref _a, ref _b) = m[&1];
let (a, b) = match m[1] { A(ref _a, ref _b) => (_a, _b) }; let (a, b) = match m[&1] { A(ref _a, ref _b) => (_a, _b) };
} }

View file

@ -52,8 +52,8 @@ impl ops::Not for Point {
impl ops::Index<bool> for Point { impl ops::Index<bool> for Point {
type Output = int; type Output = int;
fn index(&self, x: &bool) -> &int { fn index(&self, x: bool) -> &int {
if *x { if x {
&self.x &self.x
} else { } else {
&self.y &self.y

View file

@ -28,7 +28,7 @@ impl<K,V> AssociationList<K,V> {
} }
} }
impl<K: PartialEq + std::fmt::Debug, V:Clone> Index<K> for AssociationList<K,V> { impl<'a, K: PartialEq + std::fmt::Debug, V:Clone> Index<&'a K> for AssociationList<K,V> {
type Output = V; type Output = V;
fn index<'a>(&'a self, index: &K) -> &'a V { fn index<'a>(&'a self, index: &K) -> &'a V {
@ -49,9 +49,9 @@ pub fn main() {
list.push(foo.clone(), 22); list.push(foo.clone(), 22);
list.push(bar.clone(), 44); list.push(bar.clone(), 44);
assert!(list[foo] == 22); assert!(list[&foo] == 22);
assert!(list[bar] == 44); assert!(list[&bar] == 44);
assert!(list[foo] == 22); assert!(list[&foo] == 22);
assert!(list[bar] == 44); assert!(list[&bar] == 44);
} }

View file

@ -23,8 +23,8 @@ struct Foo {
impl Index<int> for Foo { impl Index<int> for Foo {
type Output = int; type Output = int;
fn index(&self, z: &int) -> &int { fn index(&self, z: int) -> &int {
if *z == 0 { if z == 0 {
&self.x &self.x
} else { } else {
&self.y &self.y
@ -33,8 +33,8 @@ impl Index<int> for Foo {
} }
impl IndexMut<int> for Foo { impl IndexMut<int> for Foo {
fn index_mut(&mut self, z: &int) -> &mut int { fn index_mut(&mut self, z: int) -> &mut int {
if *z == 0 { if z == 0 {
&mut self.x &mut self.x
} else { } else {
&mut self.y &mut self.y

View file

@ -25,8 +25,8 @@ struct Bar {
impl Index<int> for Foo { impl Index<int> for Foo {
type Output = int; type Output = int;
fn index(&self, z: &int) -> &int { fn index(&self, z: int) -> &int {
if *z == 0 { if z == 0 {
&self.x &self.x
} else { } else {
&self.y &self.y

View file

@ -18,8 +18,8 @@ struct Foo {
impl Index<int> for Foo { impl Index<int> for Foo {
type Output = int; type Output = int;
fn index(&self, z: &int) -> &int { fn index(&self, z: int) -> &int {
if *z == 0 { if z == 0 {
&self.x &self.x
} else { } else {
&self.y &self.y
@ -28,8 +28,8 @@ impl Index<int> for Foo {
} }
impl IndexMut<int> for Foo { impl IndexMut<int> for Foo {
fn index_mut(&mut self, z: &int) -> &mut int { fn index_mut(&mut self, z: int) -> &mut int {
if *z == 0 { if z == 0 {
&mut self.x &mut self.x
} else { } else {
&mut self.y &mut self.y

View file

@ -21,53 +21,53 @@ struct Foo;
impl Index<Range<Foo>> for Foo { impl Index<Range<Foo>> for Foo {
type Output = Foo; type Output = Foo;
fn index(&self, index: &Range<Foo>) -> &Foo { fn index(&self, index: Range<Foo>) -> &Foo {
unsafe { COUNT += 1; } unsafe { COUNT += 1; }
self self
} }
} }
impl Index<RangeTo<Foo>> for Foo { impl Index<RangeTo<Foo>> for Foo {
type Output = Foo; type Output = Foo;
fn index(&self, index: &RangeTo<Foo>) -> &Foo { fn index(&self, index: RangeTo<Foo>) -> &Foo {
unsafe { COUNT += 1; } unsafe { COUNT += 1; }
self self
} }
} }
impl Index<RangeFrom<Foo>> for Foo { impl Index<RangeFrom<Foo>> for Foo {
type Output = Foo; type Output = Foo;
fn index(&self, index: &RangeFrom<Foo>) -> &Foo { fn index(&self, index: RangeFrom<Foo>) -> &Foo {
unsafe { COUNT += 1; } unsafe { COUNT += 1; }
self self
} }
} }
impl Index<RangeFull> for Foo { impl Index<RangeFull> for Foo {
type Output = Foo; type Output = Foo;
fn index(&self, _index: &RangeFull) -> &Foo { fn index(&self, _index: RangeFull) -> &Foo {
unsafe { COUNT += 1; } unsafe { COUNT += 1; }
self self
} }
} }
impl IndexMut<Range<Foo>> for Foo { impl IndexMut<Range<Foo>> for Foo {
fn index_mut(&mut self, index: &Range<Foo>) -> &mut Foo { fn index_mut(&mut self, index: Range<Foo>) -> &mut Foo {
unsafe { COUNT += 1; } unsafe { COUNT += 1; }
self self
} }
} }
impl IndexMut<RangeTo<Foo>> for Foo { impl IndexMut<RangeTo<Foo>> for Foo {
fn index_mut(&mut self, index: &RangeTo<Foo>) -> &mut Foo { fn index_mut(&mut self, index: RangeTo<Foo>) -> &mut Foo {
unsafe { COUNT += 1; } unsafe { COUNT += 1; }
self self
} }
} }
impl IndexMut<RangeFrom<Foo>> for Foo { impl IndexMut<RangeFrom<Foo>> for Foo {
fn index_mut(&mut self, index: &RangeFrom<Foo>) -> &mut Foo { fn index_mut(&mut self, index: RangeFrom<Foo>) -> &mut Foo {
unsafe { COUNT += 1; } unsafe { COUNT += 1; }
self self
} }
} }
impl IndexMut<RangeFull> for Foo { impl IndexMut<RangeFull> for Foo {
fn index_mut(&mut self, _index: &RangeFull) -> &mut Foo { fn index_mut(&mut self, _index: RangeFull) -> &mut Foo {
unsafe { COUNT += 1; } unsafe { COUNT += 1; }
self self
} }