Replace assert_no_late_bound_regions with

`no_late_bound_regions().unwrap()`, which allows us to write code that
doesn't necessarily *fail* when there are higher-ranked trait bounds.
This commit is contained in:
Niko Matsakis 2015-02-13 17:23:45 -05:00
parent 92d65ab2e9
commit 48c70d6863
9 changed files with 30 additions and 26 deletions

View File

@ -838,7 +838,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
// the method call infrastructure should have
// replaced all late-bound regions with variables:
let self_ty = ty::ty_fn_sig(method_ty).input(0);
let self_ty = ty::assert_no_late_bound_regions(self.tcx(), &self_ty);
let self_ty = ty::no_late_bound_regions(self.tcx(), &self_ty).unwrap();
let (m, r) = match self_ty.sty {
ty::ty_rptr(r, ref m) => (m.mutbl, r),

View File

@ -905,8 +905,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
let base_cmt = match method_ty {
Some(method_ty) => {
let ref_ty =
ty::assert_no_late_bound_regions(
self.tcx(), &ty::ty_fn_ret(method_ty)).unwrap();
ty::no_late_bound_regions(
self.tcx(), &ty::ty_fn_ret(method_ty)).unwrap().unwrap();
self.cat_rvalue_node(node.id(), node.span(), ref_ty)
}
None => base_cmt
@ -996,7 +996,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
// FIXME(#20649) -- why are we using the `self_ty` as the element type...?
let self_ty = ty::ty_fn_sig(method_ty).input(0);
ty::assert_no_late_bound_regions(self.tcx(), &self_ty)
ty::no_late_bound_regions(self.tcx(), &self_ty).unwrap()
}
None => {
match ty::array_element_ty(self.tcx(), base_cmt.ty) {
@ -1336,8 +1336,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
// types are generated by method resolution and always have
// all late-bound regions fully instantiated, so we just want
// to skip past the binder.
ty::assert_no_late_bound_regions(self.tcx(), &ty::ty_fn_ret(method_ty))
.unwrap() // overloaded ops do not diverge, either
ty::no_late_bound_regions(self.tcx(), &ty::ty_fn_ret(method_ty))
.unwrap()
.unwrap() // overloaded ops do not diverge, either
}
}

View File

@ -4384,8 +4384,8 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
// overloaded deref operators have all late-bound
// regions fully instantiated and coverge
let fn_ret =
ty::assert_no_late_bound_regions(cx,
&ty_fn_ret(method_ty));
ty::no_late_bound_regions(cx,
&ty_fn_ret(method_ty)).unwrap();
adjusted_ty = fn_ret.unwrap();
}
None => {}
@ -5186,7 +5186,7 @@ impl<'tcx> VariantInfo<'tcx> {
let arg_tys = if args.len() > 0 {
// the regions in the argument types come from the
// enum def'n, and hence will all be early bound
ty::assert_no_late_bound_regions(cx, &ty_fn_args(ctor_ty))
ty::no_late_bound_regions(cx, &ty_fn_args(ctor_ty)).unwrap()
} else {
Vec::new()
};
@ -6677,14 +6677,17 @@ pub fn binds_late_bound_regions<'tcx, T>(
count_late_bound_regions(tcx, value) > 0
}
pub fn assert_no_late_bound_regions<'tcx, T>(
pub fn no_late_bound_regions<'tcx, T>(
tcx: &ty::ctxt<'tcx>,
value: &Binder<T>)
-> T
-> Option<T>
where T : TypeFoldable<'tcx> + Repr<'tcx> + Clone
{
assert!(!binds_late_bound_regions(tcx, value));
value.0.clone()
if binds_late_bound_regions(tcx, value) {
None
} else {
Some(value.0.clone())
}
}
/// Replace any late-bound regions bound in `value` with `'static`. Useful in trans but also

View File

@ -781,8 +781,8 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let ix_datum = unpack_datum!(bcx, trans(bcx, idx));
let ref_ty = // invoked methods have LB regions instantiated:
ty::assert_no_late_bound_regions(
bcx.tcx(), &ty::ty_fn_ret(method_ty)).unwrap();
ty::no_late_bound_regions(
bcx.tcx(), &ty::ty_fn_ret(method_ty)).unwrap().unwrap();
let elt_ty = match ty::deref(ref_ty, true) {
None => {
bcx.tcx().sess.span_bug(index_expr.span,
@ -2214,8 +2214,8 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
};
let ref_ty = // invoked methods have their LB regions instantiated
ty::assert_no_late_bound_regions(
ccx.tcx(), &ty::ty_fn_ret(method_ty)).unwrap();
ty::no_late_bound_regions(
ccx.tcx(), &ty::ty_fn_ret(method_ty)).unwrap().unwrap();
let scratch = rvalue_scratch_datum(bcx, ref_ty, "overloaded_deref");
unpack_result!(bcx, trans_overloaded_op(bcx, expr, method_call,

View File

@ -509,7 +509,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
let ctor_scheme = ty::lookup_item_type(tcx, enum_def);
let ctor_predicates = ty::lookup_predicates(tcx, enum_def);
let path_scheme = if ty::is_fn_ty(ctor_scheme.ty) {
let fn_ret = ty::assert_no_late_bound_regions(tcx, &ty::ty_fn_ret(ctor_scheme.ty));
let fn_ret = ty::no_late_bound_regions(tcx, &ty::ty_fn_ret(ctor_scheme.ty)).unwrap();
ty::TypeScheme {
ty: fn_ret.unwrap(),
generics: ctor_scheme.generics,

View File

@ -367,8 +367,8 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
// (This always bites me, should find a way to
// refactor it.)
let method_sig =
ty::assert_no_late_bound_regions(fcx.tcx(),
ty::ty_fn_sig(method_callee.ty));
ty::no_late_bound_regions(fcx.tcx(),
ty::ty_fn_sig(method_callee.ty)).unwrap();
debug!("attempt_resolution: method_callee={}",
method_callee.repr(fcx.tcx()));

View File

@ -2050,8 +2050,8 @@ fn make_overloaded_lvalue_return_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
match method {
Some(method) => {
let ref_ty = // invoked methods have all LB regions instantiated
ty::assert_no_late_bound_regions(
fcx.tcx(), &ty::ty_fn_ret(method.ty));
ty::no_late_bound_regions(
fcx.tcx(), &ty::ty_fn_ret(method.ty)).unwrap();
match method_call {
Some(method_call) => {
fcx.inh.method_map.borrow_mut().insert(method_call,

View File

@ -624,7 +624,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
constrain_call(rcx, expr, Some(&**base),
None::<ast::Expr>.iter(), true);
let fn_ret = // late-bound regions in overloaded method calls are instantiated
ty::assert_no_late_bound_regions(rcx.tcx(), &ty::ty_fn_ret(method.ty));
ty::no_late_bound_regions(rcx.tcx(), &ty::ty_fn_ret(method.ty)).unwrap();
fn_ret.unwrap()
}
None => rcx.resolve_node_type(base.id)
@ -971,7 +971,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
// was applied on the base type, as that is always the case.
let fn_sig = ty::ty_fn_sig(method.ty);
let fn_sig = // late-bound regions should have been instantiated
ty::assert_no_late_bound_regions(rcx.tcx(), fn_sig);
ty::no_late_bound_regions(rcx.tcx(), fn_sig).unwrap();
let self_ty = fn_sig.inputs[0];
let (m, r) = match self_ty.sty {
ty::ty_rptr(r, ref m) => (m.mutbl, r),

View File

@ -578,8 +578,8 @@ fn enum_variants<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
// the regions in the argument types come from the
// enum def'n, and hence will all be early bound
let arg_tys =
ty::assert_no_late_bound_regions(
fcx.tcx(), &ty::ty_fn_args(ctor_ty));
ty::no_late_bound_regions(
fcx.tcx(), &ty::ty_fn_args(ctor_ty)).unwrap();
AdtVariant {
fields: args.iter().enumerate().map(|(index, arg)| {
let arg_ty = arg_tys[index];