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",
/// 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")]
@ -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> {

View File

@ -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_|
@ -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_|
@ -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> {

View File

@ -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 {

View File

@ -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());
@ -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);
@ -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.

View File

@ -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);
})

View File

@ -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 \
@ -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 \

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::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);
}

View File

@ -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,
@ -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;

View File

@ -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) {

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
// 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);

View File

@ -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()
});
}
}

View File

@ -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));
@ -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 {
@ -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

View File

@ -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)
}

View File

@ -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) {

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
// 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 {

View File

@ -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; }
};

View File

@ -2667,7 +2667,7 @@ 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,
@ -2675,14 +2675,14 @@ impl<'tcx> ctxt<'tcx> {
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()
}
}
@ -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())
}
}

View File

@ -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(..) => {}

View File

@ -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 \

View File

@ -253,7 +253,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
ast::ItemImpl(_, _, _, _, ref ty, ref impl_items) => {
let public_ty = match ty.node {
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 => {
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 => {
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 => {
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.
if self.prev_exported {
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) {
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
// access is public.
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
// 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
/// inside.
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));
// 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(..) => {}
_ => 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();
assert!(is_local(did));
match self.tcx.map.get(did.node) {
@ -708,7 +708,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
// Checks that a path is in scope.
fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Ident) {
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_public = |def: ast::DefId| {
debug!("privacy - ck_public {:?}", def);
@ -881,7 +881,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
}
}
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, _) => {
for field in fields {
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.
let data = if dylib {
&trans.crate_formats[config::CrateTypeDylib]
trans.crate_formats.get(&config::CrateTypeDylib).unwrap()
} 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

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",
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 {
def::DefPrimTy(_) => None,
_ => 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",
ref_id));
}
let def = def_map[ref_id].full_def();
let def = def_map.get(&ref_id).unwrap().full_def();
match def {
def::DefMod(_) |
def::DefForeignMod(_) => Some(recorder::ModRef),
@ -269,8 +269,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
self.collecting = false;
let span_utils = self.span.clone();
for &(id, ref p, _, _) in &self.collected_paths {
let typ = ppaux::ty_to_string(&self.analysis.ty_cx,
(*self.analysis.ty_cx.node_types.borrow())[id]);
let typ =
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
// variable name, but who knows?)
self.fmt.formal_str(p.span,
@ -431,8 +433,10 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
ast::NamedField(ident, _) => {
let name = get_ident(ident);
let qualname = format!("{}::{}", qualname, name);
let typ = ppaux::ty_to_string(&self.analysis.ty_cx,
(*self.analysis.ty_cx.node_types.borrow())[field.node.id]);
let typ =
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) {
Some(sub_span) => self.fmt.field_str(field.span,
Some(sub_span),
@ -789,7 +793,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
self.sess.span_bug(span,
&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);
match def {
def::DefUpvar(..) |
@ -832,7 +836,8 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
.ty_cx
.impl_items
.borrow();
Some((*impl_items)[def_id]
Some(impl_items.get(&def_id)
.unwrap()
.iter()
.find(|mr| {
ty::impl_or_trait_item(
@ -941,7 +946,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
ex: &ast::Expr,
args: &Vec<P<ast::Expr>>) {
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 {
ty::MethodStatic(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));
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 {
def::DefConst(..) => None,
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 = glob_map.as_ref().unwrap();
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 {
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",
id));
}
let def = def_map[id].full_def();
let def = def_map.get(&id).unwrap().full_def();
match def {
def::DefLocal(id) => {
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 {
let value = if *immut { value.to_string() } else { "<mutable>".to_string() };
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
// is only ever a variable name, but who knows?).
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 => {
let data = &m[0].data;
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);
if binfo.trmode == TrByRef && type_is_fat_ptr(bcx.tcx(), binfo.ty) {
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 {
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>,
@ -2322,7 +2322,7 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
static");
}
let v = ccx.static_values().borrow()[item.id].clone();
let v = ccx.static_values().borrow().get(&item.id).unwrap().clone();
unsafe {
if !(llvm::LLVMConstIntGetZExtValue(v) != 0) {
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 {
ExprId(id) => ty::node_id_to_type(tcx, id),
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,

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> {
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 {
@ -1213,7 +1213,7 @@ pub fn node_id_substs<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ty::node_id_item_substs(tcx, id).substs
}
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.
match expr.node {
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 {
def::DefConst(def_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(..) => {
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 {
def::DefFn(..) | def::DefMethod(..) => {
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);
// At this point, get_item_val has already translated the
// 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,
// otherwise some LLVM optimization passes don't work as expected
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);
}
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::PREFER_IN_PLACE) {
if let SaveIn(lldest) = dest {
@ -209,7 +209,7 @@ pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let mut bcx = bcx;
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 global = if !qualif.intersects(check_const::NOT_CONST | check_const::NEEDS_DROP) {
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)));
}
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 {
def::DefVariant(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>,
autoref: bool)
-> 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,
expr.debug_loc(),
monomorphize_type(bcx, method_ty),
@ -1982,10 +1982,12 @@ fn trans_overloaded_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
dest: Option<Dest>)
-> Block<'blk, 'tcx> {
let method_call = MethodCall::expr(expr.id);
let method_type = (*bcx.tcx()
.method_map
.borrow())[method_call]
.ty;
let method_type = bcx.tcx()
.method_map
.borrow()
.get(&method_call)
.unwrap()
.ty;
let mut all_args = vec!(callee);
all_args.extend(args.iter().map(|e| &**e));
unpack_result!(bcx,

View File

@ -1046,7 +1046,7 @@ fn associated_path_def_to_ty<'tcx>(this: &AstConv<'tcx>,
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) {
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);
}
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);
assert!(const_scheme.generics.is_empty());
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
// 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 {
let ct = fcx.local_ty(pat.span, canon_id);
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 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 {
def::DefTrait(_) => {
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 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()
.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>)
-> 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,
@ -549,7 +549,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
debug!("Local variable {} is assigned type {}",
self.fcx.pat_to_string(&*local.pat),
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);
}
@ -565,7 +565,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
debug!("Pattern binding {} is assigned to {} with type {}",
token::get_ident(path1.node),
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()));
}
}
@ -3327,7 +3327,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
let mut missing_fields = Vec::new();
for class_field in field_types {
let name = class_field.name;
let (_, seen) = class_field_map[name];
let (_, seen) = *class_field_map.get(&name).unwrap();
if !seen {
missing_fields.push(
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 rty = ty::node_id_to_type(ccx.tcx, 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);
}

View File

@ -448,7 +448,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx> {
let closure_def_id = ast_util::local_def(closure_id);
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={:?}",
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)
-> 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.
@ -387,7 +387,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
};
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 {
// We'll error out later. For now, just don't ICE.
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>> {
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::TypeTraitItem(..) => {
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
{
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 {
def::DefSelfTy(node_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);
} else if struct_def.fields[0].node.kind.is_unnamed() {
// Tuple-like.
let inputs: Vec<_> = struct_def.fields.iter().map(
|field| (*tcx.tcache.borrow())[
local_def(field.node.id)].ty).collect();
let inputs: Vec<_> =
struct_def.fields
.iter()
.map(|field| tcx.tcache.borrow().get(&local_def(field.node.id))
.unwrap()
.ty)
.collect();
let ctor_fn_ty = ty::mk_ctor_fn(tcx,
local_def(ctor_id),
&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) {
Some(repeat("../").take(loc.len()).collect::<String>())
} else {
match cache.extern_locations[did.krate] {
match cache.extern_locations[&did.krate] {
render::Remote(ref s) => Some(s.to_string()),
render::Local => {
Some(repeat("../").take(loc.len()).collect::<String>())
@ -404,11 +404,11 @@ fn primitive_link(f: &mut fmt::Formatter,
needs_termination = true;
}
Some(&cnum) => {
let path = &m.paths[ast::DefId {
let path = &m.paths[&ast::DefId {
krate: cnum,
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::Local => {
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`.
} else {
let cache = cache();
let path = &cache.external_paths[self.item.def_id];
let root = match cache.extern_locations[self.item.def_id.krate] {
let path = &cache.external_paths[&self.item.def_id];
let root = match cache.extern_locations[&self.item.def_id.krate] {
Remote(ref s) => s.to_string(),
Local => self.cx.root_path.clone(),
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) {
cx.current.connect("/")
} else {
let path = &cache.external_paths[it.def_id];
let path = &cache.external_paths[&it.def_id];
path[..path.len() - 1].connect("/")
},
ty = shortty(it).to_static_str(),

View File

@ -196,7 +196,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
Some(tcx) => tcx,
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 }
let analysis = match self.analysis {
Some(analysis) => analysis, None => return false

View File

@ -745,7 +745,7 @@ mod dynamic_tests {
thread_local!(static FOO: RefCell<HashMap<i32, i32>> = 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{}",
*name));
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,
self.ecx.expr_ident(e.span, lname)));
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);
// 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(),
_ => 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);
}
let rhses = match *argument_map[rhs_nm] {
let rhses = match **argument_map.get(&rhs_nm).unwrap() {
MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(),
_ => 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
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();
}

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) {
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)),
&MatchedSeq(ref pats, seq_sp)) => {
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> {
type Output = T;
fn index(&self, _: &usize) -> &T {
fn index(&self, _: usize) -> &T {
&self.x
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ extern crate collections;
use std::collections::HashMap;
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() {}

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>)
-> Vec<(String, object)> {
match device["interfaces".to_string()]
{
match device["interfaces"] {
Json::Array(ref interfaces) =>
{
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,
device["interfaces".to_string()]);
device["interfaces"]);
Vec::new()
}
}

View File

@ -17,7 +17,7 @@ fn bar(a: foo::map) {
if false {
panic!();
} 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();
m.insert(1, A(0, 0));
let A(ref _a, ref _b) = m[1];
let (a, b) = match m[1] { A(ref _a, ref _b) => (_a, _b) };
let A(ref _a, ref _b) = m[&1];
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 {
type Output = int;
fn index(&self, x: &bool) -> &int {
if *x {
fn index(&self, x: bool) -> &int {
if x {
&self.x
} else {
&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;
fn index<'a>(&'a self, index: &K) -> &'a V {
@ -49,9 +49,9 @@ pub fn main() {
list.push(foo.clone(), 22);
list.push(bar.clone(), 44);
assert!(list[foo] == 22);
assert!(list[bar] == 44);
assert!(list[&foo] == 22);
assert!(list[&bar] == 44);
assert!(list[foo] == 22);
assert!(list[bar] == 44);
assert!(list[&foo] == 22);
assert!(list[&bar] == 44);
}

View File

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

View File

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

View File

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

View File

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