Changing TyAnon -> TyOpaque and relevant functions
This commit is contained in:
parent
d8af8b66d9
commit
6c14360c32
43 changed files with 228 additions and 216 deletions
|
|
@ -881,7 +881,7 @@ for ty::TyKind<'gcx>
|
|||
Projection(ref projection_ty) => {
|
||||
projection_ty.hash_stable(hcx, hasher);
|
||||
}
|
||||
Anon(def_id, substs) => {
|
||||
Opaque(def_id, substs) => {
|
||||
def_id.hash_stable(hcx, hasher);
|
||||
substs.hash_stable(hcx, hasher);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
|
|||
| ty::Projection(..)
|
||||
| ty::Foreign(..)
|
||||
| ty::Param(..)
|
||||
| ty::Anon(..) => {
|
||||
| ty::Opaque(..) => {
|
||||
if t.flags.intersects(self.needs_canonical_flags) {
|
||||
t.super_fold_with(self)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
|
|||
ty::Param(..) |
|
||||
ty::Closure(..) |
|
||||
ty::GeneratorWitness(..) |
|
||||
ty::Anon(..) => {
|
||||
ty::Opaque(..) => {
|
||||
t.super_fold_with(self)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ use self::outlives::env::OutlivesEnvironment;
|
|||
use self::type_variable::TypeVariableOrigin;
|
||||
use self::unify_key::ToType;
|
||||
|
||||
pub mod anon_types;
|
||||
pub mod opaque_types;
|
||||
pub mod at;
|
||||
pub mod canonical;
|
||||
mod combine;
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ use ty::outlives::Component;
|
|||
use ty::subst::{Kind, Substs, UnpackedKind};
|
||||
use util::nodemap::DefIdMap;
|
||||
|
||||
pub type AnonTypeMap<'tcx> = DefIdMap<AnonTypeDecl<'tcx>>;
|
||||
pub type OpaqueTypeMap<'tcx> = DefIdMap<OpaqueTypeDecl<'tcx>>;
|
||||
|
||||
/// Information about the anonymous, abstract types whose values we
|
||||
/// Information about the opaque, abstract types whose values we
|
||||
/// are inferring in this function (these are the `impl Trait` that
|
||||
/// appear in the return type).
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct AnonTypeDecl<'tcx> {
|
||||
pub struct OpaqueTypeDecl<'tcx> {
|
||||
/// The substitutions that we apply to the abstract that that this
|
||||
/// `impl Trait` desugars to. e.g., if:
|
||||
///
|
||||
|
|
@ -81,7 +81,7 @@ pub struct AnonTypeDecl<'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
/// Replace all anonymized types in `value` with fresh inference variables
|
||||
/// Replace all opaque types in `value` with fresh inference variables
|
||||
/// and creates appropriate obligations. For example, given the input:
|
||||
///
|
||||
/// impl Iterator<Item = impl Debug>
|
||||
|
|
@ -92,29 +92,31 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
/// ?0: Iterator<Item = ?1>
|
||||
/// ?1: Debug
|
||||
///
|
||||
/// Moreover, it returns a `AnonTypeMap` that would map `?0` to
|
||||
/// Moreover, it returns a `OpaqueTypeMap` that would map `?0` to
|
||||
/// info about the `impl Iterator<..>` type and `?1` to info about
|
||||
/// the `impl Debug` type.
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
/// - `parent_def_id` -- we will only instantiate anonymous types
|
||||
/// - `parent_def_id` -- we will only instantiate opaque types
|
||||
/// with this parent. This is typically the def-id of the function
|
||||
/// in whose return type anon types are being instantiated.
|
||||
/// in whose return type opaque types are being instantiated.
|
||||
/// - `body_id` -- the body-id with which the resulting obligations should
|
||||
/// be associated
|
||||
/// - `param_env` -- the in-scope parameter environment to be used for
|
||||
/// obligations
|
||||
/// - `value` -- the value within which we are instantiating anon types
|
||||
pub fn instantiate_anon_types<T: TypeFoldable<'tcx>>(
|
||||
/// - `value` -- the value within which we are instantiating opaque types
|
||||
pub fn instantiate_opaque_types<T: TypeFoldable<'tcx>>(
|
||||
&self,
|
||||
parent_def_id: DefId,
|
||||
body_id: ast::NodeId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: &T,
|
||||
) -> InferOk<'tcx, (T, AnonTypeMap<'tcx>)> {
|
||||
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
|
||||
debug!(
|
||||
"instantiate_anon_types(value={:?}, parent_def_id={:?}, body_id={:?}, param_env={:?})",
|
||||
"instantiate_opaque_types(value={:?},
|
||||
parent_def_id={:?}, body_id={:?},
|
||||
param_env={:?})",
|
||||
value, parent_def_id, body_id, param_env,
|
||||
);
|
||||
let mut instantiator = Instantiator {
|
||||
|
|
@ -122,17 +124,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
parent_def_id,
|
||||
body_id,
|
||||
param_env,
|
||||
anon_types: DefIdMap(),
|
||||
opaque_types: DefIdMap(),
|
||||
obligations: vec![],
|
||||
};
|
||||
let value = instantiator.instantiate_anon_types_in_map(value);
|
||||
let value = instantiator.instantiate_opaque_types_in_map(value);
|
||||
InferOk {
|
||||
value: (value, instantiator.anon_types),
|
||||
value: (value, instantiator.opaque_types),
|
||||
obligations: instantiator.obligations,
|
||||
}
|
||||
}
|
||||
|
||||
/// Given the map `anon_types` containing the existential `impl
|
||||
/// Given the map `opaque_types` containing the existential `impl
|
||||
/// Trait` types whose underlying, hidden types are being
|
||||
/// inferred, this method adds constraints to the regions
|
||||
/// appearing in those underlying hidden types to ensure that they
|
||||
|
|
@ -267,34 +269,34 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
///
|
||||
/// # Parameters
|
||||
///
|
||||
/// - `anon_types` -- the map produced by `instantiate_anon_types`
|
||||
/// - `opaque_types` -- the map produced by `instantiate_opaque_types`
|
||||
/// - `free_region_relations` -- something that can be used to relate
|
||||
/// the free regions (`'a`) that appear in the impl trait.
|
||||
pub fn constrain_anon_types<FRR: FreeRegionRelations<'tcx>>(
|
||||
pub fn constrain_opaque_types<FRR: FreeRegionRelations<'tcx>>(
|
||||
&self,
|
||||
anon_types: &AnonTypeMap<'tcx>,
|
||||
opaque_types: &OpaqueTypeMap<'tcx>,
|
||||
free_region_relations: &FRR,
|
||||
) {
|
||||
debug!("constrain_anon_types()");
|
||||
debug!("constrain_opaque_types()");
|
||||
|
||||
for (&def_id, anon_defn) in anon_types {
|
||||
self.constrain_anon_type(def_id, anon_defn, free_region_relations);
|
||||
for (&def_id, opaque_defn) in opaque_types {
|
||||
self.constrain_opaque_type(def_id, opaque_defn, free_region_relations);
|
||||
}
|
||||
}
|
||||
|
||||
fn constrain_anon_type<FRR: FreeRegionRelations<'tcx>>(
|
||||
fn constrain_opaque_type<FRR: FreeRegionRelations<'tcx>>(
|
||||
&self,
|
||||
def_id: DefId,
|
||||
anon_defn: &AnonTypeDecl<'tcx>,
|
||||
opaque_defn: &OpaqueTypeDecl<'tcx>,
|
||||
free_region_relations: &FRR,
|
||||
) {
|
||||
debug!("constrain_anon_type()");
|
||||
debug!("constrain_anon_type: def_id={:?}", def_id);
|
||||
debug!("constrain_anon_type: anon_defn={:#?}", anon_defn);
|
||||
debug!("constrain_opaque_type()");
|
||||
debug!("constrain_opaque_type: def_id={:?}", def_id);
|
||||
debug!("constrain_opaque_type: opaque_defn={:#?}", opaque_defn);
|
||||
|
||||
let concrete_ty = self.resolve_type_vars_if_possible(&anon_defn.concrete_ty);
|
||||
let concrete_ty = self.resolve_type_vars_if_possible(&opaque_defn.concrete_ty);
|
||||
|
||||
debug!("constrain_anon_type: concrete_ty={:?}", concrete_ty);
|
||||
debug!("constrain_opaque_type: concrete_ty={:?}", concrete_ty);
|
||||
|
||||
let abstract_type_generics = self.tcx.generics_of(def_id);
|
||||
|
||||
|
|
@ -303,7 +305,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// If there are required region bounds, we can just skip
|
||||
// ahead. There will already be a registered region
|
||||
// obligation related `concrete_ty` to those regions.
|
||||
if anon_defn.has_required_region_bounds {
|
||||
if opaque_defn.has_required_region_bounds {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -321,11 +323,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
_ => continue
|
||||
}
|
||||
// Get the value supplied for this region from the substs.
|
||||
let subst_arg = anon_defn.substs.region_at(param.index as usize);
|
||||
let subst_arg = opaque_defn.substs.region_at(param.index as usize);
|
||||
|
||||
// Compute the least upper bound of it with the other regions.
|
||||
debug!("constrain_anon_types: least_region={:?}", least_region);
|
||||
debug!("constrain_anon_types: subst_arg={:?}", subst_arg);
|
||||
debug!("constrain_opaque_types: least_region={:?}", least_region);
|
||||
debug!("constrain_opaque_types: subst_arg={:?}", subst_arg);
|
||||
match least_region {
|
||||
None => least_region = Some(subst_arg),
|
||||
Some(lr) => {
|
||||
|
|
@ -355,7 +357,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
let least_region = least_region.unwrap_or(self.tcx.types.re_static);
|
||||
debug!("constrain_anon_types: least_region={:?}", least_region);
|
||||
debug!("constrain_opaque_types: least_region={:?}", least_region);
|
||||
|
||||
// Require that the type `concrete_ty` outlives
|
||||
// `least_region`, modulo any type parameters that appear
|
||||
|
|
@ -384,7 +386,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// annotations are needed in this case
|
||||
self.tcx
|
||||
.sess
|
||||
.delay_span_bug(span, "unresolved inf var in anon");
|
||||
.delay_span_bug(span, "unresolved inf var in opaque");
|
||||
}
|
||||
|
||||
Component::Projection(ty::ProjectionTy {
|
||||
|
|
@ -405,7 +407,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Given the fully resolved, instantiated type for an anonymous
|
||||
/// Given the fully resolved, instantiated type for an opaque
|
||||
/// type, i.e., the value of an inference variable like C1 or C2
|
||||
/// (*), computes the "definition type" for an abstract type
|
||||
/// definition -- that is, the inferred value of `Foo1<'x>` or
|
||||
|
|
@ -420,22 +422,22 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
/// purpose of this function is to do that translation.
|
||||
///
|
||||
/// (*) C1 and C2 were introduced in the comments on
|
||||
/// `constrain_anon_types`. Read that comment for more context.
|
||||
/// `constrain_opaque_types`. Read that comment for more context.
|
||||
///
|
||||
/// # Parameters
|
||||
///
|
||||
/// - `def_id`, the `impl Trait` type
|
||||
/// - `anon_defn`, the anonymous definition created in `instantiate_anon_types`
|
||||
/// - `opaque_defn`, the opaque definition created in `instantiate_opaque_types`
|
||||
/// - `instantiated_ty`, the inferred type C1 -- fully resolved, lifted version of
|
||||
/// `anon_defn.concrete_ty`
|
||||
pub fn infer_anon_definition_from_instantiation(
|
||||
/// `opaque_defn.concrete_ty`
|
||||
pub fn infer_opaque_definition_from_instantiation(
|
||||
&self,
|
||||
def_id: DefId,
|
||||
anon_defn: &AnonTypeDecl<'tcx>,
|
||||
opaque_defn: &OpaqueTypeDecl<'tcx>,
|
||||
instantiated_ty: Ty<'gcx>,
|
||||
) -> Ty<'gcx> {
|
||||
debug!(
|
||||
"infer_anon_definition_from_instantiation(def_id={:?}, instantiated_ty={:?})",
|
||||
"infer_opaque_definition_from_instantiation(def_id={:?}, instantiated_ty={:?})",
|
||||
def_id, instantiated_ty
|
||||
);
|
||||
|
||||
|
|
@ -448,7 +450,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
// `impl Trait` return type, resulting in the parameters
|
||||
// shifting.
|
||||
let id_substs = Substs::identity_for_item(gcx, def_id);
|
||||
let map: FxHashMap<Kind<'tcx>, Kind<'gcx>> = anon_defn
|
||||
let map: FxHashMap<Kind<'tcx>, Kind<'gcx>> = opaque_defn
|
||||
.substs
|
||||
.iter()
|
||||
.enumerate()
|
||||
|
|
@ -467,7 +469,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
instantiated_ty,
|
||||
));
|
||||
debug!(
|
||||
"infer_anon_definition_from_instantiation: definition_ty={:?}",
|
||||
"infer_opaque_definition_from_instantiation: definition_ty={:?}",
|
||||
definition_ty
|
||||
);
|
||||
|
||||
|
|
@ -487,7 +489,7 @@ struct ReverseMapper<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
|
|||
/// our own errors because they are sometimes derivative.
|
||||
tainted_by_errors: bool,
|
||||
|
||||
anon_type_def_id: DefId,
|
||||
opaque_type_def_id: DefId,
|
||||
map: FxHashMap<Kind<'tcx>, Kind<'gcx>>,
|
||||
map_missing_regions_to_empty: bool,
|
||||
|
||||
|
|
@ -499,14 +501,14 @@ impl<'cx, 'gcx, 'tcx> ReverseMapper<'cx, 'gcx, 'tcx> {
|
|||
fn new(
|
||||
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
|
||||
tainted_by_errors: bool,
|
||||
anon_type_def_id: DefId,
|
||||
opaque_type_def_id: DefId,
|
||||
map: FxHashMap<Kind<'tcx>, Kind<'gcx>>,
|
||||
hidden_ty: Ty<'tcx>,
|
||||
) -> Self {
|
||||
Self {
|
||||
tcx,
|
||||
tainted_by_errors,
|
||||
anon_type_def_id,
|
||||
opaque_type_def_id,
|
||||
map,
|
||||
map_missing_regions_to_empty: false,
|
||||
hidden_ty: Some(hidden_ty),
|
||||
|
|
@ -554,7 +556,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
|
|||
None => {
|
||||
if !self.map_missing_regions_to_empty && !self.tainted_by_errors {
|
||||
if let Some(hidden_ty) = self.hidden_ty.take() {
|
||||
let span = self.tcx.def_span(self.anon_type_def_id);
|
||||
let span = self.tcx.def_span(self.opaque_type_def_id);
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx.sess,
|
||||
span,
|
||||
|
|
@ -644,19 +646,19 @@ struct Instantiator<'a, 'gcx: 'tcx, 'tcx: 'a> {
|
|||
parent_def_id: DefId,
|
||||
body_id: ast::NodeId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
anon_types: AnonTypeMap<'tcx>,
|
||||
opaque_types: OpaqueTypeMap<'tcx>,
|
||||
obligations: Vec<PredicateObligation<'tcx>>,
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
||||
fn instantiate_anon_types_in_map<T: TypeFoldable<'tcx>>(&mut self, value: &T) -> T {
|
||||
debug!("instantiate_anon_types_in_map(value={:?})", value);
|
||||
fn instantiate_opaque_types_in_map<T: TypeFoldable<'tcx>>(&mut self, value: &T) -> T {
|
||||
debug!("instantiate_opaque_types_in_map(value={:?})", value);
|
||||
let tcx = self.infcx.tcx;
|
||||
value.fold_with(&mut BottomUpFolder {
|
||||
tcx,
|
||||
reg_op: |reg| reg,
|
||||
fldop: |ty| {
|
||||
if let ty::Anon(def_id, substs) = ty.sty {
|
||||
if let ty::Opaque(def_id, substs) = ty.sty {
|
||||
// Check that this is `impl Trait` type is
|
||||
// declared by `parent_def_id` -- i.e., one whose
|
||||
// value we are inferring. At present, this is
|
||||
|
|
@ -680,7 +682,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
// ```
|
||||
//
|
||||
// Here, the return type of `foo` references a
|
||||
// `Anon` indeed, but not one whose value is
|
||||
// `Opaque` indeed, but not one whose value is
|
||||
// presently being inferred. You can get into a
|
||||
// similar situation with closure return types
|
||||
// today:
|
||||
|
|
@ -688,16 +690,16 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
// ```rust
|
||||
// fn foo() -> impl Iterator { .. }
|
||||
// fn bar() {
|
||||
// let x = || foo(); // returns the Anon assoc with `foo`
|
||||
// let x = || foo(); // returns the Opaque assoc with `foo`
|
||||
// }
|
||||
// ```
|
||||
if let Some(anon_node_id) = tcx.hir.as_local_node_id(def_id) {
|
||||
if let Some(opaque_node_id) = tcx.hir.as_local_node_id(def_id) {
|
||||
let parent_def_id = self.parent_def_id;
|
||||
let def_scope_default = || {
|
||||
let anon_parent_node_id = tcx.hir.get_parent(anon_node_id);
|
||||
parent_def_id == tcx.hir.local_def_id(anon_parent_node_id)
|
||||
let opaque_parent_node_id = tcx.hir.get_parent(opaque_node_id);
|
||||
parent_def_id == tcx.hir.local_def_id(opaque_parent_node_id)
|
||||
};
|
||||
let in_definition_scope = match tcx.hir.find(anon_node_id) {
|
||||
let in_definition_scope = match tcx.hir.find(opaque_node_id) {
|
||||
Some(Node::Item(item)) => match item.node {
|
||||
// impl trait
|
||||
hir::ItemKind::Existential(hir::ExistTy {
|
||||
|
|
@ -711,7 +713,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
}) => may_define_existential_type(
|
||||
tcx,
|
||||
self.parent_def_id,
|
||||
anon_node_id,
|
||||
opaque_node_id,
|
||||
),
|
||||
_ => def_scope_default(),
|
||||
},
|
||||
|
|
@ -719,22 +721,22 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
hir::ImplItemKind::Existential(_) => may_define_existential_type(
|
||||
tcx,
|
||||
self.parent_def_id,
|
||||
anon_node_id,
|
||||
opaque_node_id,
|
||||
),
|
||||
_ => def_scope_default(),
|
||||
},
|
||||
_ => bug!(
|
||||
"expected (impl) item, found {}",
|
||||
tcx.hir.node_to_string(anon_node_id),
|
||||
tcx.hir.node_to_string(opaque_node_id),
|
||||
),
|
||||
};
|
||||
if in_definition_scope {
|
||||
return self.fold_anon_ty(ty, def_id, substs);
|
||||
return self.fold_opaque_ty(ty, def_id, substs);
|
||||
}
|
||||
|
||||
debug!(
|
||||
"instantiate_anon_types_in_map: \
|
||||
encountered anon outside it's definition scope \
|
||||
"instantiate_opaque_types_in_map: \
|
||||
encountered opaque outside it's definition scope \
|
||||
def_id={:?}",
|
||||
def_id,
|
||||
);
|
||||
|
|
@ -746,7 +748,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
fn fold_anon_ty(
|
||||
fn fold_opaque_ty(
|
||||
&mut self,
|
||||
ty: Ty<'tcx>,
|
||||
def_id: DefId,
|
||||
|
|
@ -756,29 +758,29 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
let tcx = infcx.tcx;
|
||||
|
||||
debug!(
|
||||
"instantiate_anon_types: Anon(def_id={:?}, substs={:?})",
|
||||
"instantiate_opaque_types: Opaque(def_id={:?}, substs={:?})",
|
||||
def_id, substs
|
||||
);
|
||||
|
||||
// Use the same type variable if the exact same Anon appears more
|
||||
// Use the same type variable if the exact same Opaque appears more
|
||||
// than once in the return type (e.g. if it's passed to a type alias).
|
||||
if let Some(anon_defn) = self.anon_types.get(&def_id) {
|
||||
return anon_defn.concrete_ty;
|
||||
if let Some(opaque_defn) = self.opaque_types.get(&def_id) {
|
||||
return opaque_defn.concrete_ty;
|
||||
}
|
||||
let span = tcx.def_span(def_id);
|
||||
let ty_var = infcx.next_ty_var(TypeVariableOrigin::TypeInference(span));
|
||||
|
||||
let predicates_of = tcx.predicates_of(def_id);
|
||||
debug!(
|
||||
"instantiate_anon_types: predicates: {:#?}",
|
||||
"instantiate_opaque_types: predicates: {:#?}",
|
||||
predicates_of,
|
||||
);
|
||||
let bounds = predicates_of.instantiate(tcx, substs);
|
||||
debug!("instantiate_anon_types: bounds={:?}", bounds);
|
||||
debug!("instantiate_opaque_types: bounds={:?}", bounds);
|
||||
|
||||
let required_region_bounds = tcx.required_region_bounds(ty, bounds.predicates.clone());
|
||||
debug!(
|
||||
"instantiate_anon_types: required_region_bounds={:?}",
|
||||
"instantiate_opaque_types: required_region_bounds={:?}",
|
||||
required_region_bounds
|
||||
);
|
||||
|
||||
|
|
@ -786,34 +788,34 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
// e.g. `existential type Foo<T: Bound>: Bar;` needs to be
|
||||
// defined by a function like `fn foo<T: Bound>() -> Foo<T>`.
|
||||
debug!(
|
||||
"instantiate_anon_types: param_env: {:#?}",
|
||||
"instantiate_opaque_types: param_env: {:#?}",
|
||||
self.param_env,
|
||||
);
|
||||
debug!(
|
||||
"instantiate_anon_types: generics: {:#?}",
|
||||
"instantiate_opaque_types: generics: {:#?}",
|
||||
tcx.generics_of(def_id),
|
||||
);
|
||||
|
||||
self.anon_types.insert(
|
||||
self.opaque_types.insert(
|
||||
def_id,
|
||||
AnonTypeDecl {
|
||||
OpaqueTypeDecl {
|
||||
substs,
|
||||
concrete_ty: ty_var,
|
||||
has_required_region_bounds: !required_region_bounds.is_empty(),
|
||||
},
|
||||
);
|
||||
debug!("instantiate_anon_types: ty_var={:?}", ty_var);
|
||||
debug!("instantiate_opaque_types: ty_var={:?}", ty_var);
|
||||
|
||||
for predicate in bounds.predicates {
|
||||
// Change the predicate to refer to the type variable,
|
||||
// which will be the concrete type, instead of the Anon.
|
||||
// which will be the concrete type, instead of the Opaque.
|
||||
// This also instantiates nested `impl Trait`.
|
||||
let predicate = self.instantiate_anon_types_in_map(&predicate);
|
||||
let predicate = self.instantiate_opaque_types_in_map(&predicate);
|
||||
|
||||
let cause = traits::ObligationCause::new(span, self.body_id, traits::SizedReturnType);
|
||||
|
||||
// Require that the predicate holds for the concrete type.
|
||||
debug!("instantiate_anon_types: predicate={:?}", predicate);
|
||||
debug!("instantiate_opaque_types: predicate={:?}", predicate);
|
||||
self.obligations
|
||||
.push(traits::Obligation::new(cause, self.param_env, predicate));
|
||||
}
|
||||
|
|
@ -822,7 +824,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Whether `anon_node_id` is a sibling or a child of a sibling of `def_id`
|
||||
/// Whether `opaque_node_id` is a sibling or a child of a sibling of `def_id`
|
||||
///
|
||||
/// ```rust
|
||||
/// pub mod foo {
|
||||
|
|
@ -837,13 +839,14 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
|
|||
/// ```
|
||||
///
|
||||
/// Here, `def_id` will be the `DefId` of the existential type `Baz`.
|
||||
/// `anon_node_id` is the `NodeId` of the reference to Baz -- so either the return type of f1 or f2.
|
||||
/// `opaque_node_id` is the `NodeId` of the reference to Baz --
|
||||
/// so either the return type of f1 or f2.
|
||||
/// We will return true if the reference is within the same module as the existential type
|
||||
/// So true for f1, false for f2.
|
||||
pub fn may_define_existential_type(
|
||||
tcx: TyCtxt,
|
||||
def_id: DefId,
|
||||
anon_node_id: ast::NodeId,
|
||||
opaque_node_id: ast::NodeId,
|
||||
) -> bool {
|
||||
let mut node_id = tcx
|
||||
.hir
|
||||
|
|
@ -851,9 +854,9 @@ pub fn may_define_existential_type(
|
|||
.unwrap();
|
||||
// named existential types can be defined by any siblings or
|
||||
// children of siblings
|
||||
let mod_id = tcx.hir.get_parent(anon_node_id);
|
||||
let mod_id = tcx.hir.get_parent(opaque_node_id);
|
||||
// so we walk up the node tree until we hit the root or the parent
|
||||
// of the anon type
|
||||
// of the opaque type
|
||||
while node_id != mod_id && node_id != ast::CRATE_NODE_ID {
|
||||
node_id = tcx.hir.get_parent(node_id);
|
||||
}
|
||||
|
|
@ -483,7 +483,7 @@ fn ty_is_local_constructor(ty: Ty, in_crate: InCrate) -> bool {
|
|||
ty::Closure(..) |
|
||||
ty::Generator(..) |
|
||||
ty::GeneratorWitness(..) |
|
||||
ty::Anon(..) => {
|
||||
ty::Opaque(..) => {
|
||||
bug!("ty_is_local invoked on unexpected type: {:?}", ty)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
ty::Tuple(..) => Some(10),
|
||||
ty::Projection(..) => Some(11),
|
||||
ty::Param(..) => Some(12),
|
||||
ty::Anon(..) => Some(13),
|
||||
ty::Opaque(..) => Some(13),
|
||||
ty::Never => Some(14),
|
||||
ty::Adt(adt, ..) => match adt.adt_kind() {
|
||||
AdtKind::Struct => Some(15),
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
|
|||
|
||||
let ty = ty.super_fold_with(self);
|
||||
match ty.sty {
|
||||
ty::Anon(def_id, substs) if !substs.has_escaping_regions() => { // (*)
|
||||
ty::Opaque(def_id, substs) if !substs.has_escaping_regions() => { // (*)
|
||||
// Only normalize `impl Trait` after type-checking, usually in codegen.
|
||||
match self.param_env.reveal {
|
||||
Reveal::UserFacing => ty,
|
||||
|
|
@ -986,7 +986,7 @@ fn assemble_candidates_from_trait_def<'cx, 'gcx, 'tcx>(
|
|||
ty::Projection(ref data) => {
|
||||
(data.trait_ref(tcx).def_id, data.substs)
|
||||
}
|
||||
ty::Anon(def_id, substs) => (def_id, substs),
|
||||
ty::Opaque(def_id, substs) => (def_id, substs),
|
||||
ty::Infer(ty::TyVar(_)) => {
|
||||
// If the self-type is an inference variable, then it MAY wind up
|
||||
// being a projected type, so induce an ambiguity.
|
||||
|
|
@ -1518,7 +1518,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
|
|||
let substs = translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.node);
|
||||
let ty = if let ty::AssociatedKind::Existential = assoc_ty.item.kind {
|
||||
let item_substs = Substs::identity_for_item(tcx, assoc_ty.item.def_id);
|
||||
tcx.mk_anon(assoc_ty.item.def_id, item_substs)
|
||||
tcx.mk_opaque(assoc_ty.item.def_id, item_substs)
|
||||
} else {
|
||||
tcx.type_of(assoc_ty.item.def_id)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'_, '_, 'tcx>, ty: Ty<'tcx>) ->
|
|||
ty::Dynamic(..)
|
||||
| ty::Projection(..)
|
||||
| ty::Param(_)
|
||||
| ty::Anon(..)
|
||||
| ty::Opaque(..)
|
||||
| ty::Infer(_)
|
||||
| ty::Generator(..) => false,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx
|
|||
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||
let ty = ty.super_fold_with(self);
|
||||
match ty.sty {
|
||||
ty::Anon(def_id, substs) if !substs.has_escaping_regions() => {
|
||||
ty::Opaque(def_id, substs) if !substs.has_escaping_regions() => {
|
||||
// (*)
|
||||
// Only normalize `impl Trait` after type-checking, usually in codegen.
|
||||
match self.param_env.reveal {
|
||||
|
|
|
|||
|
|
@ -1492,7 +1492,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
|||
// before we go into the whole skolemization thing, just
|
||||
// quickly check if the self-type is a projection at all.
|
||||
match obligation.predicate.skip_binder().trait_ref.self_ty().sty {
|
||||
ty::Projection(_) | ty::Anon(..) => {}
|
||||
ty::Projection(_) | ty::Opaque(..) => {}
|
||||
ty::Infer(ty::TyVar(_)) => {
|
||||
span_bug!(obligation.cause.span,
|
||||
"Self=_ should have been handled by assemble_candidates");
|
||||
|
|
@ -1528,7 +1528,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
|||
let (def_id, substs) = match skol_trait_predicate.trait_ref.self_ty().sty {
|
||||
ty::Projection(ref data) =>
|
||||
(data.trait_ref(self.tcx()).def_id, data.substs),
|
||||
ty::Anon(def_id, substs) => (def_id, substs),
|
||||
ty::Opaque(def_id, substs) => (def_id, substs),
|
||||
_ => {
|
||||
span_bug!(
|
||||
obligation.cause.span,
|
||||
|
|
@ -2203,7 +2203,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
|||
))
|
||||
}
|
||||
|
||||
ty::Projection(_) | ty::Param(_) | ty::Anon(..) => None,
|
||||
ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => None,
|
||||
ty::Infer(ty::TyVar(_)) => Ambiguous,
|
||||
|
||||
ty::Infer(ty::CanonicalTy(_)) |
|
||||
|
|
@ -2265,7 +2265,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
ty::Adt(..) | ty::Projection(..) | ty::Param(..) | ty::Anon(..) => {
|
||||
ty::Adt(..) | ty::Projection(..) | ty::Param(..) | ty::Opaque(..) => {
|
||||
// Fallback to whatever user-defined impls exist in this case.
|
||||
None
|
||||
}
|
||||
|
|
@ -2369,7 +2369,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
ty::Anon(def_id, substs) => {
|
||||
ty::Opaque(def_id, substs) => {
|
||||
// We can resolve the `impl Trait` to its concrete type,
|
||||
// which enforces a DAG between the functions requiring
|
||||
// the auto trait bounds in question.
|
||||
|
|
|
|||
|
|
@ -2136,7 +2136,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||
self,
|
||||
Adt, Array, Slice, RawPtr, Ref, FnDef, FnPtr,
|
||||
Generator, GeneratorWitness, Dynamic, Closure, Tuple,
|
||||
Param, Infer, Projection, Anon, Foreign);
|
||||
Param, Infer, Projection, Opaque, Foreign);
|
||||
|
||||
println!("Substs interner: #{}", self.interners.substs.borrow().len());
|
||||
println!("Region interner: #{}", self.interners.region.borrow().len());
|
||||
|
|
@ -2606,8 +2606,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn mk_anon(self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> {
|
||||
self.mk_ty(Anon(def_id, substs))
|
||||
pub fn mk_opaque(self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> {
|
||||
self.mk_ty(Opaque(def_id, substs))
|
||||
}
|
||||
|
||||
pub fn intern_existential_predicates(self, eps: &[ExistentialPredicate<'tcx>])
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
|
|||
"type parameter".to_string()
|
||||
}
|
||||
}
|
||||
ty::Anon(..) => "anonymized type".to_string(),
|
||||
ty::Opaque(..) => "opaque type".to_string(),
|
||||
ty::Error => "type error".to_string(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ pub enum SimplifiedTypeGen<D>
|
|||
ClosureSimplifiedType(D),
|
||||
GeneratorSimplifiedType(D),
|
||||
GeneratorWitnessSimplifiedType(usize),
|
||||
AnonSimplifiedType(D),
|
||||
OpaqueSimplifiedType(D),
|
||||
FunctionSimplifiedType(usize),
|
||||
ParameterSimplifiedType,
|
||||
ForeignSimplifiedType(DefId),
|
||||
|
|
@ -115,8 +115,8 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
|||
None
|
||||
}
|
||||
}
|
||||
ty::Anon(def_id, _) => {
|
||||
Some(AnonSimplifiedType(def_id))
|
||||
ty::Opaque(def_id, _) => {
|
||||
Some(OpaqueSimplifiedType(def_id))
|
||||
}
|
||||
ty::Foreign(def_id) => {
|
||||
Some(ForeignSimplifiedType(def_id))
|
||||
|
|
@ -146,7 +146,7 @@ impl<D: Copy + Debug + Ord + Eq + Hash> SimplifiedTypeGen<D> {
|
|||
ClosureSimplifiedType(d) => ClosureSimplifiedType(map(d)),
|
||||
GeneratorSimplifiedType(d) => GeneratorSimplifiedType(map(d)),
|
||||
GeneratorWitnessSimplifiedType(n) => GeneratorWitnessSimplifiedType(n),
|
||||
AnonSimplifiedType(d) => AnonSimplifiedType(map(d)),
|
||||
OpaqueSimplifiedType(d) => OpaqueSimplifiedType(map(d)),
|
||||
FunctionSimplifiedType(n) => FunctionSimplifiedType(n),
|
||||
ParameterSimplifiedType => ParameterSimplifiedType,
|
||||
ForeignSimplifiedType(d) => ForeignSimplifiedType(d),
|
||||
|
|
@ -181,7 +181,7 @@ impl<'a, 'gcx, D> HashStable<StableHashingContext<'a>> for SimplifiedTypeGen<D>
|
|||
ClosureSimplifiedType(d) => d.hash_stable(hcx, hasher),
|
||||
GeneratorSimplifiedType(d) => d.hash_stable(hcx, hasher),
|
||||
GeneratorWitnessSimplifiedType(n) => n.hash_stable(hcx, hasher),
|
||||
AnonSimplifiedType(d) => d.hash_stable(hcx, hasher),
|
||||
OpaqueSimplifiedType(d) => d.hash_stable(hcx, hasher),
|
||||
FunctionSimplifiedType(n) => n.hash_stable(hcx, hasher),
|
||||
ForeignSimplifiedType(d) => d.hash_stable(hcx, hasher),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ impl FlagComputation {
|
|||
self.add_projection_ty(data);
|
||||
}
|
||||
|
||||
&ty::Anon(_, substs) => {
|
||||
&ty::Opaque(_, substs) => {
|
||||
self.add_flags(TypeFlags::HAS_PROJECTION);
|
||||
self.add_substs(substs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -771,7 +771,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector {
|
|||
// in the normalized form
|
||||
if self.just_constrained {
|
||||
match t.sty {
|
||||
ty::Projection(..) | ty::Anon(..) => { return false; }
|
||||
ty::Projection(..) | ty::Opaque(..) => { return false; }
|
||||
_ => { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ pub fn characteristic_def_id_of_type(ty: Ty) -> Option<DefId> {
|
|||
ty::FnPtr(_) |
|
||||
ty::Projection(_) |
|
||||
ty::Param(_) |
|
||||
ty::Anon(..) |
|
||||
ty::Opaque(..) |
|
||||
ty::Infer(_) |
|
||||
ty::Error |
|
||||
ty::GeneratorWitness(..) |
|
||||
|
|
|
|||
|
|
@ -1103,7 +1103,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
|
|||
}
|
||||
|
||||
// Types with no meaningful known layout.
|
||||
ty::Projection(_) | ty::Anon(..) => {
|
||||
ty::Projection(_) | ty::Opaque(..) => {
|
||||
let normalized = tcx.normalize_erasing_regions(param_env, ty);
|
||||
if ty == normalized {
|
||||
return Err(LayoutError::Unknown(ty));
|
||||
|
|
@ -1373,7 +1373,7 @@ impl<'a, 'tcx> SizeSkeleton<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
ty::Projection(_) | ty::Anon(..) => {
|
||||
ty::Projection(_) | ty::Opaque(..) => {
|
||||
let normalized = tcx.normalize_erasing_regions(param_env, ty);
|
||||
if ty == normalized {
|
||||
Err(err)
|
||||
|
|
@ -1685,7 +1685,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
|
|||
}
|
||||
}
|
||||
|
||||
ty::Projection(_) | ty::Anon(..) | ty::Param(_) |
|
||||
ty::Projection(_) | ty::Opaque(..) | ty::Param(_) |
|
||||
ty::Infer(_) | ty::Error => {
|
||||
bug!("TyLayout::field_type: unexpected type `{}`", this.ty)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@ impl<'tcx> TyS<'tcx> {
|
|||
|
||||
pub fn is_suggestable(&self) -> bool {
|
||||
match self.sty {
|
||||
TyKind::Anon(..) |
|
||||
TyKind::Opaque(..) |
|
||||
TyKind::FnDef(..) |
|
||||
TyKind::FnPtr(..) |
|
||||
TyKind::Dynamic(..) |
|
||||
|
|
@ -2265,7 +2265,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
|
|||
.collect()
|
||||
}
|
||||
|
||||
Projection(..) | Anon(..) => {
|
||||
Projection(..) | Opaque(..) => {
|
||||
// must calculate explicitly.
|
||||
// FIXME: consider special-casing always-Sized projections
|
||||
vec![ty]
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
ty::Float(..) | // OutlivesScalar
|
||||
ty::Never | // ...
|
||||
ty::Adt(..) | // OutlivesNominalType
|
||||
ty::Anon(..) | // OutlivesNominalType (ish)
|
||||
ty::Opaque(..) | // OutlivesNominalType (ish)
|
||||
ty::Foreign(..) | // OutlivesNominalType
|
||||
ty::Str | // OutlivesScalar (ish)
|
||||
ty::Array(..) | // ...
|
||||
|
|
|
|||
|
|
@ -564,11 +564,11 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
|
|||
Ok(tcx.mk_projection(projection_ty.item_def_id, projection_ty.substs))
|
||||
}
|
||||
|
||||
(&ty::Anon(a_def_id, a_substs), &ty::Anon(b_def_id, b_substs))
|
||||
(&ty::Opaque(a_def_id, a_substs), &ty::Opaque(b_def_id, b_substs))
|
||||
if a_def_id == b_def_id =>
|
||||
{
|
||||
let substs = relate_substs(relation, None, a_substs, b_substs)?;
|
||||
Ok(tcx.mk_anon(a_def_id, substs))
|
||||
Ok(tcx.mk_opaque(a_def_id, substs))
|
||||
}
|
||||
|
||||
_ =>
|
||||
|
|
|
|||
|
|
@ -865,7 +865,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
|||
ty::GeneratorWitness(types) => ty::GeneratorWitness(types.fold_with(folder)),
|
||||
ty::Closure(did, substs) => ty::Closure(did, substs.fold_with(folder)),
|
||||
ty::Projection(ref data) => ty::Projection(data.fold_with(folder)),
|
||||
ty::Anon(did, substs) => ty::Anon(did, substs.fold_with(folder)),
|
||||
ty::Opaque(did, substs) => ty::Opaque(did, substs.fold_with(folder)),
|
||||
ty::Bool | ty::Char | ty::Str | ty::Int(_) |
|
||||
ty::Uint(_) | ty::Float(_) | ty::Error | ty::Infer(_) |
|
||||
ty::Param(..) | ty::Never | ty::Foreign(..) => return self
|
||||
|
|
@ -900,7 +900,7 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> {
|
|||
ty::GeneratorWitness(ref types) => types.visit_with(visitor),
|
||||
ty::Closure(_did, ref substs) => substs.visit_with(visitor),
|
||||
ty::Projection(ref data) => data.visit_with(visitor),
|
||||
ty::Anon(_, ref substs) => substs.visit_with(visitor),
|
||||
ty::Opaque(_, ref substs) => substs.visit_with(visitor),
|
||||
ty::Bool | ty::Char | ty::Str | ty::Int(_) |
|
||||
ty::Uint(_) | ty::Float(_) | ty::Error | ty::Infer(_) |
|
||||
ty::Param(..) | ty::Never | ty::Foreign(..) => false,
|
||||
|
|
|
|||
|
|
@ -157,13 +157,13 @@ pub enum TyKind<'tcx> {
|
|||
/// `<T as Trait<..>>::N`.
|
||||
Projection(ProjectionTy<'tcx>),
|
||||
|
||||
/// Anonymized (`impl Trait`) type found in a return type.
|
||||
/// Opaque (`impl Trait`) type found in a return type.
|
||||
/// The DefId comes either from
|
||||
/// * the `impl Trait` ast::Ty node,
|
||||
/// * or the `existential type` declaration
|
||||
/// The substitutions are for the generics of the function in question.
|
||||
/// After typeck, the concrete type can be found in the `types` map.
|
||||
Anon(DefId, &'tcx Substs<'tcx>),
|
||||
Opaque(DefId, &'tcx Substs<'tcx>),
|
||||
|
||||
/// A type parameter; for example, `T` in `fn f<T>(x: T) {}
|
||||
Param(ParamTy),
|
||||
|
|
@ -1764,7 +1764,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
|||
|
||||
pub fn is_impl_trait(&self) -> bool {
|
||||
match self.sty {
|
||||
Anon(..) => true,
|
||||
Opaque(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -1791,7 +1791,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
|||
}
|
||||
v
|
||||
}
|
||||
Adt(_, substs) | Anon(_, substs) => {
|
||||
Adt(_, substs) | Opaque(_, substs) => {
|
||||
substs.regions().collect()
|
||||
}
|
||||
Closure(_, ClosureSubsts { ref substs }) |
|
||||
|
|
@ -1876,7 +1876,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
|
|||
ty::Adt(def, _substs) =>
|
||||
def.sized_constraint(tcx).is_empty(),
|
||||
|
||||
ty::Projection(_) | ty::Param(_) | ty::Anon(..) => false,
|
||||
ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => false,
|
||||
|
||||
ty::Infer(ty::TyVar(_)) => false,
|
||||
|
||||
|
|
|
|||
|
|
@ -956,7 +956,7 @@ fn needs_drop_raw<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
// Can refer to a type which may drop.
|
||||
// FIXME(eddyb) check this against a ParamEnv.
|
||||
ty::Dynamic(..) | ty::Projection(..) | ty::Param(_) |
|
||||
ty::Anon(..) | ty::Infer(_) | ty::Error => true,
|
||||
ty::Opaque(..) | ty::Infer(_) | ty::Error => true,
|
||||
|
||||
// Structural recursion.
|
||||
ty::Array(ty, _) | ty::Slice(ty) => needs_drop(ty),
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) {
|
|||
substs.types().rev().chain(opt_ty)
|
||||
}));
|
||||
}
|
||||
ty::Adt(_, substs) | ty::Anon(_, substs) => {
|
||||
ty::Adt(_, substs) | ty::Opaque(_, substs) => {
|
||||
stack.extend(substs.types().rev());
|
||||
}
|
||||
ty::Closure(_, ref substs) => {
|
||||
|
|
|
|||
|
|
@ -360,7 +360,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
|
|||
// types appearing in the fn signature
|
||||
}
|
||||
|
||||
ty::Anon(did, substs) => {
|
||||
ty::Opaque(did, substs) => {
|
||||
// all of the requirements on type parameters
|
||||
// should've been checked by the instantiation
|
||||
// of whatever returned this exact `impl Trait`.
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use ty::{BrAnon, BrEnv, BrFresh, BrNamed};
|
|||
use ty::{Bool, Char, Adt};
|
||||
use ty::{Error, Str, Array, Slice, Float, FnDef, FnPtr};
|
||||
use ty::{Param, RawPtr, Ref, Never, Tuple};
|
||||
use ty::{Closure, Generator, GeneratorWitness, Foreign, Projection, Anon};
|
||||
use ty::{Closure, Generator, GeneratorWitness, Foreign, Projection, Opaque};
|
||||
use ty::{Dynamic, Int, Uint, Infer};
|
||||
use ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, GenericParamCount, GenericParamDefKind};
|
||||
use util::nodemap::FxHashSet;
|
||||
|
|
@ -1103,9 +1103,9 @@ define_print! {
|
|||
}
|
||||
Foreign(def_id) => parameterized(f, subst::Substs::empty(), def_id, &[]),
|
||||
Projection(ref data) => data.print(f, cx),
|
||||
Anon(def_id, substs) => {
|
||||
Opaque(def_id, substs) => {
|
||||
if cx.is_verbose {
|
||||
return write!(f, "Anon({:?}, {:?})", def_id, substs);
|
||||
return write!(f, "Opaque({:?}, {:?})", def_id, substs);
|
||||
}
|
||||
|
||||
ty::tls::with(|tcx| {
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
|||
ty::Error |
|
||||
ty::Infer(_) |
|
||||
ty::Projection(..) |
|
||||
ty::Anon(..) |
|
||||
ty::Opaque(..) |
|
||||
ty::GeneratorWitness(..) |
|
||||
ty::Param(_) => {
|
||||
bug!("debuginfo: Trying to create type name for \
|
||||
|
|
|
|||
|
|
@ -721,7 +721,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||
ty::Generator(..) |
|
||||
ty::GeneratorWitness(..) |
|
||||
ty::Projection(..) |
|
||||
ty::Anon(..) |
|
||||
ty::Opaque(..) |
|
||||
ty::FnDef(..) => bug!("Unexpected type in foreign function"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
|||
// types.
|
||||
let param_env = self.param_env;
|
||||
let mir_output_ty = mir.local_decls[RETURN_PLACE].ty;
|
||||
let anon_type_map =
|
||||
let opaque_type_map =
|
||||
self.fully_perform_op(
|
||||
Locations::All,
|
||||
CustomTypeOp::new(
|
||||
|
|
@ -80,8 +80,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
|||
let mut obligations = ObligationAccumulator::default();
|
||||
|
||||
let dummy_body_id = ObligationCause::dummy().body_id;
|
||||
let (output_ty, anon_type_map) =
|
||||
obligations.add(infcx.instantiate_anon_types(
|
||||
let (output_ty, opaque_type_map) =
|
||||
obligations.add(infcx.instantiate_opaque_types(
|
||||
mir_def_id,
|
||||
dummy_body_id,
|
||||
param_env,
|
||||
|
|
@ -92,8 +92,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
|||
output_ty
|
||||
);
|
||||
debug!(
|
||||
"equate_inputs_and_outputs: anon_type_map={:#?}",
|
||||
anon_type_map
|
||||
"equate_inputs_and_outputs: opaque_type_map={:#?}",
|
||||
opaque_type_map
|
||||
);
|
||||
|
||||
debug!(
|
||||
|
|
@ -106,29 +106,30 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
|||
.eq(output_ty, mir_output_ty)?,
|
||||
);
|
||||
|
||||
for (&anon_def_id, anon_decl) in &anon_type_map {
|
||||
let anon_defn_ty = tcx.type_of(anon_def_id);
|
||||
let anon_defn_ty = anon_defn_ty.subst(tcx, anon_decl.substs);
|
||||
let anon_defn_ty = renumber::renumber_regions(
|
||||
for (&opaque_def_id, opaque_decl) in &opaque_type_map {
|
||||
let opaque_defn_ty = tcx.type_of(opaque_def_id);
|
||||
let opaque_defn_ty = opaque_defn_ty.subst(tcx, opaque_decl.substs);
|
||||
let opaque_defn_ty = renumber::renumber_regions(
|
||||
infcx,
|
||||
&anon_defn_ty,
|
||||
&opaque_defn_ty,
|
||||
);
|
||||
debug!(
|
||||
"equate_inputs_and_outputs: concrete_ty={:?}",
|
||||
anon_decl.concrete_ty
|
||||
opaque_decl.concrete_ty
|
||||
);
|
||||
debug!("equate_inputs_and_outputs: anon_defn_ty={:?}", anon_defn_ty);
|
||||
debug!("equate_inputs_and_outputs: opaque_defn_ty={:?}",
|
||||
opaque_defn_ty);
|
||||
obligations.add(
|
||||
infcx
|
||||
.at(&ObligationCause::dummy(), param_env)
|
||||
.eq(anon_decl.concrete_ty, anon_defn_ty)?,
|
||||
.eq(opaque_decl.concrete_ty, opaque_defn_ty)?,
|
||||
);
|
||||
}
|
||||
|
||||
debug!("equate_inputs_and_outputs: equated");
|
||||
|
||||
Ok(InferOk {
|
||||
value: Some(anon_type_map),
|
||||
value: Some(opaque_type_map),
|
||||
obligations: obligations.into_vec(),
|
||||
})
|
||||
},
|
||||
|
|
@ -146,22 +147,22 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
|
|||
None
|
||||
});
|
||||
|
||||
// Finally, if we instantiated the anon types successfully, we
|
||||
// Finally, if we instantiated the opaque types successfully, we
|
||||
// have to solve any bounds (e.g., `-> impl Iterator` needs to
|
||||
// prove that `T: Iterator` where `T` is the type we
|
||||
// instantiated it with).
|
||||
if let Some(anon_type_map) = anon_type_map {
|
||||
if let Some(opaque_type_map) = opaque_type_map {
|
||||
self.fully_perform_op(
|
||||
Locations::All,
|
||||
CustomTypeOp::new(
|
||||
|_cx| {
|
||||
infcx.constrain_anon_types(&anon_type_map, universal_region_relations);
|
||||
infcx.constrain_opaque_types(&opaque_type_map, universal_region_relations);
|
||||
Ok(InferOk {
|
||||
value: (),
|
||||
obligations: vec![],
|
||||
})
|
||||
},
|
||||
|| "anon_type_map".to_string(),
|
||||
|| "opaque_type_map".to_string(),
|
||||
),
|
||||
).unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
|
|||
ty::Projection(..) |
|
||||
ty::Param(_) |
|
||||
ty::GeneratorWitness(_) |
|
||||
ty::Anon(..) => {
|
||||
ty::Opaque(..) => {
|
||||
bug!("DefPathBasedNames: Trying to create type name for \
|
||||
unexpected type: {:?}", t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -490,7 +490,7 @@ impl<'b, 'a, 'tcx> TypeVisitor<'tcx> for ReachEverythingInTheInterfaceVisitor<'b
|
|||
ty::FnDef(def_id, ..) |
|
||||
ty::Closure(def_id, ..) |
|
||||
ty::Generator(def_id, ..) |
|
||||
ty::Anon(def_id, _) => Some(def_id),
|
||||
ty::Opaque(def_id, _) => Some(def_id),
|
||||
_ => None
|
||||
};
|
||||
|
||||
|
|
@ -652,7 +652,7 @@ struct TypePrivacyVisitor<'a, 'tcx: 'a> {
|
|||
in_body: bool,
|
||||
span: Span,
|
||||
empty_tables: &'a ty::TypeckTables<'tcx>,
|
||||
visited_anon_tys: FxHashSet<DefId>
|
||||
visited_opaque_tys: FxHashSet<DefId>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> {
|
||||
|
|
@ -954,7 +954,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
ty::Anon(def_id, ..) => {
|
||||
ty::Opaque(def_id, ..) => {
|
||||
for predicate in &self.tcx.predicates_of(def_id).predicates {
|
||||
let trait_ref = match *predicate {
|
||||
ty::Predicate::Trait(ref poly_trait_predicate) => {
|
||||
|
|
@ -977,10 +977,10 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
|
|||
return true;
|
||||
}
|
||||
for subst in trait_ref.substs.iter() {
|
||||
// Skip repeated `Anon`s to avoid infinite recursion.
|
||||
// Skip repeated `Opaque`s to avoid infinite recursion.
|
||||
if let UnpackedKind::Type(ty) = subst.unpack() {
|
||||
if let ty::Anon(def_id, ..) = ty.sty {
|
||||
if !self.visited_anon_tys.insert(def_id) {
|
||||
if let ty::Opaque(def_id, ..) = ty.sty {
|
||||
if !self.visited_opaque_tys.insert(def_id) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -1726,7 +1726,7 @@ fn privacy_access_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
in_body: false,
|
||||
span: krate.span,
|
||||
empty_tables: &empty_tables,
|
||||
visited_anon_tys: FxHashSet()
|
||||
visited_opaque_tys: FxHashSet()
|
||||
};
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ fn dropck_outlives<'tcx>(
|
|||
|
||||
// A projection that we couldn't resolve - it
|
||||
// might have a destructor.
|
||||
ty::Projection(..) | ty::Anon(..) => {
|
||||
ty::Projection(..) | ty::Opaque(..) => {
|
||||
result.kinds.push(ty.into());
|
||||
}
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ fn dtorck_constraint_for_ty<'a, 'gcx, 'tcx>(
|
|||
}),
|
||||
|
||||
// Types that can't be resolved. Pass them forward.
|
||||
ty::Projection(..) | ty::Anon(..) | ty::Param(..) => Ok(DtorckConstraint {
|
||||
ty::Projection(..) | ty::Opaque(..) | ty::Param(..) => Ok(DtorckConstraint {
|
||||
outlives: vec![],
|
||||
dtorck_types: vec![ty],
|
||||
overflows: vec![],
|
||||
|
|
|
|||
|
|
@ -1347,7 +1347,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
|
|||
let substs = self.ast_path_substs_for_ty(span, did, item_segment.0);
|
||||
self.normalize_ty(
|
||||
span,
|
||||
tcx.mk_anon(did, substs),
|
||||
tcx.mk_opaque(did, substs),
|
||||
)
|
||||
}
|
||||
Def::Enum(did) | Def::TyAlias(did) | Def::Struct(did) |
|
||||
|
|
@ -1540,7 +1540,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
|
|||
});
|
||||
debug!("impl_trait_ty_to_ty: final substs = {:?}", substs);
|
||||
|
||||
let ty = tcx.mk_anon(def_id, substs);
|
||||
let ty = tcx.mk_opaque(def_id, substs);
|
||||
debug!("impl_trait_ty_to_ty: {}", ty);
|
||||
ty
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ enum PointerKind<'tcx> {
|
|||
Length,
|
||||
/// The unsize info of this projection
|
||||
OfProjection(&'tcx ty::ProjectionTy<'tcx>),
|
||||
/// The unsize info of this anon ty
|
||||
OfAnon(DefId, &'tcx Substs<'tcx>),
|
||||
/// The unsize info of this opaque ty
|
||||
OfOpaque(DefId, &'tcx Substs<'tcx>),
|
||||
/// The unsize info of this parameter
|
||||
OfParam(&'tcx ty::ParamTy),
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
ty::Foreign(..) => Some(PointerKind::Thin),
|
||||
// We should really try to normalize here.
|
||||
ty::Projection(ref pi) => Some(PointerKind::OfProjection(pi)),
|
||||
ty::Anon(def_id, substs) => Some(PointerKind::OfAnon(def_id, substs)),
|
||||
ty::Opaque(def_id, substs) => Some(PointerKind::OfOpaque(def_id, substs)),
|
||||
ty::Param(ref p) => Some(PointerKind::OfParam(p)),
|
||||
// Insufficient type information.
|
||||
ty::Infer(_) => None,
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
|||
use std::slice;
|
||||
use namespace::Namespace;
|
||||
use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin};
|
||||
use rustc::infer::anon_types::AnonTypeDecl;
|
||||
use rustc::infer::opaque_types::OpaqueTypeDecl;
|
||||
use rustc::infer::type_variable::{TypeVariableOrigin};
|
||||
use rustc::middle::region;
|
||||
use rustc::mir::interpret::{ConstValue, GlobalId};
|
||||
|
|
@ -212,11 +212,11 @@ pub struct Inherited<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
|||
|
||||
deferred_generator_interiors: RefCell<Vec<(hir::BodyId, Ty<'tcx>)>>,
|
||||
|
||||
// Anonymized types found in explicit return types and their
|
||||
// Opaque types found in explicit return types and their
|
||||
// associated fresh inference variable. Writeback resolves these
|
||||
// variables to get the concrete type, which can be used to
|
||||
// deanonymize Anon, after typeck is done with all functions.
|
||||
anon_types: RefCell<DefIdMap<AnonTypeDecl<'tcx>>>,
|
||||
// 'de-opaque' OpaqueTypeDecl, after typeck is done with all functions.
|
||||
opaque_types: RefCell<DefIdMap<OpaqueTypeDecl<'tcx>>>,
|
||||
|
||||
/// Each type parameter has an implicit region bound that
|
||||
/// indicates it must outlive at least the function body (the user
|
||||
|
|
@ -635,7 +635,7 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
|
|||
deferred_call_resolutions: RefCell::new(DefIdMap()),
|
||||
deferred_cast_checks: RefCell::new(Vec::new()),
|
||||
deferred_generator_interiors: RefCell::new(Vec::new()),
|
||||
anon_types: RefCell::new(DefIdMap()),
|
||||
opaque_types: RefCell::new(DefIdMap()),
|
||||
implicit_region_bound,
|
||||
body_id,
|
||||
}
|
||||
|
|
@ -1024,7 +1024,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
|
|||
|
||||
let declared_ret_ty = fn_sig.output();
|
||||
fcx.require_type_is_sized(declared_ret_ty, decl.output.span(), traits::SizedReturnType);
|
||||
let revealed_ret_ty = fcx.instantiate_anon_types_from_return_value(fn_id, &declared_ret_ty);
|
||||
let revealed_ret_ty = fcx.instantiate_opaque_types_from_return_value(fn_id, &declared_ret_ty);
|
||||
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(revealed_ret_ty)));
|
||||
fn_sig = fcx.tcx.mk_fn_sig(
|
||||
fn_sig.inputs().iter().cloned(),
|
||||
|
|
@ -2217,24 +2217,24 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
result
|
||||
}
|
||||
|
||||
/// Replace the anonymized types from the return value of the
|
||||
/// function with type variables and records the `AnonTypeMap` for
|
||||
/// Replace the opaque types from the return value of the
|
||||
/// function with type variables and records the `OpaqueTypeMap` for
|
||||
/// later use during writeback. See
|
||||
/// `InferCtxt::instantiate_anon_types` for more details.
|
||||
fn instantiate_anon_types_from_return_value<T: TypeFoldable<'tcx>>(
|
||||
/// `InferCtxt::instantiate_opaque_types` for more details.
|
||||
fn instantiate_opaque_types_from_return_value<T: TypeFoldable<'tcx>>(
|
||||
&self,
|
||||
fn_id: ast::NodeId,
|
||||
value: &T,
|
||||
) -> T {
|
||||
let fn_def_id = self.tcx.hir.local_def_id(fn_id);
|
||||
debug!(
|
||||
"instantiate_anon_types_from_return_value(fn_def_id={:?}, value={:?})",
|
||||
"instantiate_opaque_types_from_return_value(fn_def_id={:?}, value={:?})",
|
||||
fn_def_id,
|
||||
value
|
||||
);
|
||||
|
||||
let (value, anon_type_map) = self.register_infer_ok_obligations(
|
||||
self.instantiate_anon_types(
|
||||
let (value, opaque_type_map) = self.register_infer_ok_obligations(
|
||||
self.instantiate_opaque_types(
|
||||
fn_def_id,
|
||||
self.body_id,
|
||||
self.param_env,
|
||||
|
|
@ -2242,9 +2242,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
)
|
||||
);
|
||||
|
||||
let mut anon_types = self.anon_types.borrow_mut();
|
||||
for (ty, decl) in anon_type_map {
|
||||
let old_value = anon_types.insert(ty, decl);
|
||||
let mut opaque_types = self.opaque_types.borrow_mut();
|
||||
for (ty, decl) in opaque_type_map {
|
||||
let old_value = opaque_types.insert(ty, decl);
|
||||
assert!(old_value.is_none(), "instantiated twice: {:?}/{:?}", ty, decl);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -347,8 +347,8 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
|
|||
body_hir_id,
|
||||
call_site_region);
|
||||
|
||||
self.constrain_anon_types(
|
||||
&self.fcx.anon_types.borrow(),
|
||||
self.constrain_opaque_types(
|
||||
&self.fcx.opaque_types.borrow(),
|
||||
self.outlives_environment.free_region_map(),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use rustc::ty::subst::{Subst, Substs};
|
|||
use rustc::ty::util::ExplicitSelf;
|
||||
use rustc::util::nodemap::{FxHashSet, FxHashMap};
|
||||
use rustc::middle::lang_items;
|
||||
use rustc::infer::anon_types::may_define_existential_type;
|
||||
use rustc::infer::opaque_types::may_define_existential_type;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::feature_gate::{self, GateIssue};
|
||||
|
|
@ -576,13 +576,13 @@ fn check_existential_types<'a, 'fcx, 'gcx, 'tcx>(
|
|||
ty.fold_with(&mut ty::fold::BottomUpFolder {
|
||||
tcx: fcx.tcx,
|
||||
fldop: |ty| {
|
||||
if let ty::Anon(def_id, substs) = ty.sty {
|
||||
trace!("check_existential_types: anon_ty, {:?}, {:?}", def_id, substs);
|
||||
if let ty::Opaque(def_id, substs) = ty.sty {
|
||||
trace!("check_existential_types: opaque_ty, {:?}, {:?}", def_id, substs);
|
||||
let generics = tcx.generics_of(def_id);
|
||||
// only check named existential types
|
||||
if generics.parent.is_none() {
|
||||
let anon_node_id = tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
if may_define_existential_type(tcx, fn_def_id, anon_node_id) {
|
||||
let opaque_node_id = tcx.hir.as_local_node_id(def_id).unwrap();
|
||||
if may_define_existential_type(tcx, fn_def_id, opaque_node_id) {
|
||||
trace!("check_existential_types may define. Generics: {:#?}", generics);
|
||||
let mut seen: FxHashMap<_, Vec<_>> = FxHashMap();
|
||||
for (subst, param) in substs.iter().zip(&generics.params) {
|
||||
|
|
@ -674,7 +674,7 @@ fn check_existential_types<'a, 'fcx, 'gcx, 'tcx>(
|
|||
}
|
||||
}
|
||||
} // if is_named_existential_type
|
||||
} // if let Anon
|
||||
} // if let Opaque
|
||||
ty
|
||||
},
|
||||
reg_op: |reg| reg,
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
wbcx.visit_closures();
|
||||
wbcx.visit_liberated_fn_sigs();
|
||||
wbcx.visit_fru_field_types();
|
||||
wbcx.visit_anon_types(body.value.span);
|
||||
wbcx.visit_opaque_types(body.value.span);
|
||||
wbcx.visit_cast_types();
|
||||
wbcx.visit_free_region_map();
|
||||
wbcx.visit_user_provided_tys();
|
||||
|
|
@ -393,18 +393,18 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_anon_types(&mut self, span: Span) {
|
||||
for (&def_id, anon_defn) in self.fcx.anon_types.borrow().iter() {
|
||||
fn visit_opaque_types(&mut self, span: Span) {
|
||||
for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
|
||||
let node_id = self.tcx().hir.as_local_node_id(def_id).unwrap();
|
||||
let instantiated_ty = self.resolve(&anon_defn.concrete_ty, &node_id);
|
||||
let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &node_id);
|
||||
|
||||
let generics = self.tcx().generics_of(def_id);
|
||||
|
||||
let definition_ty = if generics.parent.is_some() {
|
||||
// impl trait
|
||||
self.fcx.infer_anon_definition_from_instantiation(
|
||||
self.fcx.infer_opaque_definition_from_instantiation(
|
||||
def_id,
|
||||
anon_defn,
|
||||
opaque_defn,
|
||||
instantiated_ty,
|
||||
)
|
||||
} else {
|
||||
|
|
@ -427,8 +427,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
|
|||
// find a type parameter
|
||||
if let ty::Param(..) = ty.sty {
|
||||
// look it up in the substitution list
|
||||
assert_eq!(anon_defn.substs.len(), generics.params.len());
|
||||
for (subst, param) in anon_defn.substs.iter().zip(&generics.params) {
|
||||
assert_eq!(opaque_defn.substs.len(), generics.params.len());
|
||||
for (subst, param) in opaque_defn.substs.iter().zip(&generics.params) {
|
||||
if let UnpackedKind::Type(subst) = subst.unpack() {
|
||||
if subst == ty {
|
||||
// found it in the substitution list, replace with the
|
||||
|
|
@ -460,7 +460,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
|
|||
ty::ReStatic => region,
|
||||
_ => {
|
||||
trace!("checking {:?}", region);
|
||||
for (subst, p) in anon_defn.substs.iter().zip(&generics.params) {
|
||||
for (subst, p) in opaque_defn.substs.iter().zip(&generics.params) {
|
||||
if let UnpackedKind::Lifetime(subst) = subst.unpack() {
|
||||
if subst == region {
|
||||
// found it in the substitution list, replace with the
|
||||
|
|
@ -477,7 +477,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
trace!("anon_defn: {:#?}", anon_defn);
|
||||
trace!("opaque_defn: {:#?}", opaque_defn);
|
||||
trace!("generics: {:#?}", generics);
|
||||
self.tcx()
|
||||
.sess
|
||||
|
|
@ -501,7 +501,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
|
|||
})
|
||||
};
|
||||
|
||||
if let ty::Anon(defin_ty_def_id, _substs) = definition_ty.sty {
|
||||
if let ty::Opaque(defin_ty_def_id, _substs) = definition_ty.sty {
|
||||
if def_id == defin_ty_def_id {
|
||||
// Concrete type resolved to the existential type itself
|
||||
// Force a cycle error
|
||||
|
|
@ -516,8 +516,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
|
|||
if old != definition_ty {
|
||||
span_bug!(
|
||||
span,
|
||||
"visit_anon_types tried to write \
|
||||
different types for the same existential type: {:?}, {:?}, {:?}",
|
||||
"visit_opaque_types tried to write \
|
||||
different types for the same existential type: {:?}, {:?}, {:?}",
|
||||
def_id,
|
||||
definition_ty,
|
||||
old,
|
||||
|
|
|
|||
|
|
@ -1643,9 +1643,10 @@ fn explicit_predicates_of<'a, 'tcx>(
|
|||
Node::ImplItem(item) => match item.node {
|
||||
ImplItemKind::Existential(ref bounds) => {
|
||||
let substs = Substs::identity_for_item(tcx, def_id);
|
||||
let anon_ty = tcx.mk_anon(def_id, substs);
|
||||
let opaque_ty = tcx.mk_opaque(def_id, substs);
|
||||
|
||||
// Collect the bounds, i.e. the `A+B+'c` in `impl A+B+'c`.
|
||||
<<<<<<< HEAD
|
||||
let bounds = compute_bounds(
|
||||
&icx,
|
||||
anon_ty,
|
||||
|
|
@ -1653,8 +1654,15 @@ fn explicit_predicates_of<'a, 'tcx>(
|
|||
SizedByDefault::Yes,
|
||||
tcx.def_span(def_id),
|
||||
);
|
||||
=======
|
||||
let bounds = compute_bounds(&icx,
|
||||
opaque_ty,
|
||||
bounds,
|
||||
SizedByDefault::Yes,
|
||||
tcx.def_span(def_id));
|
||||
>>>>>>> ca386bc20a... Changing TyAnon -> TyOpaque and relevant functions
|
||||
|
||||
predicates.extend(bounds.predicates(tcx, anon_ty));
|
||||
predicates.extend(bounds.predicates(tcx, opaque_ty));
|
||||
&item.generics
|
||||
}
|
||||
_ => &item.generics,
|
||||
|
|
@ -1684,12 +1692,12 @@ fn explicit_predicates_of<'a, 'tcx>(
|
|||
ref generics,
|
||||
}) => {
|
||||
let substs = Substs::identity_for_item(tcx, def_id);
|
||||
let anon_ty = tcx.mk_anon(def_id, substs);
|
||||
let opaque_ty = tcx.mk_opaque(def_id, substs);
|
||||
|
||||
// Collect the bounds, i.e. the `A+B+'c` in `impl A+B+'c`.
|
||||
let bounds = compute_bounds(
|
||||
&icx,
|
||||
anon_ty,
|
||||
opaque_ty,
|
||||
bounds,
|
||||
SizedByDefault::Yes,
|
||||
tcx.def_span(def_id),
|
||||
|
|
@ -1699,11 +1707,11 @@ fn explicit_predicates_of<'a, 'tcx>(
|
|||
// impl Trait
|
||||
return ty::GenericPredicates {
|
||||
parent: None,
|
||||
predicates: bounds.predicates(tcx, anon_ty),
|
||||
predicates: bounds.predicates(tcx, opaque_ty),
|
||||
};
|
||||
} else {
|
||||
// named existential types
|
||||
predicates.extend(bounds.predicates(tcx, anon_ty));
|
||||
predicates.extend(bounds.predicates(tcx, opaque_ty));
|
||||
generics
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
//n Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
|
|
@ -62,7 +62,7 @@ struct ParameterCollector {
|
|||
impl<'tcx> TypeVisitor<'tcx> for ParameterCollector {
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
|
||||
match t.sty {
|
||||
ty::Projection(..) | ty::Anon(..) if !self.include_nonconstraining => {
|
||||
ty::Projection(..) | ty::Opaque(..) if !self.include_nonconstraining => {
|
||||
// projections are not injective
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
self.add_constraints_from_trait_ref(current, data.trait_ref(tcx), variance);
|
||||
}
|
||||
|
||||
ty::Anon(_, substs) => {
|
||||
ty::Opaque(_, substs) => {
|
||||
self.add_constraints_from_invariant_substs(current, substs, variance);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2672,11 +2672,11 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
|||
|
||||
ty::Param(ref p) => Generic(p.name.to_string()),
|
||||
|
||||
ty::Anon(def_id, substs) => {
|
||||
ty::Opaque(def_id, substs) => {
|
||||
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
|
||||
// by looking up the projections associated with the def_id.
|
||||
let predicates_of = cx.tcx.predicates_of(def_id);
|
||||
let substs = cx.tcx.lift(&substs).expect("Anon lift failed");
|
||||
let substs = cx.tcx.lift(&substs).expect("Opaque lift failed");
|
||||
let bounds = predicates_of.instantiate(cx.tcx, substs);
|
||||
let mut regions = vec![];
|
||||
let mut has_sized = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue