Skip to content

Commit 3860eab

Browse files
toidiunikomatsakis
authored andcommitted
fix for late-bound regions
1 parent e5284b0 commit 3860eab

File tree

3 files changed

+45
-15
lines changed

3 files changed

+45
-15
lines changed

src/librustc_typeck/outlives/implicit_infer.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc::hir;
1212
use rustc::hir::def_id::DefId;
1313
use rustc::hir::itemlikevisit::ItemLikeVisitor;
1414
use rustc::ty::subst::{Kind, Subst, UnpackedKind};
15-
use rustc::ty::{self, Ty, TyCtxt};
15+
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
1616
use rustc::util::nodemap::FxHashMap;
1717

1818
use super::explicit::ExplicitPredicatesMap;
@@ -208,14 +208,26 @@ fn insert_required_predicates_to_be_wf<'tcx>(
208208
debug!("field_ty = {}", &field_ty);
209209
debug!("ty in field = {}", &ty);
210210
if let Some(ex_trait_ref) = obj.principal() {
211-
check_explicit_predicates(
212-
tcx,
213-
&ex_trait_ref.skip_binder().def_id,
214-
ex_trait_ref.with_self_ty(tcx, ty).skip_binder().substs,
215-
required_predicates,
216-
explicit_map,
217-
true,
218-
);
211+
// The method `has_escaping_regions` checks if
212+
// there are any late-bound regions, which is
213+
// the lifetime `'r`. It is safe to ignore
214+
// these since `'r` is not in scope for `Foo`.
215+
//
216+
// ```
217+
// struct Foo {
218+
// bar: for<'r> Fn(usize, &'r FnMut())
219+
// }
220+
// ```
221+
if !ty.has_escaping_regions() {
222+
check_explicit_predicates(
223+
tcx,
224+
&ex_trait_ref.skip_binder().def_id,
225+
ex_trait_ref.with_self_ty(tcx, ty).skip_binder().substs,
226+
required_predicates,
227+
explicit_map,
228+
true,
229+
);
230+
}
219231
}
220232
}
221233

src/librustc_typeck/outlives/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ fn inferred_outlives_of<'a, 'tcx>(
5959
ty::Predicate::TypeOutlives(p) => p.to_string(),
6060

6161
err => bug!("unexpected predicate {:?}", err),
62-
})
63-
.collect();
62+
}).collect();
6463
pred.sort();
6564

6665
let span = tcx.def_span(item_def_id);
@@ -117,11 +116,9 @@ fn inferred_outlives_crate<'tcx>(
117116
ty::Binder::bind(ty::OutlivesPredicate(region1, region2)),
118117
),
119118
},
120-
)
121-
.collect();
119+
).collect();
122120
(def_id, Lrc::new(vec))
123-
})
124-
.collect();
121+
}).collect();
125122

126123
let empty_predicate = Lrc::new(Vec::new());
127124

src/test/ui/issue-53419.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2012 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+
//compile-pass
12+
13+
#![feature(infer_outlives_requirements)]
14+
15+
struct Foo {
16+
bar: for<'r> Fn(usize, &'r FnMut())
17+
}
18+
19+
fn main() {
20+
}
21+

0 commit comments

Comments
 (0)