1
Fork 0

Auto merge of #87141 - spastorino:remove_impl_trait_in_bindings, r=oli-obk

Remove impl trait in bindings

Closes #86729

r? `@oli-obk`
This commit is contained in:
bors 2021-07-20 05:34:22 +00:00
commit a72c360a30
113 changed files with 540 additions and 1954 deletions

View file

@ -1,5 +1,4 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId;
use rustc_index::vec::IndexVec;
use rustc_middle::infer::MemberConstraint;
use rustc_middle::ty::{self, Ty};
@ -32,9 +31,6 @@ where
crate struct NllMemberConstraint<'tcx> {
next_constraint: Option<NllMemberConstraintIndex>,
/// The opaque type whose hidden type is being inferred. (Used in error reporting.)
crate opaque_type_def_id: DefId,
/// The span where the hidden type was instantiated.
crate definition_span: Span,
@ -91,7 +87,6 @@ impl<'tcx> MemberConstraintSet<'tcx, ty::RegionVid> {
let constraint_index = self.constraints.push(NllMemberConstraint {
next_constraint,
member_region_vid,
opaque_type_def_id: m_c.opaque_type_def_id,
definition_span: m_c.definition_span,
hidden_ty: m_c.hidden_ty,
start_index,

View file

@ -551,7 +551,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
polonius_output: Option<Rc<PoloniusOutput>>,
) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
let mir_def_id = body.source.def_id();
self.propagate_constraints(body, infcx.tcx);
self.propagate_constraints(body);
let mut errors_buffer = RegionErrors::new();
@ -599,7 +599,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// for each region variable until all the constraints are
/// satisfied. Note that some values may grow **too** large to be
/// feasible, but we check this later.
fn propagate_constraints(&mut self, _body: &Body<'tcx>, tcx: TyCtxt<'tcx>) {
fn propagate_constraints(&mut self, _body: &Body<'tcx>) {
debug!("propagate_constraints()");
debug!("propagate_constraints: constraints={:#?}", {
@ -617,7 +617,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// own.
let constraint_sccs = self.constraint_sccs.clone();
for scc in constraint_sccs.all_sccs() {
self.compute_value_for_scc(scc, tcx);
self.compute_value_for_scc(scc);
}
// Sort the applied member constraints so we can binary search
@ -629,7 +629,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// computed, by unioning the values of its successors.
/// Assumes that all successors have been computed already
/// (which is assured by iterating over SCCs in dependency order).
fn compute_value_for_scc(&mut self, scc_a: ConstraintSccIndex, tcx: TyCtxt<'tcx>) {
fn compute_value_for_scc(&mut self, scc_a: ConstraintSccIndex) {
let constraint_sccs = self.constraint_sccs.clone();
// Walk each SCC `B` such that `A: B`...
@ -652,12 +652,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// Now take member constraints into account.
let member_constraints = self.member_constraints.clone();
for m_c_i in member_constraints.indices(scc_a) {
self.apply_member_constraint(
tcx,
scc_a,
m_c_i,
member_constraints.choice_regions(m_c_i),
);
self.apply_member_constraint(scc_a, m_c_i, member_constraints.choice_regions(m_c_i));
}
debug!(
@ -680,31 +675,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// If we make any changes, returns true, else false.
fn apply_member_constraint(
&mut self,
tcx: TyCtxt<'tcx>,
scc: ConstraintSccIndex,
member_constraint_index: NllMemberConstraintIndex,
choice_regions: &[ty::RegionVid],
) -> bool {
debug!("apply_member_constraint(scc={:?}, choice_regions={:#?})", scc, choice_regions,);
if let Some(uh_oh) =
choice_regions.iter().find(|&&r| !self.universal_regions.is_universal_region(r))
{
// FIXME(#61773): This case can only occur with
// `impl_trait_in_bindings`, I believe, and we are just
// opting not to handle it for now. See #61773 for
// details.
tcx.sess.delay_span_bug(
self.member_constraints[member_constraint_index].definition_span,
&format!(
"member constraint for `{:?}` has an option region `{:?}` \
that is not a universal region",
self.member_constraints[member_constraint_index].opaque_type_def_id, uh_oh,
),
);
return false;
}
// Create a mutable vector of the options. We'll try to winnow
// them down.
let mut choice_regions: Vec<ty::RegionVid> = choice_regions.to_vec();

View file

@ -122,7 +122,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if let Err(terr) = self.eq_opaque_type_and_type(
mir_output_ty,
normalized_output_ty,
mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
) {
@ -145,7 +144,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if let Err(err) = self.eq_opaque_type_and_type(
mir_output_ty,
user_provided_output_ty,
mir_def_id,
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
) {

View file

@ -1119,6 +1119,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
)
}
/// Try to relate `sub <: sup`
fn sub_types(
&mut self,
sub: Ty<'tcx>,
@ -1129,32 +1130,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
self.relate_types(sub, ty::Variance::Covariant, sup, locations, category)
}
/// Try to relate `sub <: sup`; if this fails, instantiate opaque
/// variables in `sub` with their inferred definitions and try
/// again. This is used for opaque types in places (e.g., `let x:
/// impl Foo = ..`).
fn sub_types_or_anon(
&mut self,
sub: Ty<'tcx>,
sup: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory,
) -> Fallible<()> {
if let Err(terr) = self.sub_types(sub, sup, locations, category) {
if let ty::Opaque(..) = sup.kind() {
// When you have `let x: impl Foo = ...` in a closure,
// the resulting inferend values are stored with the
// def-id of the base function.
let parent_def_id =
self.tcx().closure_base_def_id(self.body.source.def_id()).expect_local();
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
} else {
return Err(terr);
}
}
Ok(())
}
fn eq_types(
&mut self,
a: Ty<'tcx>,
@ -1207,7 +1182,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}
/// Equates a type `anon_ty` that may contain opaque types whose
/// values are to be inferred by the MIR with def-id `anon_owner_def_id`.
/// values are to be inferred by the MIR.
///
/// The type `revealed_ty` contains the same type as `anon_ty`, but with the
/// hidden types for impl traits revealed.
@ -1235,12 +1210,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
/// generics of `foo`). Note that `anon_ty` is not just the opaque type,
/// but the entire return type (which may contain opaque types within it).
/// * `revealed_ty` would be `Box<(T, u32)>`
/// * `anon_owner_def_id` would be the def-id of `foo`
fn eq_opaque_type_and_type(
&mut self,
revealed_ty: Ty<'tcx>,
anon_ty: Ty<'tcx>,
anon_owner_def_id: LocalDefId,
locations: Locations,
category: ConstraintCategory,
) -> Fallible<()> {
@ -1270,12 +1243,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let tcx = infcx.tcx;
let param_env = self.param_env;
let body = self.body;
let mir_def_id = body.source.def_id().expect_local();
// the "concrete opaque types" maps
let concrete_opaque_types = &tcx.typeck(anon_owner_def_id).concrete_opaque_types;
let concrete_opaque_types = &tcx.typeck(mir_def_id).concrete_opaque_types;
let mut opaque_type_values = VecMap::new();
debug!("eq_opaque_type_and_type: mir_def_id={:?}", body.source.def_id());
debug!("eq_opaque_type_and_type: mir_def_id={:?}", mir_def_id);
let opaque_type_map = self.fully_perform_op(
locations,
category,
@ -1293,7 +1267,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// any generic parameters.)
let (output_ty, opaque_type_map) =
obligations.add(infcx.instantiate_opaque_types(
anon_owner_def_id,
mir_def_id,
dummy_body_id,
param_env,
anon_ty,
@ -1489,7 +1463,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let rv_ty = rv.ty(body, tcx);
let rv_ty = self.normalize(rv_ty, location);
if let Err(terr) =
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
self.sub_types(rv_ty, place_ty, location.to_locations(), category)
{
span_mirbug!(
self,
@ -1776,9 +1750,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let locations = term_location.to_locations();
if let Err(terr) =
self.sub_types_or_anon(sig.output(), dest_ty, locations, category)
{
if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations, category) {
span_mirbug!(
self,
term,