1
Fork 0

Track bound vars

This commit is contained in:
Jack Huey 2020-10-05 20:41:46 -04:00
parent 62a49c3bb8
commit 30187c81f6
33 changed files with 478 additions and 362 deletions

View file

@ -658,7 +658,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self_ty,
trait_ref.path.segments.last().unwrap(),
);
let poly_trait_ref = ty::Binder::bind(ty::TraitRef::new(trait_def_id, substs));
let poly_trait_ref = ty::Binder::bind(ty::TraitRef::new(trait_def_id, substs), self.tcx());
bounds.trait_bounds.push((poly_trait_ref, span, constness));
@ -741,7 +741,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
false,
Some(self_ty),
);
let poly_trait_ref = ty::Binder::bind(ty::TraitRef::new(trait_def_id, substs));
let poly_trait_ref = ty::Binder::bind(ty::TraitRef::new(trait_def_id, substs), self.tcx());
bounds.trait_bounds.push((poly_trait_ref, span, Constness::NotConst));
let mut dup_bindings = FxHashMap::default();
@ -878,9 +878,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.instantiate_lang_item_trait_ref(
*lang_item, *span, *hir_id, args, param_ty, bounds,
),
hir::GenericBound::Outlives(ref l) => bounds
.region_bounds
.push((ty::Binder::bind(self.ast_region_to_region(l, None)), l.span)),
hir::GenericBound::Outlives(ref l) => bounds.region_bounds.push((
ty::Binder::bind(self.ast_region_to_region(l, None), self.tcx()),
l.span,
)),
}
}
}
@ -1664,7 +1665,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
};
self.one_bound_for_assoc_type(
|| traits::supertraits(tcx, ty::Binder::bind(trait_ref)),
|| traits::supertraits(tcx, ty::Binder::bind(trait_ref, tcx)),
|| "Self".to_string(),
assoc_ident,
span,
@ -2368,8 +2369,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!("ty_of_fn: output_ty={:?}", output_ty);
let bare_fn_ty =
ty::Binder::bind(tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi));
let bare_fn_ty = ty::Binder::bind(
tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, unsafety, abi),
tcx,
);
if !self.allow_ty_infer() {
// We always collect the spans for placeholder types when evaluating `fn`s, but we

View file

@ -571,13 +571,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
},
};
let result = ty::Binder::bind(self.tcx.mk_fn_sig(
supplied_arguments,
supplied_return,
decl.c_variadic,
hir::Unsafety::Normal,
Abi::RustCall,
));
let result = ty::Binder::bind(
self.tcx.mk_fn_sig(
supplied_arguments,
supplied_return,
decl.c_variadic,
hir::Unsafety::Normal,
Abi::RustCall,
),
self.tcx,
);
debug!("supplied_sig_of_closure: result={:?}", result);

View file

@ -225,7 +225,7 @@ fn compare_predicate_entailment<'tcx>(
let (impl_m_own_bounds, _) = infcx.replace_bound_vars_with_fresh_vars(
impl_m_span,
infer::HigherRankedType,
ty::Binder::bind(impl_m_own_bounds.predicates),
ty::Binder::bind(impl_m_own_bounds.predicates, tcx),
);
for predicate in impl_m_own_bounds {
let traits::Normalized { value: predicate, obligations } =
@ -258,14 +258,14 @@ fn compare_predicate_entailment<'tcx>(
);
let impl_sig =
inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, impl_sig);
let impl_fty = tcx.mk_fn_ptr(ty::Binder::bind(impl_sig));
let impl_fty = tcx.mk_fn_ptr(ty::Binder::bind(impl_sig, tcx));
debug!("compare_impl_method: impl_fty={:?}", impl_fty);
let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(trait_m.def_id));
let trait_sig = trait_sig.subst(tcx, trait_to_placeholder_substs);
let trait_sig =
inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig);
let trait_fty = tcx.mk_fn_ptr(ty::Binder::bind(trait_sig));
let trait_fty = tcx.mk_fn_ptr(ty::Binder::bind(trait_sig, tcx));
debug!("compare_impl_method: trait_fty={:?}", trait_fty);

View file

@ -486,7 +486,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let found = self.resolve_vars_with_obligations(found);
if let hir::FnRetTy::Return(ty) = fn_decl.output {
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(self, ty);
let ty = self.tcx.erase_late_bound_regions(Binder::bind(ty));
let ty = self.tcx.erase_late_bound_regions(Binder::bind(ty, self.tcx));
let ty = self.normalize_associated_types_in(expr.span, ty);
if self.can_coerce(found, ty) {
err.multipart_suggestion(

View file

@ -202,11 +202,11 @@ pub fn resolve_interior<'a, 'tcx>(
// Extract type components to build the witness type.
let type_list = fcx.tcx.mk_type_list(type_causes.iter().map(|cause| cause.ty));
let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind(type_list));
let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind(type_list, fcx.tcx));
// Store the generator types and spans into the typeck results for this generator.
visitor.fcx.inh.typeck_results.borrow_mut().generator_interior_types =
ty::Binder::bind(type_causes);
ty::Binder::bind(type_causes, fcx.tcx);
debug!(
"types in generator after region replacement {:?}, span = {:?}",

View file

@ -366,7 +366,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
(n_tps, inputs, output, unsafety)
};
let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic);
let sig = ty::Binder::bind(sig);
let sig = ty::Binder::bind(sig, tcx);
equate_intrinsic_type(tcx, it, n_tps, sig)
}

View file

@ -119,7 +119,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
// We won't add these if we encountered an illegal sized bound, so that we can use
// a custom error in that case.
if illegal_sized_bound.is_none() {
let method_ty = self.tcx.mk_fn_ptr(ty::Binder::bind(method_sig));
let method_ty = self.tcx.mk_fn_ptr(ty::Binder::bind(method_sig, self.tcx));
self.add_obligations(method_ty, all_substs, method_predicates);
}

View file

@ -399,7 +399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
obligations.extend(traits::predicates_for_generics(cause.clone(), self.param_env, bounds));
// Also add an obligation for the method type being well-formed.
let method_ty = tcx.mk_fn_ptr(ty::Binder::bind(fn_sig));
let method_ty = tcx.mk_fn_ptr(ty::Binder::bind(fn_sig, tcx));
debug!(
"lookup_in_trait_adjusted: matched method method_ty={:?} obligation={:?}",
method_ty, obligation

View file

@ -1067,13 +1067,14 @@ fn check_method_receiver<'fcx, 'tcx>(
debug!("check_method_receiver: sig={:?}", sig);
let self_ty = fcx.normalize_associated_types_in(span, self_ty);
let self_ty = fcx.tcx.liberate_late_bound_regions(method.def_id, ty::Binder::bind(self_ty));
let self_ty =
fcx.tcx.liberate_late_bound_regions(method.def_id, ty::Binder::bind(self_ty, fcx.tcx));
let receiver_ty = sig.inputs()[0];
let receiver_ty = fcx.normalize_associated_types_in(span, receiver_ty);
let receiver_ty =
fcx.tcx.liberate_late_bound_regions(method.def_id, ty::Binder::bind(receiver_ty));
fcx.tcx.liberate_late_bound_regions(method.def_id, ty::Binder::bind(receiver_ty, fcx.tcx));
if fcx.tcx.features().arbitrary_self_types {
if !receiver_is_valid(fcx, span, receiver_ty, self_ty, true) {

View file

@ -1707,7 +1707,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
}
diag.emit();
ty::Binder::bind(fn_sig)
ty::Binder::bind(fn_sig, tcx)
}
None => <dyn AstConv<'_>>::ty_of_fn(
&icx,
@ -1749,13 +1749,10 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
let ty = tcx.type_of(tcx.hir().get_parent_did(hir_id).to_def_id());
let inputs =
data.fields().iter().map(|f| tcx.type_of(tcx.hir().local_def_id(f.hir_id)));
ty::Binder::bind(tcx.mk_fn_sig(
inputs,
ty,
false,
hir::Unsafety::Normal,
abi::Abi::Rust,
))
ty::Binder::bind(
tcx.mk_fn_sig(inputs, ty, false, hir::Unsafety::Normal, abi::Abi::Rust),
tcx,
)
}
Expr(&hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => {
@ -2039,7 +2036,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
param.bounds.iter().for_each(|bound| match bound {
hir::GenericBound::Outlives(lt) => {
let bound = <dyn AstConv<'_>>::ast_region_to_region(&icx, &lt, None);
let outlives = ty::Binder::bind(ty::OutlivesPredicate(region, bound));
let outlives = ty::Binder::bind(ty::OutlivesPredicate(region, bound), tcx);
predicates.insert((outlives.to_predicate(tcx), lt.span));
}
_ => bug!(),
@ -2099,9 +2096,13 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
} else {
let span = bound_pred.bounded_ty.span;
let re_root_empty = tcx.lifetimes.re_root_empty;
let predicate = ty::Binder::bind(ty::PredicateKind::TypeOutlives(
ty::OutlivesPredicate(ty, re_root_empty),
));
let predicate = ty::Binder::bind(
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
ty,
re_root_empty,
)),
tcx,
);
predicates.insert((predicate.to_predicate(tcx), span));
}
}
@ -2144,9 +2145,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
let region =
<dyn AstConv<'_>>::ast_region_to_region(&icx, lifetime, None);
predicates.insert((
ty::Binder::bind(ty::PredicateKind::TypeOutlives(
ty::OutlivesPredicate(ty, region),
))
ty::Binder::bind(
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
ty, region,
)),
tcx,
)
.to_predicate(tcx),
lifetime.span,
));