diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 5cc7502b512..8dbac7f515e 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -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), diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 6c295142c9f..6ce5fd07341 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -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 } } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 8618bde95fe..db8a6eef670 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -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 + -> Option 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 diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 480679f43cb..7a05cc55276 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -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, diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 81868f3695c..0d30741978a 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -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, diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 6a9d34d7637..7354ea7377c 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -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())); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 4c91db5a62c..ee8bf8b7627 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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, diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 72ea0961e05..ba150138aa7 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -624,7 +624,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) { constrain_call(rcx, expr, Some(&**base), None::.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), diff --git a/src/librustc_typeck/check/wf.rs b/src/librustc_typeck/check/wf.rs index 94670305be7..2adc809f7ac 100644 --- a/src/librustc_typeck/check/wf.rs +++ b/src/librustc_typeck/check/wf.rs @@ -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];