Skip to content

Commit eddf89b

Browse files
committed
---
yaml --- r: 178462 b: refs/heads/try c: a9d465f h: refs/heads/master v: v3
1 parent 502b1c5 commit eddf89b

File tree

17 files changed

+372
-499
lines changed

17 files changed

+372
-499
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 336c8d2e9c6b276b162bdb3edd43706372e6eddd
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 474b324eda10440d6568ef872a7307d38e7de95b
5-
refs/heads/try: e0f5980ead4f88e78a47f4d84da4dc11472f66ba
5+
refs/heads/try: a9d465fec902588b71937de96e66d160d2adebf5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ mod array;
147147
mod core {
148148
pub use panicking;
149149
pub use fmt;
150+
pub use ops;
150151
}
151152

152153
#[doc(hidden)]

branches/try/src/librustc_typeck/check/coercion.rs renamed to branches/try/src/librustc/middle/infer/coercion.rs

Lines changed: 202 additions & 126 deletions
Large diffs are not rendered by default.

branches/try/src/librustc/middle/infer/mod.rs

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

41+
use self::coercion::Coerce;
4042
use self::combine::{Combine, Combineable, CombineFields};
4143
use self::region_inference::{RegionVarBindings, RegionSnapshot};
4244
use self::equate::Equate;
@@ -45,6 +47,7 @@ use self::lub::Lub;
4547
use self::unify::{UnificationTable, InferCtxtMethodsForSimplyUnifiableTypes};
4648
use self::error_reporting::ErrorReporting;
4749

50+
pub mod coercion;
4851
pub mod combine;
4952
pub mod doc;
5053
pub mod equate;
@@ -65,6 +68,7 @@ pub type Bound<T> = Option<T>;
6568
pub type cres<'tcx, T> = Result<T,ty::type_err<'tcx>>; // "combine result"
6669
pub type ures<'tcx> = cres<'tcx, ()>; // "unify result"
6770
pub type fres<T> = Result<T, fixup_err>; // "fixup result"
71+
pub type CoerceResult<'tcx> = cres<'tcx, Option<ty::AutoAdjustment<'tcx>>>;
6872

6973
pub struct InferCtxt<'a, 'tcx: 'a> {
7074
pub tcx: &'a ty::ctxt<'tcx>,
@@ -405,6 +409,24 @@ fn expected_found<T>(a_is_expected: bool,
405409
}
406410
}
407411

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+
408430
trait then<'tcx> {
409431
fn then<T, F>(&self, f: F) -> Result<T, ty::type_err<'tcx>> where
410432
T: Clone,
@@ -667,7 +689,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
667689
{
668690
debug!("sub_types({} <: {})", a.repr(self.tcx), b.repr(self.tcx));
669691
self.commit_if_ok(|| {
670-
let trace = TypeTrace::types(origin, a_is_expected, a, b);
692+
let trace = TypeTrace {
693+
origin: origin,
694+
values: Types(expected_found(a_is_expected, a, b))
695+
};
671696
self.sub(a_is_expected, trace).tys(a, b).to_ures()
672697
})
673698
}
@@ -680,7 +705,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
680705
-> ures<'tcx>
681706
{
682707
self.commit_if_ok(|| {
683-
let trace = TypeTrace::types(origin, a_is_expected, a, b);
708+
let trace = TypeTrace {
709+
origin: origin,
710+
values: Types(expected_found(a_is_expected, a, b))
711+
};
684712
self.equate(a_is_expected, trace).tys(a, b).to_ures()
685713
})
686714
}
@@ -1090,17 +1118,6 @@ impl<'tcx> TypeTrace<'tcx> {
10901118
self.origin.span()
10911119
}
10921120

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-
11041121
pub fn dummy(tcx: &ty::ctxt<'tcx>) -> TypeTrace<'tcx> {
11051122
TypeTrace {
11061123
origin: Misc(codemap::DUMMY_SP),

branches/try/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/try/src/librustc_typeck/check/callee.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use super::LvaluePreference;
2121
use super::method;
2222
use super::structurally_resolved_type;
2323
use super::TupleArgumentsFlag;
24-
use super::UnresolvedTypeAction;
2524
use super::write_call;
2625

2726
use middle::infer;
@@ -78,7 +77,6 @@ pub fn check_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
7877
callee_expr.span,
7978
original_callee_ty,
8079
Some(callee_expr),
81-
UnresolvedTypeAction::Error,
8280
LvaluePreference::NoPreference,
8381
|adj_ty, idx| {
8482
let autoderefref = ty::AutoDerefRef { autoderefs: idx, autoref: None };

branches/try/src/librustc_typeck/check/demand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111

12-
use check::{coercion, FnCtxt};
12+
use check::FnCtxt;
1313
use middle::ty::{self, Ty};
1414
use middle::infer;
1515

@@ -62,7 +62,7 @@ pub fn coerce<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
6262
expr_ty.repr(fcx.ccx.tcx));
6363
let expr_ty = fcx.resolve_type_vars_if_possible(expr_ty);
6464
let expected = fcx.resolve_type_vars_if_possible(expected);
65-
match coercion::mk_assignty(fcx, expr, expr_ty, expected) {
65+
match fcx.mk_assignty(expr, expr_ty, expected) {
6666
Ok(()) => { /* ok */ }
6767
Err(ref err) => {
6868
fcx.report_mismatched_types(sp, expected, expr_ty, err);

branches/try/src/librustc_typeck/check/method/confirm.rs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use super::probe;
1212

1313
use check::{self, FnCtxt, NoPreference, PreferMutLvalue, callee, demand};
14-
use check::UnresolvedTypeAction;
1514
use middle::mem_categorization::Typer;
1615
use middle::subst::{self};
1716
use middle::traits;
@@ -142,19 +141,10 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
142141

143142
// Commit the autoderefs by calling `autoderef again, but this
144143
// time writing the results into the various tables.
145-
let (autoderefd_ty, n, result) = check::autoderef(self.fcx,
146-
self.span,
147-
unadjusted_self_ty,
148-
Some(self.self_expr),
149-
UnresolvedTypeAction::Error,
150-
NoPreference,
151-
|_, n| {
152-
if n == auto_deref_ref.autoderefs {
153-
Some(())
154-
} else {
155-
None
156-
}
157-
});
144+
let (autoderefd_ty, n, result) =
145+
check::autoderef(
146+
self.fcx, self.span, unadjusted_self_ty, Some(self.self_expr), NoPreference,
147+
|_, n| if n == auto_deref_ref.autoderefs { Some(()) } else { None });
158148
assert_eq!(n, auto_deref_ref.autoderefs);
159149
assert_eq!(result, Some(()));
160150

@@ -312,18 +302,15 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
312302
// yield an object-type (e.g., `&Object` or `Box<Object>`
313303
// etc).
314304

315-
let (_, _, result) = check::autoderef(self.fcx,
316-
self.span,
317-
self_ty,
318-
None,
319-
UnresolvedTypeAction::Error,
320-
NoPreference,
321-
|ty, _| {
322-
match ty.sty {
323-
ty::ty_trait(ref data) => Some(closure(self, ty, &**data)),
324-
_ => None,
325-
}
326-
});
305+
let (_, _, result) =
306+
check::autoderef(
307+
self.fcx, self.span, self_ty, None, NoPreference,
308+
|ty, _| {
309+
match ty.sty {
310+
ty::ty_trait(ref data) => Some(closure(self, ty, &**data)),
311+
_ => None,
312+
}
313+
});
327314

328315
match result {
329316
Some(r) => r,
@@ -530,7 +517,6 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
530517
expr.span,
531518
self.fcx.expr_ty(expr),
532519
Some(expr),
533-
UnresolvedTypeAction::Error,
534520
PreferMutLvalue,
535521
|_, autoderefs| {
536522
if autoderefs == autoderef_count + 1 {

branches/try/src/librustc_typeck/check/method/probe.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use super::{CandidateSource,ImplSource,TraitSource};
1414
use super::suggest;
1515

1616
use check;
17-
use check::{FnCtxt, NoPreference, UnresolvedTypeAction};
17+
use check::{FnCtxt, NoPreference};
1818
use middle::fast_reject;
1919
use middle::subst;
2020
use middle::subst::Subst;
@@ -169,19 +169,16 @@ fn create_steps<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
169169
-> Option<Vec<CandidateStep<'tcx>>> {
170170
let mut steps = Vec::new();
171171

172-
let (final_ty, dereferences, _) = check::autoderef(fcx,
173-
span,
174-
self_ty,
175-
None,
176-
UnresolvedTypeAction::Error,
177-
NoPreference,
178-
|t, d| {
179-
let adjustment = AutoDeref(d);
180-
steps.push(CandidateStep { self_ty: t, adjustment: adjustment });
181-
None::<()> // keep iterating until we can't anymore
182-
});
183-
184-
match final_ty.sty {
172+
let (fully_dereferenced_ty, dereferences, _) =
173+
check::autoderef(
174+
fcx, span, self_ty, None, NoPreference,
175+
|t, d| {
176+
let adjustment = AutoDeref(d);
177+
steps.push(CandidateStep { self_ty: t, adjustment: adjustment });
178+
None::<()> // keep iterating until we can't anymore
179+
});
180+
181+
match fully_dereferenced_ty.sty {
185182
ty::ty_vec(elem_ty, Some(len)) => {
186183
steps.push(CandidateStep {
187184
self_ty: ty::mk_vec(fcx.tcx(), elem_ty, None),

0 commit comments

Comments
 (0)