Skip to content

Commit b2085d9

Browse files
committed
auto merge of #20527 : nikomatsakis/rust/japaric-boxed-uc-ice-fix, r=aturon
This fixes an ICE that japaric was encountering in the wf checker. r? @aturon
2 parents 260e461 + 537139e commit b2085d9

File tree

3 files changed

+58
-18
lines changed

3 files changed

+58
-18
lines changed

src/librustc/middle/ty_fold.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ pub trait TypeFolder<'tcx> : Sized {
7070
/// track the Debruijn index nesting level.
7171
fn exit_region_binder(&mut self) { }
7272

73+
fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T>
74+
where T : TypeFoldable<'tcx> + Repr<'tcx>
75+
{
76+
// FIXME(#20526) this should replace `enter_region_binder`/`exit_region_binder`.
77+
super_fold_binder(self, t)
78+
}
79+
7380
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
7481
super_fold_ty(self, t)
7582
}
@@ -183,12 +190,9 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
183190
}
184191
}
185192

186-
impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
193+
impl<'tcx, T:TypeFoldable<'tcx>+Repr<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
187194
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Binder<T> {
188-
folder.enter_region_binder();
189-
let result = ty::Binder(self.0.fold_with(folder));
190-
folder.exit_region_binder();
191-
result
195+
folder.fold_binder(self)
192196
}
193197
}
194198

@@ -556,6 +560,17 @@ impl<'tcx> TypeFoldable<'tcx> for ty::UnboxedClosureUpvar<'tcx> {
556560
//
557561
// They should invoke `foo.fold_with()` to do recursive folding.
558562

563+
pub fn super_fold_binder<'tcx, T, U>(this: &mut T,
564+
binder: &ty::Binder<U>)
565+
-> ty::Binder<U>
566+
where T : TypeFolder<'tcx>, U : TypeFoldable<'tcx>
567+
{
568+
this.enter_region_binder();
569+
let result = ty::Binder(binder.0.fold_with(this));
570+
this.exit_region_binder();
571+
result
572+
}
573+
559574
pub fn super_fold_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T,
560575
ty: Ty<'tcx>)
561576
-> Ty<'tcx> {

src/librustc_typeck/check/wf.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,18 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
301301
self.fcx.tcx()
302302
}
303303

304+
fn fold_binder<T>(&mut self, binder: &ty::Binder<T>) -> ty::Binder<T>
305+
where T : TypeFoldable<'tcx> + Repr<'tcx>
306+
{
307+
self.binding_count += 1;
308+
let value = liberate_late_bound_regions(self.fcx.tcx(), self.scope, binder);
309+
debug!("BoundsChecker::fold_binder: late-bound regions replaced: {}",
310+
value.repr(self.tcx()));
311+
let value = value.fold_with(self);
312+
self.binding_count -= 1;
313+
ty::Binder(value)
314+
}
315+
304316
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
305317
debug!("BoundsChecker t={}",
306318
t.repr(self.tcx()));
@@ -361,19 +373,6 @@ impl<'cx,'tcx> TypeFolder<'tcx> for BoundsChecker<'cx,'tcx> {
361373

362374
self.fold_substs(substs);
363375
}
364-
ty::ty_bare_fn(_, &ty::BareFnTy{sig: ref fn_sig, ..}) |
365-
ty::ty_closure(box ty::ClosureTy{sig: ref fn_sig, ..}) => {
366-
self.binding_count += 1;
367-
368-
let fn_sig = liberate_late_bound_regions(self.fcx.tcx(), self.scope, fn_sig);
369-
370-
debug!("late-bound regions replaced: {}",
371-
fn_sig.repr(self.tcx()));
372-
373-
self.fold_fn_sig(&fn_sig);
374-
375-
self.binding_count -= 1;
376-
}
377376
_ => {
378377
super_fold_ty(self, t);
379378
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that the `wf` checker properly handles bound regions in object
12+
// types. Compiling this code used to trigger an ICE.
13+
14+
pub struct Context<'tcx> {
15+
vec: &'tcx Vec<int>
16+
}
17+
18+
pub type Cmd<'a> = &'a int;
19+
20+
pub type DecodeInlinedItem<'a> =
21+
Box<for<'tcx> FnMut(Cmd, &Context<'tcx>) -> Result<&'tcx int, ()> + 'a>;
22+
23+
fn foo(d: DecodeInlinedItem) {
24+
}
25+
26+
fn main() { }

0 commit comments

Comments
 (0)