Skip to content

Commit df27ed8

Browse files
committed
---
yaml --- r: 177843 b: refs/heads/snap-stage3 c: f9f3ba5 h: refs/heads/master i: 177841: 3fd9a43 177839: 6b1c4e9 v: v3
1 parent 7ec1141 commit df27ed8

File tree

9 files changed

+67
-201
lines changed

9 files changed

+67
-201
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 474b324eda10440d6568ef872a7307d38e7de95b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 52c74e63dacd49017b19330e0cbecbac0a3fe62e
4+
refs/heads/snap-stage3: f9f3ba5920ddb2b8bae5047eea556081e0da159d
55
refs/heads/try: fde4472848b662a4d1236388c4cf15e2450237e6
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/librustc/middle/infer/mod.rs

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ use std::rc::Rc;
3333
use syntax::ast;
3434
use syntax::codemap;
3535
use syntax::codemap::Span;
36-
use util::common::indent;
3736
use util::nodemap::FnvHashMap;
3837
use util::ppaux::{ty_to_string};
3938
use util::ppaux::{Repr, UserString};
4039

41-
use self::coercion::Coerce;
4240
use self::combine::{Combine, Combineable, CombineFields};
4341
use self::region_inference::{RegionVarBindings, RegionSnapshot};
4442
use self::equate::Equate;
@@ -47,7 +45,6 @@ use self::lub::Lub;
4745
use self::unify::{UnificationTable, InferCtxtMethodsForSimplyUnifiableTypes};
4846
use self::error_reporting::ErrorReporting;
4947

50-
pub mod coercion;
5148
pub mod combine;
5249
pub mod doc;
5350
pub mod equate;
@@ -68,7 +65,6 @@ pub type Bound<T> = Option<T>;
6865
pub type cres<'tcx, T> = Result<T,ty::type_err<'tcx>>; // "combine result"
6966
pub type ures<'tcx> = cres<'tcx, ()>; // "unify result"
7067
pub type fres<T> = Result<T, fixup_err>; // "fixup result"
71-
pub type CoerceResult<'tcx> = cres<'tcx, Option<ty::AutoAdjustment<'tcx>>>;
7268

7369
pub struct InferCtxt<'a, 'tcx: 'a> {
7470
pub tcx: &'a ty::ctxt<'tcx>,
@@ -409,24 +405,6 @@ fn expected_found<T>(a_is_expected: bool,
409405
}
410406
}
411407

412-
pub fn mk_coercety<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
413-
a_is_expected: bool,
414-
origin: TypeOrigin,
415-
a: Ty<'tcx>,
416-
b: Ty<'tcx>)
417-
-> CoerceResult<'tcx> {
418-
debug!("mk_coercety({} -> {})", a.repr(cx.tcx), b.repr(cx.tcx));
419-
indent(|| {
420-
cx.commit_if_ok(|| {
421-
let trace = TypeTrace {
422-
origin: origin,
423-
values: Types(expected_found(a_is_expected, a, b))
424-
};
425-
Coerce(cx.combine_fields(a_is_expected, trace)).tys(a, b)
426-
})
427-
})
428-
}
429-
430408
trait then<'tcx> {
431409
fn then<T, F>(&self, f: F) -> Result<T, ty::type_err<'tcx>> where
432410
T: Clone,
@@ -689,10 +667,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
689667
{
690668
debug!("sub_types({} <: {})", a.repr(self.tcx), b.repr(self.tcx));
691669
self.commit_if_ok(|| {
692-
let trace = TypeTrace {
693-
origin: origin,
694-
values: Types(expected_found(a_is_expected, a, b))
695-
};
670+
let trace = TypeTrace::types(origin, a_is_expected, a, b);
696671
self.sub(a_is_expected, trace).tys(a, b).to_ures()
697672
})
698673
}
@@ -705,10 +680,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
705680
-> ures<'tcx>
706681
{
707682
self.commit_if_ok(|| {
708-
let trace = TypeTrace {
709-
origin: origin,
710-
values: Types(expected_found(a_is_expected, a, b))
711-
};
683+
let trace = TypeTrace::types(origin, a_is_expected, a, b);
712684
self.equate(a_is_expected, trace).tys(a, b).to_ures()
713685
})
714686
}
@@ -1118,6 +1090,17 @@ impl<'tcx> TypeTrace<'tcx> {
11181090
self.origin.span()
11191091
}
11201092

1093+
pub fn types(origin: TypeOrigin,
1094+
a_is_expected: bool,
1095+
a: Ty<'tcx>,
1096+
b: Ty<'tcx>)
1097+
-> TypeTrace<'tcx> {
1098+
TypeTrace {
1099+
origin: origin,
1100+
values: Types(expected_found(a_is_expected, a, b))
1101+
}
1102+
}
1103+
11211104
pub fn dummy(tcx: &ty::ctxt<'tcx>) -> TypeTrace<'tcx> {
11221105
TypeTrace {
11231106
origin: Misc(codemap::DUMMY_SP),

branches/snap-stage3/src/librustc_borrowck/borrowck/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,16 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
770770
MutabilityViolation => {
771771
"cannot assign to data"
772772
}
773-
BorrowViolation(euv::ClosureCapture(_)) |
773+
BorrowViolation(euv::ClosureCapture(_)) => {
774+
// I don't think we can get aliasability violations
775+
// with closure captures, so no need to come up with a
776+
// good error message. The reason this cannot happen
777+
// is because we only capture local variables in
778+
// closures, and those are never aliasable.
779+
self.tcx.sess.span_bug(
780+
span,
781+
"aliasability violation with closure");
782+
}
774783
BorrowViolation(euv::OverloadedOperator) |
775784
BorrowViolation(euv::AddrOf) |
776785
BorrowViolation(euv::AutoRef) |
@@ -800,17 +809,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
800809
self.tcx.sess.span_err(span,
801810
format!("{} in a captured outer \
802811
variable in an `Fn` closure", prefix).as_slice());
803-
if let BorrowViolation(euv::ClosureCapture(_)) = kind {
804-
// The aliasability violation with closure captures can
805-
// happen for nested closures, so we know the enclosing
806-
// closure incorrectly accepts an `Fn` while it needs to
807-
// be `FnMut`.
808-
span_help!(self.tcx.sess, self.tcx.map.span(id),
809-
"consider changing this to accept closures that implement `FnMut`");
810-
} else {
811-
span_help!(self.tcx.sess, self.tcx.map.span(id),
812+
span_help!(self.tcx.sess, self.tcx.map.span(id),
812813
"consider changing this closure to take self by mutable reference");
813-
}
814814
}
815815
mc::AliasableStatic(..) |
816816
mc::AliasableStaticMut(..) => {

branches/snap-stage3/src/librustc_trans/trans/expr.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,9 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
420420
let tcx = bcx.tcx();
421421

422422
let datum_ty = datum.ty;
423-
424-
debug!("unsize_unique_vec expr.id={} datum_ty={} len={}",
425-
expr.id, datum_ty.repr(tcx), len);
426-
427-
// We do not arrange cleanup ourselves; if we already are an
428-
// L-value, then cleanup will have already been scheduled (and
429-
// the `datum.store_to` call below will emit code to zero the
430-
// drop flag when moving out of the L-value). If we are an R-value,
431-
// then we do not need to schedule cleanup.
423+
// Arrange cleanup
424+
let lval = unpack_datum!(bcx,
425+
datum.to_lvalue_datum(bcx, "unsize_unique_vec", expr.id));
432426

433427
let ll_len = C_uint(bcx.ccx(), len);
434428
let unit_ty = ty::sequence_element_type(tcx, ty::type_content(datum_ty));
@@ -439,7 +433,7 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
439433
let base = PointerCast(bcx,
440434
base,
441435
type_of::type_of(bcx.ccx(), datum_ty).ptr_to());
442-
bcx = datum.store_to(bcx, base);
436+
bcx = lval.store_to(bcx, base);
443437

444438
Store(bcx, ll_len, get_len(bcx, scratch.val));
445439
DatumBlock::new(bcx, scratch.to_expr_datum())
@@ -461,20 +455,22 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
461455
};
462456
let result_ty = ty::mk_uniq(tcx, ty::unsize_ty(tcx, unboxed_ty, k, expr.span));
463457

464-
// We do not arrange cleanup ourselves; if we already are an
465-
// L-value, then cleanup will have already been scheduled (and
466-
// the `datum.store_to` call below will emit code to zero the
467-
// drop flag when moving out of the L-value). If we are an R-value,
468-
// then we do not need to schedule cleanup.
458+
let lval = unpack_datum!(bcx,
459+
datum.to_lvalue_datum(bcx, "unsize_unique_expr", expr.id));
469460

470461
let scratch = rvalue_scratch_datum(bcx, result_ty, "__uniq_fat_ptr");
471462
let llbox_ty = type_of::type_of(bcx.ccx(), datum_ty);
472463
let base = PointerCast(bcx, get_dataptr(bcx, scratch.val), llbox_ty.ptr_to());
473-
bcx = datum.store_to(bcx, base);
464+
bcx = lval.store_to(bcx, base);
474465

475466
let info = unsized_info(bcx, k, expr.id, unboxed_ty, |t| ty::mk_uniq(tcx, t));
476467
Store(bcx, info, get_len(bcx, scratch.val));
477468

469+
let scratch = unpack_datum!(bcx,
470+
scratch.to_expr_datum().to_lvalue_datum(bcx,
471+
"fresh_uniq_fat_ptr",
472+
expr.id));
473+
478474
DatumBlock::new(bcx, scratch.to_expr_datum())
479475
}
480476
}

branches/snap-stage3/src/librustc/middle/infer/coercion.rs renamed to branches/snap-stage3/src/librustc_typeck/check/coercion.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@
6060
//! sort of a minor point so I've opted to leave it for later---after all
6161
//! we may want to adjust precisely when coercions occur.
6262
63-
use super::{CoerceResult, Coercion};
64-
use super::combine::{CombineFields, Combine};
65-
use super::sub::Sub;
63+
use middle::infer::{cres, Coercion, InferCtxt, TypeOrigin, TypeTrace};
64+
use middle::infer::combine::{CombineFields, Combine};
65+
use middle::infer::sub::Sub;
6666

6767
use middle::subst;
6868
use middle::ty::{AutoPtr, AutoDerefRef, AdjustDerefRef, AutoUnsize, AutoUnsafe};
6969
use middle::ty::{mt};
7070
use middle::ty::{self, Ty};
71+
use util::common::indent;
7172
use util::ppaux;
7273
use util::ppaux::Repr;
7374

@@ -472,24 +473,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
472473
}
473474
}
474475

475-
pub fn coerce_borrowed_fn(&self,
476-
a: Ty<'tcx>,
477-
b: Ty<'tcx>)
478-
-> CoerceResult<'tcx> {
479-
debug!("coerce_borrowed_fn(a={}, b={})",
480-
a.repr(self.tcx()),
481-
b.repr(self.tcx()));
482-
483-
match a.sty {
484-
ty::ty_bare_fn(Some(a_def_id), f) => {
485-
self.coerce_from_fn_item(a, a_def_id, f, b)
486-
}
487-
_ => {
488-
self.subtype(a, b)
489-
}
490-
}
491-
}
492-
493476
fn coerce_from_fn_item(&self,
494477
a: Ty<'tcx>,
495478
fn_def_id_a: ast::DefId,
@@ -551,6 +534,23 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
551534
}
552535
}
553536

537+
pub type CoerceResult<'tcx> = cres<'tcx, Option<ty::AutoAdjustment<'tcx>>>;
538+
539+
pub fn mk_coercety<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
540+
a_is_expected: bool,
541+
origin: TypeOrigin,
542+
a: Ty<'tcx>,
543+
b: Ty<'tcx>)
544+
-> CoerceResult<'tcx> {
545+
debug!("mk_coercety({} -> {})", a.repr(cx.tcx), b.repr(cx.tcx));
546+
indent(|| {
547+
cx.commit_if_ok(|| {
548+
let trace = TypeTrace::types(origin, a_is_expected, a, b);
549+
Coerce(cx.combine_fields(a_is_expected, trace)).tys(a, b)
550+
})
551+
})
552+
}
553+
554554
fn can_coerce_mutbls(from_mutbl: ast::Mutability,
555555
to_mutbl: ast::Mutability)
556556
-> bool {

branches/snap-stage3/src/librustc_typeck/check/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub mod vtable;
132132
pub mod writeback;
133133
pub mod regionmanip;
134134
pub mod regionck;
135+
pub mod coercion;
135136
pub mod demand;
136137
pub mod method;
137138
mod upvar;
@@ -1730,18 +1731,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17301731
sub: Ty<'tcx>,
17311732
sup: Ty<'tcx>)
17321733
-> Result<(), ty::type_err<'tcx>> {
1733-
match infer::mk_coercety(self.infcx(),
1734-
false,
1735-
infer::ExprAssignable(expr.span),
1736-
sub,
1737-
sup) {
1738-
Ok(None) => Ok(()),
1739-
Err(ref e) => Err((*e)),
1740-
Ok(Some(adjustment)) => {
1734+
match try!(coercion::mk_coercety(self.infcx(),
1735+
false,
1736+
infer::ExprAssignable(expr.span),
1737+
sub,
1738+
sup)) {
1739+
None => {}
1740+
Some(adjustment) => {
17411741
self.write_adjustment(expr.id, expr.span, adjustment);
1742-
Ok(())
17431742
}
17441743
}
1744+
Ok(())
17451745
}
17461746

17471747
pub fn mk_eqty(&self,

branches/snap-stage3/src/test/compile-fail/issue-21600.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

branches/snap-stage3/src/test/run-pass/issue-20055-box-trait.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)