1
Fork 0

More rebinds

This commit is contained in:
Jack Huey 2020-12-16 22:36:14 -05:00
parent af3b1cb0b5
commit 5e7095850c
24 changed files with 152 additions and 148 deletions

View file

@ -837,9 +837,9 @@ 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((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)), l.span)),
}
}
}

View file

@ -26,7 +26,7 @@ pub struct Bounds<'tcx> {
/// A list of region bounds on the (implicit) self type. So if you
/// had `T: 'a + 'b` this might would be a list `['a, 'b]` (but
/// the `T` is not explicitly included).
pub region_bounds: Vec<(ty::Region<'tcx>, Span)>,
pub region_bounds: Vec<(ty::Binder<ty::Region<'tcx>>, Span)>,
/// A list of trait bounds. So if you had `T: Debug` this would be
/// `T: Debug`. Note that the self-type is explicit here.
@ -68,8 +68,12 @@ impl<'tcx> Bounds<'tcx> {
sized_predicate
.into_iter()
.chain(self.region_bounds.iter().map(|&(region_bound, span)| {
let outlives = ty::OutlivesPredicate(param_ty, region_bound);
(ty::Binder::bind(outlives).to_predicate(tcx), span)
(
region_bound
.map_bound(|region_bound| ty::OutlivesPredicate(param_ty, region_bound))
.to_predicate(tcx),
span,
)
}))
.chain(self.trait_bounds.iter().map(|&(bound_trait_ref, span, constness)| {
let predicate = bound_trait_ref.with_constness(constness).to_predicate(tcx);

View file

@ -389,7 +389,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// In that case, we check each argument against "error" in order to
// set up all the node type bindings.
(
ty::Binder::bind(self.tcx.mk_fn_sig(
ty::Binder::dummy(self.tcx.mk_fn_sig(
self.err_args(arg_exprs.len()).into_iter(),
self.tcx.ty_error(),
false,

View file

@ -24,7 +24,7 @@ use std::iter;
struct ExpectedSig<'tcx> {
/// Span that gave us this expectation, if we know that.
cause_span: Option<Span>,
sig: ty::FnSig<'tcx>,
sig: ty::PolyFnSig<'tcx>,
}
struct ClosureSignatures<'tcx> {
@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
ty::Infer(ty::TyVar(vid)) => self.deduce_expectations_from_obligations(vid),
ty::FnPtr(sig) => {
let expected_sig = ExpectedSig { cause_span: None, sig: sig.skip_binder() };
let expected_sig = ExpectedSig { cause_span: None, sig };
(Some(expected_sig), Some(ty::ClosureKind::Fn))
}
_ => (None, None),
@ -274,13 +274,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ret_param_ty = self.resolve_vars_if_possible(ret_param_ty);
debug!("deduce_sig_from_projection: ret_param_ty={:?}", ret_param_ty);
let sig = self.tcx.mk_fn_sig(
let sig = projection.rebind(self.tcx.mk_fn_sig(
input_tys.iter(),
&ret_param_ty,
false,
hir::Unsafety::Normal,
Abi::Rust,
);
));
debug!("deduce_sig_from_projection: sig={:?}", sig);
Some(ExpectedSig { cause_span, sig })
@ -374,9 +374,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Watch out for some surprises and just ignore the
// expectation if things don't see to match up with what we
// expect.
if expected_sig.sig.c_variadic != decl.c_variadic {
if expected_sig.sig.c_variadic() != decl.c_variadic {
return self.sig_of_closure_no_expectation(expr_def_id, decl, body);
} else if expected_sig.sig.inputs_and_output.len() != decl.inputs.len() + 1 {
} else if expected_sig.sig.skip_binder().inputs_and_output.len() != decl.inputs.len() + 1 {
return self.sig_of_closure_with_mismatched_number_of_arguments(
expr_def_id,
decl,
@ -388,14 +388,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Create a `PolyFnSig`. Note the oddity that late bound
// regions appearing free in `expected_sig` are now bound up
// in this binder we are creating.
assert!(!expected_sig.sig.has_vars_bound_above(ty::INNERMOST));
let bound_sig = ty::Binder::bind(self.tcx.mk_fn_sig(
expected_sig.sig.inputs().iter().cloned(),
expected_sig.sig.output(),
decl.c_variadic,
hir::Unsafety::Normal,
Abi::RustCall,
));
assert!(!expected_sig.sig.skip_binder().has_vars_bound_above(ty::INNERMOST));
let bound_sig = expected_sig.sig.map_bound(|sig| {
self.tcx.mk_fn_sig(
sig.inputs().iter().cloned(),
sig.output(),
sig.c_variadic,
hir::Unsafety::Normal,
Abi::RustCall,
)
});
// `deduce_expectations_from_expected_type` introduces
// late-bound lifetimes defined elsewhere, which we now
@ -428,6 +430,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let expr_map_node = hir.get_if_local(expr_def_id).unwrap();
let expected_args: Vec<_> = expected_sig
.sig
.skip_binder()
.inputs()
.iter()
.map(|ty| ArgKind::from_expected_ty(ty, None))
@ -500,7 +503,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (supplied_ty, _) = self.infcx.replace_bound_vars_with_fresh_vars(
hir_ty.span,
LateBoundRegionConversionTime::FnCall,
ty::Binder::bind(supplied_ty),
supplied_sig.inputs().rebind(supplied_ty),
); // recreated from (*) above
// Check that E' = S'.
@ -619,12 +622,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// where R is the return type we are expecting. This type `T`
// will be our output.
let output_ty = self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| {
if let ty::PredicateAtom::Projection(proj_predicate) =
obligation.predicate.skip_binders()
{
let bound_predicate = obligation.predicate.bound_atom();
if let ty::PredicateAtom::Projection(proj_predicate) = bound_predicate.skip_binder() {
self.deduce_future_output_from_projection(
obligation.cause.span,
ty::Binder::bind(proj_predicate),
bound_predicate.rebind(proj_predicate),
)
} else {
None
@ -704,7 +706,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
astconv.ast_ty_to_ty(&output);
}
let result = ty::Binder::bind(self.tcx.mk_fn_sig(
let result = ty::Binder::dummy(self.tcx.mk_fn_sig(
supplied_arguments,
self.tcx.ty_error(),
decl.c_variadic,

View file

@ -494,12 +494,11 @@ fn compare_self_type<'tcx>(
ty::ImplContainer(_) => impl_trait_ref.self_ty(),
ty::TraitContainer(_) => tcx.types.self_param,
};
let self_arg_ty = tcx.fn_sig(method.def_id).input(0).skip_binder();
let self_arg_ty = tcx.fn_sig(method.def_id).input(0);
let param_env = ty::ParamEnv::reveal_all();
tcx.infer_ctxt().enter(|infcx| {
let self_arg_ty =
tcx.liberate_late_bound_regions(method.def_id, ty::Binder::bind(self_arg_ty));
let self_arg_ty = tcx.liberate_late_bound_regions(method.def_id, self_arg_ty);
let can_eq_self = |ty| infcx.can_eq(param_env, untransformed_self_ty, ty).is_ok();
match ExplicitSelf::determine(self_arg_ty, can_eq_self) {
ExplicitSelf::ByValue => "self".to_owned(),

View file

@ -764,12 +764,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.pending_obligations()
.into_iter()
.filter_map(move |obligation| {
match obligation.predicate.skip_binders() {
let bound_predicate = obligation.predicate.bound_atom();
match bound_predicate.skip_binder() {
ty::PredicateAtom::Projection(data) => {
Some((ty::Binder::bind(data).to_poly_trait_ref(self.tcx), obligation))
Some((bound_predicate.rebind(data).to_poly_trait_ref(self.tcx), obligation))
}
ty::PredicateAtom::Trait(data, _) => {
Some((ty::Binder::bind(data).to_poly_trait_ref(), obligation))
Some((bound_predicate.rebind(data).to_poly_trait_ref(), obligation))
}
ty::PredicateAtom::Subtype(..) => None,
ty::PredicateAtom::RegionOutlives(..) => None,

View file

@ -204,7 +204,8 @@ pub fn resolve_interior<'a, 'tcx>(
let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind(type_list));
// Store the generator types and spans into the typeck results for this generator.
visitor.fcx.inh.typeck_results.borrow_mut().generator_interior_types = type_causes;
visitor.fcx.inh.typeck_results.borrow_mut().generator_interior_types =
ty::Binder::bind(type_causes);
debug!(
"types in generator after region replacement {:?}, span = {:?}",

View file

@ -12,7 +12,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_target::spec::abi::Abi;
@ -23,10 +23,7 @@ fn equate_intrinsic_type<'tcx>(
it: &hir::ForeignItem<'_>,
def_id: DefId,
n_tps: usize,
abi: Abi,
safety: hir::Unsafety,
inputs: Vec<Ty<'tcx>>,
output: Ty<'tcx>,
sig: ty::PolyFnSig<'tcx>,
) {
match it.kind {
hir::ForeignItemKind::Fn(..) => {}
@ -53,13 +50,7 @@ fn equate_intrinsic_type<'tcx>(
return;
}
let fty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
inputs.into_iter(),
output,
false,
safety,
abi,
)));
let fty = tcx.mk_fn_ptr(sig);
let cause = ObligationCause::new(it.span, it.hir_id, ObligationCauseCode::IntrinsicType);
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(def_id)), fty);
}
@ -380,7 +371,9 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
};
(n_tps, inputs, output, unsafety)
};
equate_intrinsic_type(tcx, it, def_id, n_tps, Abi::RustIntrinsic, unsafety, inputs, output)
let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic);
let sig = ty::Binder::bind(sig);
equate_intrinsic_type(tcx, it, def_id, n_tps, sig)
}
/// Type-check `extern "platform-intrinsic" { ... }` functions.
@ -466,14 +459,13 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
}
};
equate_intrinsic_type(
tcx,
it,
def_id,
n_tps,
Abi::PlatformIntrinsic,
hir::Unsafety::Unsafe,
inputs,
let sig = tcx.mk_fn_sig(
inputs.into_iter(),
output,
)
false,
hir::Unsafety::Unsafe,
Abi::PlatformIntrinsic,
);
let sig = ty::Binder::dummy(sig);
equate_intrinsic_type(tcx, it, def_id, n_tps, sig)
}

View file

@ -1986,11 +1986,10 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
}
_ => bug!(),
};
let pred = ty::Binder::dummy(ty::PredicateAtom::RegionOutlives(
ty::OutlivesPredicate(r1, r2),
));
let pred = ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r1, r2))
.to_predicate(icx.tcx);
(pred.potentially_quantified(icx.tcx, ty::PredicateKind::ForAll), span)
(pred, span)
}))
}
@ -2238,10 +2237,8 @@ fn predicates_from_bound<'tcx>(
}
hir::GenericBound::Outlives(ref lifetime) => {
let region = astconv.ast_region_to_region(lifetime, None);
let pred = ty::Binder::dummy(ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(
param_ty, region,
)))
.potentially_quantified(astconv.tcx(), ty::PredicateKind::ForAll);
let pred = ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(param_ty, region))
.to_predicate(astconv.tcx());
vec![(pred, lifetime.span)]
}
}

View file

@ -226,19 +226,21 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) {
let expected_return_type = if tcx.lang_items().termination().is_some() {
// we take the return type of the given main function, the real check is done
// in `check_fn`
actual.output().skip_binder()
actual.output()
} else {
// standard () main return type
tcx.mk_unit()
ty::Binder::dummy(tcx.mk_unit())
};
let se_ty = tcx.mk_fn_ptr(ty::Binder::bind(tcx.mk_fn_sig(
iter::empty(),
expected_return_type,
false,
hir::Unsafety::Normal,
Abi::Rust,
)));
let se_ty = tcx.mk_fn_ptr(expected_return_type.map_bound(|expected_return_type| {
tcx.mk_fn_sig(
iter::empty(),
expected_return_type,
false,
hir::Unsafety::Normal,
Abi::Rust,
)
}));
require_same_types(
tcx,

View file

@ -3,7 +3,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::{self, CratePredicatesMap, TyCtxt};
use rustc_middle::ty::{self, CratePredicatesMap, ToPredicate, TyCtxt};
use rustc_span::symbol::sym;
use rustc_span::Span;
@ -89,17 +89,15 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CratePredica
|(ty::OutlivesPredicate(kind1, region2), &span)| {
match kind1.unpack() {
GenericArgKind::Type(ty1) => Some((
ty::Binder::dummy(ty::PredicateAtom::TypeOutlives(
ty::OutlivesPredicate(ty1, region2),
))
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
ty::PredicateAtom::TypeOutlives(ty::OutlivesPredicate(ty1, region2))
.to_predicate(tcx),
span,
)),
GenericArgKind::Lifetime(region1) => Some((
ty::Binder::dummy(ty::PredicateAtom::RegionOutlives(
ty::OutlivesPredicate(region1, region2),
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(
region1, region2,
))
.potentially_quantified(tcx, ty::PredicateKind::ForAll),
.to_predicate(tcx),
span,
)),
GenericArgKind::Const(_) => {