Skip to content

Commit cb33248

Browse files
committed
use usize for self instead of ty
1 parent 3860eab commit cb33248

File tree

1 file changed

+24
-31
lines changed

1 file changed

+24
-31
lines changed

src/librustc_typeck/outlives/implicit_infer.rs

+24-31
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, TypeFoldable};
15+
use rustc::ty::{self, Ty, TyCtxt};
1616
use rustc::util::nodemap::FxHashMap;
1717

1818
use super::explicit::ExplicitPredicatesMap;
@@ -191,43 +191,35 @@ fn insert_required_predicates_to_be_wf<'tcx>(
191191
substs,
192192
required_predicates,
193193
explicit_map,
194-
false,
194+
IgnoreSelfTy(false),
195195
);
196196
}
197197

198198
ty::Dynamic(obj, ..) => {
199199
// This corresponds to `dyn Trait<..>`. In this case, we should
200200
// use the explicit predicates as well.
201201

202-
// We are passing type `ty` as a placeholder value with the function
203-
// `with_self_ty`, since there is no concrete type `Self` for a
204-
// `dyn Trait` at this stage. Therefore when checking explicit
205-
// predicates in `check_explicit_predicates` we need to ignore
206-
// checking the explicit_map for Self type.
207202
debug!("Dynamic");
208203
debug!("field_ty = {}", &field_ty);
209204
debug!("ty in field = {}", &ty);
210205
if let Some(ex_trait_ref) = obj.principal() {
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-
}
206+
// Here, we are passing the type `usize` as a
207+
// placeholder value with the function
208+
// `with_self_ty`, since there is no concrete type
209+
// `Self` for a `dyn Trait` at this
210+
// stage. Therefore when checking explicit
211+
// predicates in `check_explicit_predicates` we
212+
// need to ignore checking the explicit_map for
213+
// Self type.
214+
let substs = ex_trait_ref.with_self_ty(tcx, tcx.types.usize).skip_binder().substs;
215+
check_explicit_predicates(
216+
tcx,
217+
&ex_trait_ref.skip_binder().def_id,
218+
substs,
219+
required_predicates,
220+
explicit_map,
221+
IgnoreSelfTy(true),
222+
);
231223
}
232224
}
233225

@@ -241,7 +233,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
241233
obj.substs,
242234
required_predicates,
243235
explicit_map,
244-
false,
236+
IgnoreSelfTy(false),
245237
);
246238
}
247239

@@ -250,6 +242,8 @@ fn insert_required_predicates_to_be_wf<'tcx>(
250242
}
251243
}
252244

245+
pub struct IgnoreSelfTy(bool);
246+
253247
/// We also have to check the explicit predicates
254248
/// declared on the type.
255249
///
@@ -271,7 +265,7 @@ pub fn check_explicit_predicates<'tcx>(
271265
substs: &[Kind<'tcx>],
272266
required_predicates: &mut RequiredPredicates<'tcx>,
273267
explicit_map: &mut ExplicitPredicatesMap<'tcx>,
274-
ignore_self_ty: bool,
268+
ignore_self_ty: IgnoreSelfTy,
275269
) {
276270
debug!("def_id = {:?}", &def_id);
277271
debug!("substs = {:?}", &substs);
@@ -309,7 +303,7 @@ pub fn check_explicit_predicates<'tcx>(
309303
// to apply the substs, and not filter this predicate, we might then falsely
310304
// conclude that e.g. `X: 'x` was a reasonable inferred requirement.
311305
if let UnpackedKind::Type(ty) = outlives_predicate.0.unpack() {
312-
if ty.is_self() && ignore_self_ty {
306+
if ty.is_self() && ignore_self_ty.0 {
313307
debug!("skipping self ty = {:?}", &ty);
314308
continue;
315309
}
@@ -319,5 +313,4 @@ pub fn check_explicit_predicates<'tcx>(
319313
debug!("predicate = {:?}", &predicate);
320314
insert_outlives_predicate(tcx, predicate.0.into(), predicate.1, required_predicates);
321315
}
322-
// }
323316
}

0 commit comments

Comments
 (0)