recompute opaque type origin
This commit is contained in:
@@ -33,9 +33,6 @@ pub struct OpaqueTypeDecl<'tcx> {
|
||||
/// There can be multiple, but they are all `lub`ed together at the end
|
||||
/// to obtain the canonical hidden type.
|
||||
pub hidden_type: OpaqueHiddenType<'tcx>,
|
||||
|
||||
/// The origin of the opaque type.
|
||||
pub origin: hir::OpaqueTyOrigin,
|
||||
}
|
||||
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
@@ -108,7 +105,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() {
|
||||
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) if def_id.is_local() => {
|
||||
let def_id = def_id.expect_local();
|
||||
let origin = match self.defining_use_anchor {
|
||||
match self.defining_use_anchor {
|
||||
DefiningAnchor::Bind(_) => {
|
||||
// Check that this is `impl Trait` type is
|
||||
// declared by `parent_def_id` -- i.e., one whose
|
||||
@@ -144,9 +141,11 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
// let x = || foo(); // returns the Opaque assoc with `foo`
|
||||
// }
|
||||
// ```
|
||||
self.opaque_type_origin(def_id)?
|
||||
if self.opaque_type_origin(def_id).is_none() {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
DefiningAnchor::Bubble => self.opaque_type_origin_unchecked(def_id),
|
||||
DefiningAnchor::Bubble => {}
|
||||
DefiningAnchor::Error => return None,
|
||||
};
|
||||
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() {
|
||||
@@ -170,7 +169,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
cause.clone(),
|
||||
param_env,
|
||||
b,
|
||||
origin,
|
||||
a_is_expected,
|
||||
))
|
||||
}
|
||||
@@ -524,7 +522,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
cause: ObligationCause<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
hidden_ty: Ty<'tcx>,
|
||||
origin: hir::OpaqueTyOrigin,
|
||||
a_is_expected: bool,
|
||||
) -> InferResult<'tcx, ()> {
|
||||
// Ideally, we'd get the span where *this specific `ty` came
|
||||
@@ -544,11 +541,11 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
ty::PredicateKind::Ambiguous,
|
||||
)]
|
||||
} else {
|
||||
let prev = self.inner.borrow_mut().opaque_types().register(
|
||||
opaque_type_key,
|
||||
OpaqueHiddenType { ty: hidden_ty, span },
|
||||
origin,
|
||||
);
|
||||
let prev = self
|
||||
.inner
|
||||
.borrow_mut()
|
||||
.opaque_types()
|
||||
.register(opaque_type_key, OpaqueHiddenType { ty: hidden_ty, span });
|
||||
if let Some(prev) = prev {
|
||||
self.at(&cause, param_env)
|
||||
.eq_exp(DefineOpaqueTypes::Yes, a_is_expected, prev, hidden_ty)?
|
||||
@@ -579,15 +576,11 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
hidden_ty: Ty<'tcx>,
|
||||
) -> InferResult<'tcx, ()> {
|
||||
assert!(self.next_trait_solver());
|
||||
let origin = self
|
||||
.opaque_type_origin(opaque_type_key.def_id)
|
||||
.expect("should be called for defining usages only");
|
||||
self.register_hidden_type(
|
||||
opaque_type_key,
|
||||
ObligationCause::dummy(),
|
||||
param_env,
|
||||
hidden_ty,
|
||||
origin,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use rustc_data_structures::undo_log::UndoLogs;
|
||||
use rustc_hir::OpaqueTyOrigin;
|
||||
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty};
|
||||
use rustc_span::DUMMY_SP;
|
||||
|
||||
@@ -60,14 +59,13 @@ impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> {
|
||||
&mut self,
|
||||
key: OpaqueTypeKey<'tcx>,
|
||||
hidden_type: OpaqueHiddenType<'tcx>,
|
||||
origin: OpaqueTyOrigin,
|
||||
) -> Option<Ty<'tcx>> {
|
||||
if let Some(decl) = self.storage.opaque_types.get_mut(&key) {
|
||||
let prev = std::mem::replace(&mut decl.hidden_type, hidden_type);
|
||||
self.undo_log.push(UndoLog::OpaqueTypes(key, Some(prev)));
|
||||
return Some(prev.ty);
|
||||
}
|
||||
let decl = OpaqueTypeDecl { hidden_type, origin };
|
||||
let decl = OpaqueTypeDecl { hidden_type };
|
||||
self.storage.opaque_types.insert(key, decl);
|
||||
self.undo_log.push(UndoLog::OpaqueTypes(key, None));
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user