Skip to content

Commit 48c70d6

Browse files
committed
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.
1 parent 92d65ab commit 48c70d6

File tree

9 files changed

+30
-26
lines changed

9 files changed

+30
-26
lines changed

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
838838
// the method call infrastructure should have
839839
// replaced all late-bound regions with variables:
840840
let self_ty = ty::ty_fn_sig(method_ty).input(0);
841-
let self_ty = ty::assert_no_late_bound_regions(self.tcx(), &self_ty);
841+
let self_ty = ty::no_late_bound_regions(self.tcx(), &self_ty).unwrap();
842842

843843
let (m, r) = match self_ty.sty {
844844
ty::ty_rptr(r, ref m) => (m.mutbl, r),

src/librustc/middle/mem_categorization.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
905905
let base_cmt = match method_ty {
906906
Some(method_ty) => {
907907
let ref_ty =
908-
ty::assert_no_late_bound_regions(
909-
self.tcx(), &ty::ty_fn_ret(method_ty)).unwrap();
908+
ty::no_late_bound_regions(
909+
self.tcx(), &ty::ty_fn_ret(method_ty)).unwrap().unwrap();
910910
self.cat_rvalue_node(node.id(), node.span(), ref_ty)
911911
}
912912
None => base_cmt
@@ -996,7 +996,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
996996

997997
// FIXME(#20649) -- why are we using the `self_ty` as the element type...?
998998
let self_ty = ty::ty_fn_sig(method_ty).input(0);
999-
ty::assert_no_late_bound_regions(self.tcx(), &self_ty)
999+
ty::no_late_bound_regions(self.tcx(), &self_ty).unwrap()
10001000
}
10011001
None => {
10021002
match ty::array_element_ty(self.tcx(), base_cmt.ty) {
@@ -1336,8 +1336,9 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
13361336
// types are generated by method resolution and always have
13371337
// all late-bound regions fully instantiated, so we just want
13381338
// to skip past the binder.
1339-
ty::assert_no_late_bound_regions(self.tcx(), &ty::ty_fn_ret(method_ty))
1340-
.unwrap() // overloaded ops do not diverge, either
1339+
ty::no_late_bound_regions(self.tcx(), &ty::ty_fn_ret(method_ty))
1340+
.unwrap()
1341+
.unwrap() // overloaded ops do not diverge, either
13411342
}
13421343
}
13431344

src/librustc/middle/ty.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4384,8 +4384,8 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
43844384
// overloaded deref operators have all late-bound
43854385
// regions fully instantiated and coverge
43864386
let fn_ret =
4387-
ty::assert_no_late_bound_regions(cx,
4388-
&ty_fn_ret(method_ty));
4387+
ty::no_late_bound_regions(cx,
4388+
&ty_fn_ret(method_ty)).unwrap();
43894389
adjusted_ty = fn_ret.unwrap();
43904390
}
43914391
None => {}
@@ -5186,7 +5186,7 @@ impl<'tcx> VariantInfo<'tcx> {
51865186
let arg_tys = if args.len() > 0 {
51875187
// the regions in the argument types come from the
51885188
// enum def'n, and hence will all be early bound
5189-
ty::assert_no_late_bound_regions(cx, &ty_fn_args(ctor_ty))
5189+
ty::no_late_bound_regions(cx, &ty_fn_args(ctor_ty)).unwrap()
51905190
} else {
51915191
Vec::new()
51925192
};
@@ -6677,14 +6677,17 @@ pub fn binds_late_bound_regions<'tcx, T>(
66776677
count_late_bound_regions(tcx, value) > 0
66786678
}
66796679

6680-
pub fn assert_no_late_bound_regions<'tcx, T>(
6680+
pub fn no_late_bound_regions<'tcx, T>(
66816681
tcx: &ty::ctxt<'tcx>,
66826682
value: &Binder<T>)
6683-
-> T
6683+
-> Option<T>
66846684
where T : TypeFoldable<'tcx> + Repr<'tcx> + Clone
66856685
{
6686-
assert!(!binds_late_bound_regions(tcx, value));
6687-
value.0.clone()
6686+
if binds_late_bound_regions(tcx, value) {
6687+
None
6688+
} else {
6689+
Some(value.0.clone())
6690+
}
66886691
}
66896692

66906693
/// Replace any late-bound regions bound in `value` with `'static`. Useful in trans but also

src/librustc_trans/trans/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,8 @@ fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
781781
let ix_datum = unpack_datum!(bcx, trans(bcx, idx));
782782

783783
let ref_ty = // invoked methods have LB regions instantiated:
784-
ty::assert_no_late_bound_regions(
785-
bcx.tcx(), &ty::ty_fn_ret(method_ty)).unwrap();
784+
ty::no_late_bound_regions(
785+
bcx.tcx(), &ty::ty_fn_ret(method_ty)).unwrap().unwrap();
786786
let elt_ty = match ty::deref(ref_ty, true) {
787787
None => {
788788
bcx.tcx().sess.span_bug(index_expr.span,
@@ -2214,8 +2214,8 @@ fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
22142214
};
22152215

22162216
let ref_ty = // invoked methods have their LB regions instantiated
2217-
ty::assert_no_late_bound_regions(
2218-
ccx.tcx(), &ty::ty_fn_ret(method_ty)).unwrap();
2217+
ty::no_late_bound_regions(
2218+
ccx.tcx(), &ty::ty_fn_ret(method_ty)).unwrap().unwrap();
22192219
let scratch = rvalue_scratch_datum(bcx, ref_ty, "overloaded_deref");
22202220

22212221
unpack_result!(bcx, trans_overloaded_op(bcx, expr, method_call,

src/librustc_typeck/check/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
509509
let ctor_scheme = ty::lookup_item_type(tcx, enum_def);
510510
let ctor_predicates = ty::lookup_predicates(tcx, enum_def);
511511
let path_scheme = if ty::is_fn_ty(ctor_scheme.ty) {
512-
let fn_ret = ty::assert_no_late_bound_regions(tcx, &ty::ty_fn_ret(ctor_scheme.ty));
512+
let fn_ret = ty::no_late_bound_regions(tcx, &ty::ty_fn_ret(ctor_scheme.ty)).unwrap();
513513
ty::TypeScheme {
514514
ty: fn_ret.unwrap(),
515515
generics: ctor_scheme.generics,

src/librustc_typeck/check/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,8 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
367367
// (This always bites me, should find a way to
368368
// refactor it.)
369369
let method_sig =
370-
ty::assert_no_late_bound_regions(fcx.tcx(),
371-
ty::ty_fn_sig(method_callee.ty));
370+
ty::no_late_bound_regions(fcx.tcx(),
371+
ty::ty_fn_sig(method_callee.ty)).unwrap();
372372

373373
debug!("attempt_resolution: method_callee={}",
374374
method_callee.repr(fcx.tcx()));

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,8 +2050,8 @@ fn make_overloaded_lvalue_return_type<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
20502050
match method {
20512051
Some(method) => {
20522052
let ref_ty = // invoked methods have all LB regions instantiated
2053-
ty::assert_no_late_bound_regions(
2054-
fcx.tcx(), &ty::ty_fn_ret(method.ty));
2053+
ty::no_late_bound_regions(
2054+
fcx.tcx(), &ty::ty_fn_ret(method.ty)).unwrap();
20552055
match method_call {
20562056
Some(method_call) => {
20572057
fcx.inh.method_map.borrow_mut().insert(method_call,

src/librustc_typeck/check/regionck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
624624
constrain_call(rcx, expr, Some(&**base),
625625
None::<ast::Expr>.iter(), true);
626626
let fn_ret = // late-bound regions in overloaded method calls are instantiated
627-
ty::assert_no_late_bound_regions(rcx.tcx(), &ty::ty_fn_ret(method.ty));
627+
ty::no_late_bound_regions(rcx.tcx(), &ty::ty_fn_ret(method.ty)).unwrap();
628628
fn_ret.unwrap()
629629
}
630630
None => rcx.resolve_node_type(base.id)
@@ -971,7 +971,7 @@ fn constrain_autoderefs<'a, 'tcx>(rcx: &mut Rcx<'a, 'tcx>,
971971
// was applied on the base type, as that is always the case.
972972
let fn_sig = ty::ty_fn_sig(method.ty);
973973
let fn_sig = // late-bound regions should have been instantiated
974-
ty::assert_no_late_bound_regions(rcx.tcx(), fn_sig);
974+
ty::no_late_bound_regions(rcx.tcx(), fn_sig).unwrap();
975975
let self_ty = fn_sig.inputs[0];
976976
let (m, r) = match self_ty.sty {
977977
ty::ty_rptr(r, ref m) => (m.mutbl, r),

src/librustc_typeck/check/wf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ fn enum_variants<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
578578
// the regions in the argument types come from the
579579
// enum def'n, and hence will all be early bound
580580
let arg_tys =
581-
ty::assert_no_late_bound_regions(
582-
fcx.tcx(), &ty::ty_fn_args(ctor_ty));
581+
ty::no_late_bound_regions(
582+
fcx.tcx(), &ty::ty_fn_args(ctor_ty)).unwrap();
583583
AdtVariant {
584584
fields: args.iter().enumerate().map(|(index, arg)| {
585585
let arg_ty = arg_tys[index];

0 commit comments

Comments
 (0)