Skip to content

Commit 0b0b801

Browse files
committed
add warning for rust-lang#6248 and remove instances of it
1 parent 6806900 commit 0b0b801

32 files changed

+142
-92
lines changed

src/libcore/hashmap.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rand;
2525
use uint;
2626
use vec;
2727
use util::unreachable;
28+
use kinds::Copy;
2829

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

@@ -529,6 +530,18 @@ pub impl<K: Hash + Eq, V> HashMap<K, V> {
529530
}
530531
}
531532

533+
pub impl<K: Hash + Eq, V: Copy> HashMap<K, V> {
534+
/// Like `find`, but returns a copy of the value.
535+
fn find_copy(&self, k: &K) -> Option<V> {
536+
self.find(k).map_consume(|v| copy *v)
537+
}
538+
539+
/// Like `get`, but returns a copy of the value.
540+
fn get_copy(&self, k: &K) -> V {
541+
copy *self.get(k)
542+
}
543+
}
544+
532545
impl<K:Hash + Eq,V:Eq> Eq for HashMap<K, V> {
533546
fn eq(&self, other: &HashMap<K, V>) -> bool {
534547
if self.len() != other.len() { return false; }

src/librustc/metadata/encoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn encode_type_param_bounds(ebml_w: &writer::Encoder,
190190
ecx: @EncodeContext,
191191
params: &OptVec<TyParam>) {
192192
let ty_param_defs =
193-
@params.map_to_vec(|param| *ecx.tcx.ty_param_defs.get(&param.id));
193+
@params.map_to_vec(|param| ecx.tcx.ty_param_defs.get_copy(&param.id));
194194
encode_ty_type_param_defs(ebml_w, ecx, ty_param_defs,
195195
tag_items_data_item_ty_param_bounds);
196196
}
@@ -275,7 +275,7 @@ fn encode_symbol(ecx: @EncodeContext, ebml_w: &writer::Encoder, id: node_id) {
275275
fn encode_discriminant(ecx: @EncodeContext, ebml_w: &writer::Encoder,
276276
id: node_id) {
277277
ebml_w.start_tag(tag_items_data_item_symbol);
278-
ebml_w.writer.write(str::to_bytes(**ecx.discrim_symbols.get(&id)));
278+
ebml_w.writer.write(str::to_bytes(*ecx.discrim_symbols.get_copy(&id)));
279279
ebml_w.end_tag();
280280
}
281281

@@ -1035,7 +1035,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: &writer::Encoder,
10351035
let ebml_w = copy *ebml_w;
10361036
|i, cx, v| {
10371037
visit::visit_item(i, cx, v);
1038-
match *ecx.tcx.items.get(&i.id) {
1038+
match ecx.tcx.items.get_copy(&i.id) {
10391039
ast_map::node_item(_, pt) => {
10401040
encode_info_for_item(ecx, &ebml_w, i,
10411041
index, *pt);
@@ -1048,7 +1048,7 @@ fn encode_info_for_items(ecx: @EncodeContext, ebml_w: &writer::Encoder,
10481048
let ebml_w = copy *ebml_w;
10491049
|ni, cx, v| {
10501050
visit::visit_foreign_item(ni, cx, v);
1051-
match *ecx.tcx.items.get(&ni.id) {
1051+
match ecx.tcx.items.get_copy(&ni.id) {
10521052
ast_map::node_foreign_item(_, abi, _, pt) => {
10531053
encode_info_for_foreign_item(ecx, &ebml_w, ni,
10541054
index, /*bad*/copy *pt,

src/librustc/middle/borrowck/gather_loans/lifetime.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use middle::ty;
1818
use syntax::ast::{m_const, m_imm, m_mutbl};
1919
use syntax::ast;
2020
use syntax::codemap::span;
21+
use util::ppaux::{note_and_explain_region};
2122

2223
pub fn guarantee_lifetime(bccx: @BorrowckCtxt,
2324
item_scope_id: ast::node_id,
@@ -215,13 +216,6 @@ impl GuaranteeLifetimeContext {
215216
}
216217
};
217218

218-
// FIXME(#3511) grow to the nearest cleanup scope---this can
219-
// cause observable errors if freezing!
220-
if !self.bccx.tcx.region_maps.is_cleanup_scope(root_scope) {
221-
debug!("%? is not a cleanup scope, adjusting", root_scope);
222-
root_scope = self.bccx.tcx.region_maps.cleanup_scope(root_scope);
223-
}
224-
225219
// If we are borrowing the inside of an `@mut` box,
226220
// we need to dynamically mark it to prevent incompatible
227221
// borrows from happening later.
@@ -235,6 +229,34 @@ impl GuaranteeLifetimeContext {
235229
}
236230
};
237231

232+
// FIXME(#3511) grow to the nearest cleanup scope---this can
233+
// cause observable errors if freezing!
234+
if !self.bccx.tcx.region_maps.is_cleanup_scope(root_scope) {
235+
debug!("%? is not a cleanup scope, adjusting", root_scope);
236+
237+
let cleanup_scope =
238+
self.bccx.tcx.region_maps.cleanup_scope(root_scope);
239+
240+
if opt_dyna.is_some() {
241+
self.tcx().sess.span_warn(
242+
self.span,
243+
fmt!("Dynamic freeze scope artifically extended \
244+
(see Issue #6248)"));
245+
note_and_explain_region(
246+
self.bccx.tcx,
247+
"managed value only needs to be frozen for ",
248+
ty::re_scope(root_scope),
249+
"...");
250+
note_and_explain_region(
251+
self.bccx.tcx,
252+
"...but due to Issue #6248, it will be frozen for ",
253+
ty::re_scope(cleanup_scope),
254+
"");
255+
}
256+
257+
root_scope = cleanup_scope;
258+
}
259+
238260
// Add a record of what is required
239261
let rm_key = root_map_key {id: cmt_deref.id, derefs: derefs};
240262
let root_info = RootInfo {scope: root_scope, freeze: opt_dyna};

src/librustc/middle/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn check_item_recursion(sess: Session,
237237
match env.def_map.find(&e.id) {
238238
Some(&def_const(def_id)) => {
239239
if ast_util::is_local(def_id) {
240-
match *env.ast_map.get(&def_id.node) {
240+
match env.ast_map.get_copy(&def_id.node) {
241241
ast_map::node_item(it, _) => {
242242
(v.visit_item)(it, env, v);
243243
}

src/librustc/middle/check_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
523523
}
524524
}
525525
pat_enum(_, args) => {
526-
match *cx.tcx.def_map.get(&pat_id) {
526+
match cx.tcx.def_map.get_copy(&pat_id) {
527527
def_const(did) => {
528528
let const_expr =
529529
lookup_const_by_id(cx.tcx, did).get();
@@ -567,7 +567,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
567567
}
568568
pat_struct(_, ref flds, _) => {
569569
// Is this a struct or an enum variant?
570-
match *cx.tcx.def_map.get(&pat_id) {
570+
match cx.tcx.def_map.get_copy(&pat_id) {
571571
def_variant(_, variant_id) => {
572572
if variant(variant_id) == *ctor_id {
573573
// FIXME #4731: Is this right? --pcw

src/librustc/middle/kind.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn check_item(item: @item, cx: Context, visitor: visit::vt<Context>) {
128128
// Yes, it's a destructor.
129129
match self_type.node {
130130
ty_path(_, path_node_id) => {
131-
let struct_def = *cx.tcx.def_map.get(
131+
let struct_def = cx.tcx.def_map.get_copy(
132132
&path_node_id);
133133
let struct_did =
134134
ast_util::def_id_of_def(struct_def);
@@ -272,7 +272,7 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
272272
let ts = /*bad*/ copy **ts;
273273
let type_param_defs = match e.node {
274274
expr_path(_) => {
275-
let did = ast_util::def_id_of_def(*cx.tcx.def_map.get(&e.id));
275+
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&e.id));
276276
ty::lookup_item_type(cx.tcx, did).generics.type_param_defs
277277
}
278278
_ => {
@@ -333,7 +333,7 @@ fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
333333
for cx.tcx.node_type_substs.find(&id).each |ts| {
334334
// FIXME(#5562): removing this copy causes a segfault before stage2
335335
let ts = /*bad*/ copy **ts;
336-
let did = ast_util::def_id_of_def(*cx.tcx.def_map.get(&id));
336+
let did = ast_util::def_id_of_def(cx.tcx.def_map.get_copy(&id));
337337
let type_param_defs =
338338
ty::lookup_item_type(cx.tcx, did).generics.type_param_defs;
339339
for vec::each2(ts, *type_param_defs) |&ty, type_param_def| {
@@ -399,7 +399,7 @@ pub fn check_bounds(cx: Context,
399399
fn is_nullary_variant(cx: Context, ex: @expr) -> bool {
400400
match ex.node {
401401
expr_path(_) => {
402-
match *cx.tcx.def_map.get(&ex.id) {
402+
match cx.tcx.def_map.get_copy(&ex.id) {
403403
def_variant(edid, vdid) => {
404404
vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
405405
}

src/librustc/middle/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
696696
for vec::each(vec::append_one(tys, decl.output)) |ty| {
697697
match ty.node {
698698
ast::ty_path(_, id) => {
699-
match *cx.def_map.get(&id) {
699+
match cx.def_map.get_copy(&id) {
700700
ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
701701
cx.sess.span_lint(
702702
ctypes, id, fn_id,

src/librustc/middle/liveness.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ fn visit_expr(expr: @expr, self: @mut IrMaps, vt: vt<@mut IrMaps>) {
469469
match expr.node {
470470
// live nodes required for uses or definitions of variables:
471471
expr_path(_) => {
472-
let def = *self.tcx.def_map.get(&expr.id);
472+
let def = self.tcx.def_map.get_copy(&expr.id);
473473
debug!("expr %d: path that leads to %?", expr.id, def);
474474
if moves::moved_variable_node_id_from_def(def).is_some() {
475475
self.add_live_node_for_node(expr.id, ExprNode(expr.span));
@@ -616,7 +616,7 @@ pub impl Liveness {
616616
fn variable_from_path(&self, expr: @expr) -> Option<Variable> {
617617
match expr.node {
618618
expr_path(_) => {
619-
let def = *self.tcx.def_map.get(&expr.id);
619+
let def = self.tcx.def_map.get_copy(&expr.id);
620620
moves::moved_variable_node_id_from_def(def).map(
621621
|rdef| self.variable(*rdef, expr.span)
622622
)
@@ -1338,7 +1338,7 @@ pub impl Liveness {
13381338

13391339
fn access_path(&self, expr: @expr, succ: LiveNode, acc: uint)
13401340
-> LiveNode {
1341-
let def = *self.tcx.def_map.get(&expr.id);
1341+
let def = self.tcx.def_map.get_copy(&expr.id);
13421342
match moves::moved_variable_node_id_from_def(def) {
13431343
Some(nid) => {
13441344
let ln = self.live_node(expr.id, expr.span);
@@ -1605,7 +1605,7 @@ pub impl Liveness {
16051605
fn check_lvalue(@self, expr: @expr, vt: vt<@Liveness>) {
16061606
match expr.node {
16071607
expr_path(_) => {
1608-
match *self.tcx.def_map.get(&expr.id) {
1608+
match self.tcx.def_map.get_copy(&expr.id) {
16091609
def_local(nid, mutbl) => {
16101610
// Assignment to an immutable variable or argument: only legal
16111611
// if there is no later assignment. If this local is actually

src/librustc/middle/mem_categorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ pub impl mem_categorization_ctxt {
409409
}
410410

411411
ast::expr_path(_) => {
412-
let def = *self.tcx.def_map.get(&expr.id);
412+
let def = self.tcx.def_map.get_copy(&expr.id);
413413
self.cat_def(expr.id, expr.span, expr_ty, def)
414414
}
415415

@@ -977,7 +977,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
977977
}
978978
}
979979
ty::ty_enum(*) => {
980-
match *tcx.def_map.get(&node_id) {
980+
match tcx.def_map.get_copy(&node_id) {
981981
ast::def_variant(_, variant_id) => {
982982
for ty::lookup_struct_fields(tcx, variant_id).each |fld| {
983983
if fld.ident == f_name {

src/librustc/middle/moves.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ pub impl VisitContext {
441441
self.move_maps.variable_moves_map.insert(
442442
expr.id, entire_expr);
443443

444-
let def = *self.tcx.def_map.get(&expr.id);
444+
let def = self.tcx.def_map.get_copy(&expr.id);
445445
for moved_variable_node_id_from_def(def).each |&id| {
446446
self.move_maps.moved_variables_set.insert(id);
447447
}

src/librustc/middle/privacy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ pub fn check_crate(tcx: ty::ctxt,
481481
}
482482
}
483483
expr_path(path) => {
484-
check_path(expr.span, *tcx.def_map.get(&expr.id), path);
484+
check_path(expr.span, tcx.def_map.get_copy(&expr.id), path);
485485
}
486486
expr_struct(_, ref fields, _) => {
487487
match ty::get(ty::expr_ty(tcx, expr)).sty {
@@ -499,7 +499,7 @@ pub fn check_crate(tcx: ty::ctxt,
499499
ty_enum(id, _) => {
500500
if id.crate != local_crate ||
501501
!privileged_items.contains(&(id.node)) {
502-
match *tcx.def_map.get(&expr.id) {
502+
match tcx.def_map.get_copy(&expr.id) {
503503
def_variant(_, variant_id) => {
504504
for (*fields).each |field| {
505505
debug!("(privacy checking) \

src/librustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ pub fn determine_rp_in_crate(sess: Session,
949949
let cx = &mut *cx;
950950
while cx.worklist.len() != 0 {
951951
let c_id = cx.worklist.pop();
952-
let c_variance = { *cx.region_paramd_items.get(&c_id) };
952+
let c_variance = cx.region_paramd_items.get_copy(&c_id);
953953
// NOTE cleanup scopes cause an exaggerated lock here
954954
debug!("popped %d from worklist", c_id);
955955
match cx.dep_map.find(&c_id) {

src/librustc/middle/trans/_match.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ pub fn trans_opt(bcx: block, o: &Opt) -> opt_result {
280280
pub fn variant_opt(bcx: block, pat_id: ast::node_id)
281281
-> Opt {
282282
let ccx = bcx.ccx();
283-
match *ccx.tcx.def_map.get(&pat_id) {
283+
match ccx.tcx.def_map.get_copy(&pat_id) {
284284
ast::def_variant(enum_id, var_id) => {
285285
let variants = ty::enum_variants(ccx.tcx, enum_id);
286286
for vec::each(*variants) |v| {
@@ -516,7 +516,7 @@ pub fn enter_opt<'r>(bcx: block,
516516
match p.node {
517517
ast::pat_enum(*) |
518518
ast::pat_ident(_, _, None) if pat_is_const(tcx.def_map, p) => {
519-
let const_def = *tcx.def_map.get(&p.id);
519+
let const_def = tcx.def_map.get_copy(&p.id);
520520
let const_def_id = ast_util::def_id_of_def(const_def);
521521
if opt_eq(tcx, &lit(ConstLit(const_def_id)), opt) {
522522
Some(~[])
@@ -552,7 +552,7 @@ pub fn enter_opt<'r>(bcx: block,
552552
if opt_eq(tcx, &variant_opt(bcx, p.id), opt) {
553553
// Look up the struct variant ID.
554554
let struct_id;
555-
match *tcx.def_map.get(&p.id) {
555+
match tcx.def_map.get_copy(&p.id) {
556556
ast::def_variant(_, found_struct_id) => {
557557
struct_id = found_struct_id;
558558
}

src/librustc/middle/trans/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
20522052
fcx.llretptr.get(),
20532053
0,
20542054
i);
2055-
let llarg = match *fcx.llargs.get(&field.node.id) {
2055+
let llarg = match fcx.llargs.get_copy(&field.node.id) {
20562056
local_mem(x) => x,
20572057
_ => {
20582058
ccx.tcx.sess.bug(~"trans_tuple_struct: llarg wasn't \
@@ -2141,7 +2141,7 @@ pub fn trans_enum_def(ccx: @CrateContext, enum_definition: &ast::enum_def,
21412141
21422142
pub fn trans_item(ccx: @CrateContext, item: &ast::item) {
21432143
let _icx = ccx.insn_ctxt("trans_item");
2144-
let path = match *ccx.tcx.items.get(&item.id) {
2144+
let path = match ccx.tcx.items.get_copy(&item.id) {
21452145
ast_map::node_item(_, p) => p,
21462146
// tjc: ?
21472147
_ => fail!(~"trans_item"),
@@ -2443,7 +2443,7 @@ pub fn fill_fn_pair(bcx: block, pair: ValueRef, llfn: ValueRef,
24432443
}
24442444
24452445
pub fn item_path(ccx: @CrateContext, i: @ast::item) -> path {
2446-
let base = match *ccx.tcx.items.get(&i.id) {
2446+
let base = match ccx.tcx.items.get_copy(&i.id) {
24472447
ast_map::node_item(_, p) => p,
24482448
// separate map for paths?
24492449
_ => fail!(~"item_path")

src/librustc/middle/trans/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ pub fn trans_expr_fn(bcx: block,
424424

425425
let Result {bcx: bcx, val: closure} = match sigil {
426426
ast::BorrowedSigil | ast::ManagedSigil | ast::OwnedSigil => {
427-
let cap_vars = *ccx.maps.capture_map.get(&user_id);
427+
let cap_vars = ccx.maps.capture_map.get_copy(&user_id);
428428
let ret_handle = match is_loop_body {Some(x) => x,
429429
None => None};
430430
let ClosureResult {llbox, cdata_ty, bcx}

src/librustc/middle/trans/consts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
158158
if !ast_util::is_local(def_id) {
159159
def_id = inline::maybe_instantiate_inline(cx, def_id, true);
160160
}
161-
match *cx.tcx.items.get(&def_id.node) {
161+
match cx.tcx.items.get_copy(&def_id.node) {
162162
ast_map::node_item(@ast::item {
163163
node: ast::item_const(_, subexpr), _
164164
}, _) => {
@@ -167,7 +167,7 @@ pub fn get_const_val(cx: @CrateContext, def_id: ast::def_id) -> ValueRef {
167167
_ => cx.tcx.sess.bug(~"expected a const to be an item")
168168
}
169169
}
170-
*cx.const_values.get(&def_id.node)
170+
cx.const_values.get_copy(&def_id.node)
171171
}
172172

173173
pub fn const_expr(cx: @CrateContext, e: @ast::expr) -> ValueRef {
@@ -560,7 +560,7 @@ pub fn trans_const(ccx: @CrateContext, _e: @ast::expr, id: ast::node_id) {
560560
let g = base::get_item_val(ccx, id);
561561
// At this point, get_item_val has already translated the
562562
// constant's initializer to determine its LLVM type.
563-
let v = *ccx.const_values.get(&id);
563+
let v = ccx.const_values.get_copy(&id);
564564
llvm::LLVMSetInitializer(g, v);
565565
llvm::LLVMSetGlobalConstant(g, True);
566566
}

src/librustc/middle/trans/controlflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub fn trans_log(log_ex: @ast::expr,
193193
};
194194

195195
let global = if ccx.module_data.contains_key(&modname) {
196-
*ccx.module_data.get(&modname)
196+
ccx.module_data.get_copy(&modname)
197197
} else {
198198
let s = link::mangle_internal_name_by_path_and_seq(
199199
ccx, modpath, ~"loglevel");

0 commit comments

Comments
 (0)