Skip to content

Commit

Permalink
add warning for rust-lang#6248 and remove instances of it
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed May 5, 2013
1 parent 6806900 commit 0b0b801
Show file tree
Hide file tree
Showing 32 changed files with 142 additions and 92 deletions.
13 changes: 13 additions & 0 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use rand;
use uint;
use vec;
use util::unreachable;
use kinds::Copy;

static INITIAL_CAPACITY: uint = 32u; // 2^5

Expand Down Expand Up @@ -529,6 +530,18 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
}
}

pub impl<K: Hash + Eq, V: Copy> HashMap<K, V> {
/// Like `find`, but returns a copy of the value.
fn find_copy(&self, k: &K) -> Option<V> {
self.find(k).map_consume(|v| copy *v)
}

/// Like `get`, but returns a copy of the value.
fn get_copy(&self, k: &K) -> V {
copy *self.get(k)
}
}

impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
fn eq(&self, other: &HashMap<K, V>) -> bool {
if self.len() != other.len() { return false; }
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn encode_type_param_bounds(ebml_w: &writer::Encoder,
ecx: @EncodeContext,
params: &OptVec<TyParam>) {
let ty_param_defs =
@params.map_to_vec(|param| *ecx.tcx.ty_param_defs.get(&param.id));
@params.map_to_vec(|param| ecx.tcx.ty_param_defs.get_copy(&param.id));
encode_ty_type_param_defs(ebml_w, ecx, ty_param_defs,
tag_items_data_item_ty_param_bounds);
}
Expand Down Expand Up @@ -275,7 +275,7 @@ fn encode_symbol(ecx: @EncodeContext, ebml_w: &writer::Encoder, id: node_id) {
fn encode_discriminant(ecx: @EncodeContext, ebml_w: &writer::Encoder,
id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
ebml_w.writer.write(str::to_bytes(**ecx.discrim_symbols.get(&id)));
ebml_w.writer.write(str::to_bytes(*ecx.discrim_symbols.get_copy(&id)));
ebml_w.end_tag();
}

Expand Down Expand Up @@ -1035,7 +1035,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: &writer::Encoder,
let ebml_w = copy *ebml_w;
|i, cx, v| {
visit::visit_item(i, cx, v);
match *ecx.tcx.items.get(&i.id) {
match ecx.tcx.items.get_copy(&i.id) {
ast_map::node_item(_, pt) => {
encode_info_for_item(ecx, &ebml_w, i,
index, *pt);
Expand All @@ -1048,7 +1048,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: &writer::Encoder,
let ebml_w = copy *ebml_w;
|ni, cx, v| {
visit::visit_foreign_item(ni, cx, v);
match *ecx.tcx.items.get(&ni.id) {
match ecx.tcx.items.get_copy(&ni.id) {
ast_map::node_foreign_item(_, abi, _, pt) => {
encode_info_for_foreign_item(ecx, &ebml_w, ni,
index, /*bad*/copy *pt,
Expand Down
36 changes: 29 additions & 7 deletions src/librustc/middle/borrowck/gather_loans/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use middle::ty;
use syntax::ast::{m_const, m_imm, m_mutbl};
use syntax::ast;
use syntax::codemap::span;
use util::ppaux::{note_and_explain_region};

pub fn guarantee_lifetime(bccx: @BorrowckCtxt,
item_scope_id: ast::node_id,
Expand Down Expand Up @@ -215,13 +216,6 @@ impl GuaranteeLifetimeContext {
}
};

// FIXME(#3511) grow to the nearest cleanup scope---this can
// cause observable errors if freezing!
if !self.bccx.tcx.region_maps.is_cleanup_scope(root_scope) {
debug!("%? is not a cleanup scope, adjusting", root_scope);
root_scope = self.bccx.tcx.region_maps.cleanup_scope(root_scope);
}

// If we are borrowing the inside of an `@mut` box,
// we need to dynamically mark it to prevent incompatible
// borrows from happening later.
Expand All @@ -235,6 +229,34 @@ impl GuaranteeLifetimeContext {
}
};

// FIXME(#3511) grow to the nearest cleanup scope---this can
// cause observable errors if freezing!
if !self.bccx.tcx.region_maps.is_cleanup_scope(root_scope) {
debug!("%? is not a cleanup scope, adjusting", root_scope);

let cleanup_scope =
self.bccx.tcx.region_maps.cleanup_scope(root_scope);

if opt_dyna.is_some() {
self.tcx().sess.span_warn(
self.span,
fmt!("Dynamic freeze scope artifically extended \
(see Issue #6248)"));
note_and_explain_region(
self.bccx.tcx,
"managed value only needs to be frozen for ",
ty::re_scope(root_scope),
"...");
note_and_explain_region(
self.bccx.tcx,
"...but due to Issue #6248, it will be frozen for ",
ty::re_scope(cleanup_scope),
"");
}

root_scope = cleanup_scope;
}

// Add a record of what is required
let rm_key = root_map_key {id: cmt_deref.id, derefs: derefs};
let root_info = RootInfo {scope: root_scope, freeze: opt_dyna};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub fn check_item_recursion(sess: Session,
match env.def_map.find(&e.id) {
Some(&def_const(def_id)) => {
if ast_util::is_local(def_id) {
match *env.ast_map.get(&def_id.node) {
match env.ast_map.get_copy(&def_id.node) {
ast_map::node_item(it, _) => {
(v.visit_item)(it, env, v);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
}
}
pat_enum(_, args) => {
match *cx.tcx.def_map.get(&pat_id) {
match cx.tcx.def_map.get_copy(&pat_id) {
def_const(did) => {
let const_expr =
lookup_const_by_id(cx.tcx, did).get();
Expand Down Expand Up @@ -567,7 +567,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
}
pat_struct(_, ref flds, _) => {
// Is this a struct or an enum variant?
match *cx.tcx.def_map.get(&pat_id) {
match cx.tcx.def_map.get_copy(&pat_id) {
def_variant(_, variant_id) => {
if variant(variant_id) == *ctor_id {
// FIXME #4731: Is this right? --pcw
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn check_item(item: @item, cx: Context, visitor: visit::vt<Context>) {
// Yes, it's a destructor.
match self_type.node {
ty_path(_, path_node_id) => {
let struct_def = *cx.tcx.def_map.get(
let struct_def = cx.tcx.def_map.get_copy(
&path_node_id);
let struct_did =
ast_util::def_id_of_def(struct_def);
Expand Down Expand Up @@ -272,7 +272,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
let ts = /*bad*/ copy **ts;
let type_param_defs = match e.node {
expr_path(_) => {
let did = ast_util::def_id_of_def(*cx.tcx.def_map.get(&e.id));
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&e.id));
ty::lookup_item_type(cx.tcx, did).generics.type_param_defs
}
_ => {
Expand Down Expand Up @@ -333,7 +333,7 @@ fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
for cx.tcx.node_type_substs.find(&id).each |ts| {
// FIXME(#5562): removing this copy causes a segfault before stage2
let ts = /*bad*/ copy **ts;
let did = ast_util::def_id_of_def(*cx.tcx.def_map.get(&id));
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
let type_param_defs =
ty::lookup_item_type(cx.tcx, did).generics.type_param_defs;
for vec::each2(ts, *type_param_defs) |&ty, type_param_def| {
Expand Down Expand Up @@ -399,7 +399,7 @@ pub fn check_bounds(cx: Context,
fn is_nullary_variant(cx: Context, ex: @expr) -> bool {
match ex.node {
expr_path(_) => {
match *cx.tcx.def_map.get(&ex.id) {
match cx.tcx.def_map.get_copy(&ex.id) {
def_variant(edid, vdid) => {
vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
for vec::each(vec::append_one(tys, decl.output)) |ty| {
match ty.node {
ast::ty_path(_, id) => {
match *cx.def_map.get(&id) {
match cx.def_map.get_copy(&id) {
ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
cx.sess.span_lint(
ctypes, id, fn_id,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ fn visit_expr(expr: @expr, self: @mut IrMaps, vt: vt<@mut IrMaps>) {
match expr.node {
// live nodes required for uses or definitions of variables:
expr_path(_) => {
let def = *self.tcx.def_map.get(&expr.id);
let def = self.tcx.def_map.get_copy(&expr.id);
debug!("expr %d: path that leads to %?", expr.id, def);
if moves::moved_variable_node_id_from_def(def).is_some() {
self.add_live_node_for_node(expr.id, ExprNode(expr.span));
Expand Down Expand Up @@ -616,7 +616,7 @@ pub impl Liveness {
fn variable_from_path(&self, expr: @expr) -> Option<Variable> {
match expr.node {
expr_path(_) => {
let def = *self.tcx.def_map.get(&expr.id);
let def = self.tcx.def_map.get_copy(&expr.id);
moves::moved_variable_node_id_from_def(def).map(
|rdef| self.variable(*rdef, expr.span)
)
Expand Down Expand Up @@ -1338,7 +1338,7 @@ pub impl Liveness {

fn access_path(&self, expr: @expr, succ: LiveNode, acc: uint)
-> LiveNode {
let def = *self.tcx.def_map.get(&expr.id);
let def = self.tcx.def_map.get_copy(&expr.id);
match moves::moved_variable_node_id_from_def(def) {
Some(nid) => {
let ln = self.live_node(expr.id, expr.span);
Expand Down Expand Up @@ -1605,7 +1605,7 @@ pub impl Liveness {
fn check_lvalue(@self, expr: @expr, vt: vt<@Liveness>) {
match expr.node {
expr_path(_) => {
match *self.tcx.def_map.get(&expr.id) {
match self.tcx.def_map.get_copy(&expr.id) {
def_local(nid, mutbl) => {
// Assignment to an immutable variable or argument: only legal
// if there is no later assignment. If this local is actually
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ pub impl mem_categorization_ctxt {
}

ast::expr_path(_) => {
let def = *self.tcx.def_map.get(&expr.id);
let def = self.tcx.def_map.get_copy(&expr.id);
self.cat_def(expr.id, expr.span, expr_ty, def)
}

Expand Down Expand Up @@ -977,7 +977,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
}
}
ty::ty_enum(*) => {
match *tcx.def_map.get(&node_id) {
match tcx.def_map.get_copy(&node_id) {
ast::def_variant(_, variant_id) => {
for ty::lookup_struct_fields(tcx, variant_id).each |fld| {
if fld.ident == f_name {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ pub impl VisitContext {
self.move_maps.variable_moves_map.insert(
expr.id, entire_expr);

let def = *self.tcx.def_map.get(&expr.id);
let def = self.tcx.def_map.get_copy(&expr.id);
for moved_variable_node_id_from_def(def).each |&id| {
self.move_maps.moved_variables_set.insert(id);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ pub fn check_crate(tcx: ty::ctxt,
}
}
expr_path(path) => {
check_path(expr.span, *tcx.def_map.get(&expr.id), path);
check_path(expr.span, tcx.def_map.get_copy(&expr.id), path);
}
expr_struct(_, ref fields, _) => {
match ty::get(ty::expr_ty(tcx, expr)).sty {
Expand All @@ -499,7 +499,7 @@ pub fn check_crate(tcx: ty::ctxt,
ty_enum(id, _) => {
if id.crate != local_crate ||
!privileged_items.contains(&(id.node)) {
match *tcx.def_map.get(&expr.id) {
match tcx.def_map.get_copy(&expr.id) {
def_variant(_, variant_id) => {
for (*fields).each |field| {
debug!("(privacy checking) \
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ pub fn determine_rp_in_crate(sess: Session,
let cx = &mut *cx;
while cx.worklist.len() != 0 {
let c_id = cx.worklist.pop();
let c_variance = { *cx.region_paramd_items.get(&c_id) };
let c_variance = cx.region_paramd_items.get_copy(&c_id);
// NOTE cleanup scopes cause an exaggerated lock here
debug!("popped %d from worklist", c_id);
match cx.dep_map.find(&c_id) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub fn trans_opt(bcx: block, o: &Opt) -> opt_result {
pub fn variant_opt(bcx: block, pat_id: ast::node_id)
-> Opt {
let ccx = bcx.ccx();
match *ccx.tcx.def_map.get(&pat_id) {
match ccx.tcx.def_map.get_copy(&pat_id) {
ast::def_variant(enum_id, var_id) => {
let variants = ty::enum_variants(ccx.tcx, enum_id);
for vec::each(*variants) |v| {
Expand Down Expand Up @@ -516,7 +516,7 @@ pub fn enter_opt<'r>(bcx: block,
match p.node {
ast::pat_enum(*) |
ast::pat_ident(_, _, None) if pat_is_const(tcx.def_map, p) => {
let const_def = *tcx.def_map.get(&p.id);
let const_def = tcx.def_map.get_copy(&p.id);
let const_def_id = ast_util::def_id_of_def(const_def);
if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) {
Some(~[])
Expand Down Expand Up @@ -552,7 +552,7 @@ pub fn enter_opt<'r>(bcx: block,
if opt_eq(tcx, &variant_opt(bcx, p.id), opt) {
// Look up the struct variant ID.
let struct_id;
match *tcx.def_map.get(&p.id) {
match tcx.def_map.get_copy(&p.id) {
ast::def_variant(_, found_struct_id) => {
struct_id = found_struct_id;
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
fcx.llretptr.get(),
0,
i);
let llarg = match *fcx.llargs.get(&field.node.id) {
let llarg = match fcx.llargs.get_copy(&field.node.id) {
local_mem(x) => x,
_ => {
ccx.tcx.sess.bug(~"trans_tuple_struct: llarg wasn't \
Expand Down Expand Up @@ -2141,7 +2141,7 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: &ast::enum_def,
pub fn trans_item(ccx: @CrateContext, item: &ast::item) {
let _icx = ccx.insn_ctxt("trans_item");
let path = match *ccx.tcx.items.get(&item.id) {
let path = match ccx.tcx.items.get_copy(&item.id) {
ast_map::node_item(_, p) => p,
// tjc: ?
_ => fail!(~"trans_item"),
Expand Down Expand Up @@ -2443,7 +2443,7 @@ pub fn fill_fn_pair(bcx: block, pair: ValueRef, llfn: ValueRef,
}
pub fn item_path(ccx: @CrateContext, i: @ast::item) -> path {
let base = match *ccx.tcx.items.get(&i.id) {
let base = match ccx.tcx.items.get_copy(&i.id) {
ast_map::node_item(_, p) => p,
// separate map for paths?
_ => fail!(~"item_path")
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ pub fn trans_expr_fn(bcx: block,

let Result {bcx: bcx, val: closure} = match sigil {
ast::BorrowedSigil | ast::ManagedSigil | ast::OwnedSigil => {
let cap_vars = *ccx.maps.capture_map.get(&user_id);
let cap_vars = ccx.maps.capture_map.get_copy(&user_id);
let ret_handle = match is_loop_body {Some(x) => x,
None => None};
let ClosureResult {llbox, cdata_ty, bcx}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
if !ast_util::is_local(def_id) {
def_id = inline::maybe_instantiate_inline(cx, def_id, true);
}
match *cx.tcx.items.get(&def_id.node) {
match cx.tcx.items.get_copy(&def_id.node) {
ast_map::node_item(@ast::item {
node: ast::item_const(_, subexpr), _
}, _) => {
Expand All @@ -167,7 +167,7 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
_ => cx.tcx.sess.bug(~"expected a const to be an item")
}
}
*cx.const_values.get(&def_id.node)
cx.const_values.get_copy(&def_id.node)
}

pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
Expand Down Expand Up @@ -560,7 +560,7 @@ pub fn trans_const(ccx: @CrateContext, _e: @ast::expr, id: ast::node_id) {
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.const_values.get(&id);
let v = ccx.const_values.get_copy(&id);
llvm::LLVMSetInitializer(g, v);
llvm::LLVMSetGlobalConstant(g, True);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/controlflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn trans_log(log_ex: @ast::expr,
};

let global = if ccx.module_data.contains_key(&modname) {
*ccx.module_data.get(&modname)
ccx.module_data.get_copy(&modname)
} else {
let s = link::mangle_internal_name_by_path_and_seq(
ccx, modpath, ~"loglevel");
Expand Down
Loading

0 comments on commit 0b0b801

Please sign in to comment.