1
Fork 0

Remove unnecessary field

This commit is contained in:
Oli Scherer 2022-01-27 14:52:24 +00:00
parent 5b49b8e2d5
commit d35d1ef4f5
2 changed files with 12 additions and 24 deletions

View file

@ -26,9 +26,6 @@ use super::InferResult;
/// appear in the return type). /// appear in the return type).
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct OpaqueTypeDecl<'tcx> { pub struct OpaqueTypeDecl<'tcx> {
/// The opaque type (`ty::Opaque`) for this declaration.
pub opaque_type: Ty<'tcx>,
/// The hidden types that have been inferred for this opaque type. /// The hidden types that have been inferred for this opaque type.
/// There can be multiple, but they are all `lub`ed together at the end /// There can be multiple, but they are all `lub`ed together at the end
/// to obtain the canonical hidden type. /// to obtain the canonical hidden type.
@ -82,11 +79,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
return Ok(InferOk { value: (), obligations: vec![] }); return Ok(InferOk { value: (), obligations: vec![] });
} }
if self.defining_use_anchor.is_some() { if self.defining_use_anchor.is_some() {
let process = |a: Ty<'tcx>, b: Ty<'tcx>| { let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
if !matches!(a.kind(), ty::Opaque(..)) { ty::Opaque(def_id, substs) => self.fold_opaque_ty_new(
return None; OpaqueTypeKey { def_id, substs },
} cause.clone(),
self.fold_opaque_ty_new(a, cause.clone(), param_env, b) param_env,
b,
),
_ => None,
}; };
if let Some(res) = process(a, b) { if let Some(res) = process(a, b) {
res res
@ -118,7 +118,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let origin = self.opaque_ty_origin_unchecked(key.def_id, cause.span); let origin = self.opaque_ty_origin_unchecked(key.def_id, cause.span);
let prev = self.inner.borrow_mut().opaque_types().register( let prev = self.inner.borrow_mut().opaque_types().register(
key, key,
opaque_type,
OpaqueHiddenType { ty: hidden_ty, span: cause.span }, OpaqueHiddenType { ty: hidden_ty, span: cause.span },
origin, origin,
); );
@ -482,7 +481,7 @@ impl UseKind {
impl<'a, 'tcx> InferCtxt<'a, 'tcx> { impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
fn fold_opaque_ty_new( fn fold_opaque_ty_new(
&self, &self,
opaque_type: Ty<'tcx>, opaque_type_key: OpaqueTypeKey<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
hidden_ty: Ty<'tcx>, hidden_ty: Ty<'tcx>,
@ -521,26 +520,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// let x = || foo(); // returns the Opaque assoc with `foo` // let x = || foo(); // returns the Opaque assoc with `foo`
// } // }
// ``` // ```
let opaque_type_key = opaque_type.expect_opaque_type();
if let Some(origin) = self.opaque_type_origin(opaque_type_key.def_id, cause.span) { if let Some(origin) = self.opaque_type_origin(opaque_type_key.def_id, cause.span) {
return Some(self.fold_opaque_ty( return Some(self.fold_opaque_ty(cause, param_env, opaque_type_key, origin, hidden_ty));
opaque_type,
cause,
param_env,
opaque_type_key,
origin,
hidden_ty,
));
} }
debug!(?opaque_type, "encountered opaque outside its definition scope",); debug!(?opaque_type_key, "encountered opaque outside its definition scope",);
None None
} }
#[instrument(skip(self), level = "debug")] #[instrument(skip(self), level = "debug")]
fn fold_opaque_ty( fn fold_opaque_ty(
&self, &self,
opaque_type: Ty<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
opaque_type_key: OpaqueTypeKey<'tcx>, opaque_type_key: OpaqueTypeKey<'tcx>,
@ -560,7 +550,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let mut obligations = vec![]; let mut obligations = vec![];
let prev = self.inner.borrow_mut().opaque_types().register( let prev = self.inner.borrow_mut().opaque_types().register(
OpaqueTypeKey { def_id, substs }, OpaqueTypeKey { def_id, substs },
opaque_type,
OpaqueHiddenType { ty: hidden_ty, span }, OpaqueHiddenType { ty: hidden_ty, span },
origin, origin,
); );

View file

@ -72,7 +72,6 @@ impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> {
pub fn register( pub fn register(
&mut self, &mut self,
key: OpaqueTypeKey<'tcx>, key: OpaqueTypeKey<'tcx>,
opaque_type: Ty<'tcx>,
hidden_type: OpaqueHiddenType<'tcx>, hidden_type: OpaqueHiddenType<'tcx>,
origin: OpaqueTyOrigin, origin: OpaqueTyOrigin,
) -> Option<Ty<'tcx>> { ) -> Option<Ty<'tcx>> {
@ -81,7 +80,7 @@ impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> {
self.undo_log.push(UndoLog::OpaqueTypes(key, Some(prev))); self.undo_log.push(UndoLog::OpaqueTypes(key, Some(prev)));
return Some(prev.ty); return Some(prev.ty);
} }
let decl = OpaqueTypeDecl { opaque_type, hidden_type, origin }; let decl = OpaqueTypeDecl { hidden_type, origin };
self.storage.opaque_types.insert(key, decl); self.storage.opaque_types.insert(key, decl);
self.undo_log.push(UndoLog::OpaqueTypes(key, None)); self.undo_log.push(UndoLog::OpaqueTypes(key, None));
None None