Skip to content

Commit b65dc42

Browse files
committed
TypeChecker: Avoid unnecessary copies
1 parent de1df36 commit b65dc42

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/librustc/middle/typeck/infer/combine.rs

+33-33
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,12 @@ pub fn super_fn_sigs<C:Combine>(
434434
pub fn super_tys<C:Combine>(
435435
this: &C, a: ty::t, b: ty::t) -> cres<ty::t> {
436436
let tcx = this.infcx().tcx;
437-
return match (/*bad*/copy ty::get(a).sty, /*bad*/copy ty::get(b).sty) {
437+
return match (&ty::get(a).sty, &ty::get(b).sty) {
438438
// The "subtype" ought to be handling cases involving bot or var:
439-
(ty::ty_bot, _) |
440-
(_, ty::ty_bot) |
441-
(ty::ty_infer(TyVar(_)), _) |
442-
(_, ty::ty_infer(TyVar(_))) => {
439+
(&ty::ty_bot, _) |
440+
(_, &ty::ty_bot) |
441+
(&ty::ty_infer(TyVar(_)), _) |
442+
(_, &ty::ty_infer(TyVar(_))) => {
443443
tcx.sess.bug(
444444
fmt!("%s: bot and var types should have been handled (%s,%s)",
445445
this.tag(),
@@ -448,68 +448,68 @@ pub fn super_tys<C:Combine>(
448448
}
449449

450450
// Relate integral variables to other types
451-
(ty::ty_infer(IntVar(a_id)), ty::ty_infer(IntVar(b_id))) => {
451+
(&ty::ty_infer(IntVar(a_id)), &ty::ty_infer(IntVar(b_id))) => {
452452
if_ok!(this.infcx().simple_vars(this.a_is_expected(),
453453
a_id, b_id));
454454
Ok(a)
455455
}
456-
(ty::ty_infer(IntVar(v_id)), ty::ty_int(v)) => {
456+
(&ty::ty_infer(IntVar(v_id)), &ty::ty_int(v)) => {
457457
unify_integral_variable(this, this.a_is_expected(),
458458
v_id, IntType(v))
459459
}
460-
(ty::ty_int(v), ty::ty_infer(IntVar(v_id))) => {
460+
(&ty::ty_int(v), &ty::ty_infer(IntVar(v_id))) => {
461461
unify_integral_variable(this, !this.a_is_expected(),
462462
v_id, IntType(v))
463463
}
464-
(ty::ty_infer(IntVar(v_id)), ty::ty_uint(v)) => {
464+
(&ty::ty_infer(IntVar(v_id)), &ty::ty_uint(v)) => {
465465
unify_integral_variable(this, this.a_is_expected(),
466466
v_id, UintType(v))
467467
}
468-
(ty::ty_uint(v), ty::ty_infer(IntVar(v_id))) => {
468+
(&ty::ty_uint(v), &ty::ty_infer(IntVar(v_id))) => {
469469
unify_integral_variable(this, !this.a_is_expected(),
470470
v_id, UintType(v))
471471
}
472472

473473
// Relate floating-point variables to other types
474-
(ty::ty_infer(FloatVar(a_id)), ty::ty_infer(FloatVar(b_id))) => {
474+
(&ty::ty_infer(FloatVar(a_id)), &ty::ty_infer(FloatVar(b_id))) => {
475475
if_ok!(this.infcx().simple_vars(this.a_is_expected(),
476476
a_id, b_id));
477477
Ok(a)
478478
}
479-
(ty::ty_infer(FloatVar(v_id)), ty::ty_float(v)) => {
479+
(&ty::ty_infer(FloatVar(v_id)), &ty::ty_float(v)) => {
480480
unify_float_variable(this, this.a_is_expected(), v_id, v)
481481
}
482-
(ty::ty_float(v), ty::ty_infer(FloatVar(v_id))) => {
482+
(&ty::ty_float(v), &ty::ty_infer(FloatVar(v_id))) => {
483483
unify_float_variable(this, !this.a_is_expected(), v_id, v)
484484
}
485485

486-
(ty::ty_nil, _) |
487-
(ty::ty_bool, _) |
488-
(ty::ty_int(_), _) |
489-
(ty::ty_uint(_), _) |
490-
(ty::ty_float(_), _) => {
486+
(&ty::ty_nil, _) |
487+
(&ty::ty_bool, _) |
488+
(&ty::ty_int(_), _) |
489+
(&ty::ty_uint(_), _) |
490+
(&ty::ty_float(_), _) => {
491491
if ty::get(a).sty == ty::get(b).sty {
492492
Ok(a)
493493
} else {
494494
Err(ty::terr_sorts(expected_found(this, a, b)))
495495
}
496496
}
497497

498-
(ty::ty_param(ref a_p), ty::ty_param(ref b_p)) if a_p.idx == b_p.idx => {
498+
(&ty::ty_param(ref a_p), &ty::ty_param(ref b_p)) if a_p.idx == b_p.idx => {
499499
Ok(a)
500500
}
501501

502-
(ty::ty_enum(a_id, ref a_substs),
503-
ty::ty_enum(b_id, ref b_substs))
502+
(&ty::ty_enum(a_id, ref a_substs),
503+
&ty::ty_enum(b_id, ref b_substs))
504504
if a_id == b_id => {
505505
let type_def = ty::lookup_item_type(tcx, a_id);
506506
do this.substs(&type_def.generics, a_substs, b_substs).chain |substs| {
507507
Ok(ty::mk_enum(tcx, a_id, substs))
508508
}
509509
}
510510

511-
(ty::ty_trait(a_id, ref a_substs, a_store, a_mutbl),
512-
ty::ty_trait(b_id, ref b_substs, b_store, b_mutbl))
511+
(&ty::ty_trait(a_id, ref a_substs, a_store, a_mutbl),
512+
&ty::ty_trait(b_id, ref b_substs, b_store, b_mutbl))
513513
if a_id == b_id && a_mutbl == b_mutbl => {
514514
let trait_def = ty::lookup_trait_def(tcx, a_id);
515515
do this.substs(&trait_def.generics, a_substs, b_substs).chain |substs| {
@@ -519,53 +519,53 @@ pub fn super_tys<C:Combine>(
519519
}
520520
}
521521

522-
(ty::ty_struct(a_id, ref a_substs), ty::ty_struct(b_id, ref b_substs))
522+
(&ty::ty_struct(a_id, ref a_substs), &ty::ty_struct(b_id, ref b_substs))
523523
if a_id == b_id => {
524524
let type_def = ty::lookup_item_type(tcx, a_id);
525525
do this.substs(&type_def.generics, a_substs, b_substs).chain |substs| {
526526
Ok(ty::mk_struct(tcx, a_id, substs))
527527
}
528528
}
529529

530-
(ty::ty_box(ref a_mt), ty::ty_box(ref b_mt)) => {
530+
(&ty::ty_box(ref a_mt), &ty::ty_box(ref b_mt)) => {
531531
do this.mts(a_mt, b_mt).chain |mt| {
532532
Ok(ty::mk_box(tcx, mt))
533533
}
534534
}
535535

536-
(ty::ty_uniq(ref a_mt), ty::ty_uniq(ref b_mt)) => {
536+
(&ty::ty_uniq(ref a_mt), &ty::ty_uniq(ref b_mt)) => {
537537
do this.mts(a_mt, b_mt).chain |mt| {
538538
Ok(ty::mk_uniq(tcx, mt))
539539
}
540540
}
541541

542-
(ty::ty_ptr(ref a_mt), ty::ty_ptr(ref b_mt)) => {
542+
(&ty::ty_ptr(ref a_mt), &ty::ty_ptr(ref b_mt)) => {
543543
do this.mts(a_mt, b_mt).chain |mt| {
544544
Ok(ty::mk_ptr(tcx, mt))
545545
}
546546
}
547547

548-
(ty::ty_rptr(a_r, ref a_mt), ty::ty_rptr(b_r, ref b_mt)) => {
548+
(&ty::ty_rptr(a_r, ref a_mt), &ty::ty_rptr(b_r, ref b_mt)) => {
549549
let r = if_ok!(this.contraregions(a_r, b_r));
550550
let mt = if_ok!(this.mts(a_mt, b_mt));
551551
Ok(ty::mk_rptr(tcx, r, mt))
552552
}
553553

554-
(ty::ty_evec(ref a_mt, vs_a), ty::ty_evec(ref b_mt, vs_b)) => {
554+
(&ty::ty_evec(ref a_mt, vs_a), &ty::ty_evec(ref b_mt, vs_b)) => {
555555
do this.mts(a_mt, b_mt).chain |mt| {
556556
do this.vstores(ty::terr_vec, vs_a, vs_b).chain |vs| {
557557
Ok(ty::mk_evec(tcx, mt, vs))
558558
}
559559
}
560560
}
561561

562-
(ty::ty_estr(vs_a), ty::ty_estr(vs_b)) => {
562+
(&ty::ty_estr(vs_a), &ty::ty_estr(vs_b)) => {
563563
do this.vstores(ty::terr_str, vs_a, vs_b).chain |vs| {
564564
Ok(ty::mk_estr(tcx,vs))
565565
}
566566
}
567567

568-
(ty::ty_tup(ref as_), ty::ty_tup(ref bs)) => {
568+
(&ty::ty_tup(ref as_), &ty::ty_tup(ref bs)) => {
569569
if as_.len() == bs.len() {
570570
map_vec2(*as_, *bs, |a, b| this.tys(*a, *b) )
571571
.chain(|ts| Ok(ty::mk_tup(tcx, ts)) )
@@ -575,13 +575,13 @@ pub fn super_tys<C:Combine>(
575575
}
576576
}
577577

578-
(ty::ty_bare_fn(ref a_fty), ty::ty_bare_fn(ref b_fty)) => {
578+
(&ty::ty_bare_fn(ref a_fty), &ty::ty_bare_fn(ref b_fty)) => {
579579
do this.bare_fn_tys(a_fty, b_fty).chain |fty| {
580580
Ok(ty::mk_bare_fn(tcx, fty))
581581
}
582582
}
583583

584-
(ty::ty_closure(ref a_fty), ty::ty_closure(ref b_fty)) => {
584+
(&ty::ty_closure(ref a_fty), &ty::ty_closure(ref b_fty)) => {
585585
do this.closure_tys(a_fty, b_fty).chain |fty| {
586586
Ok(ty::mk_closure(tcx, fty))
587587
}

0 commit comments

Comments
 (0)