diff options
Diffstat (limited to 'compiler/rustc_infer')
| -rw-r--r-- | compiler/rustc_infer/src/infer/canonical/query_response.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/opaque_types.rs | 52 | ||||
| -rw-r--r-- | compiler/rustc_infer/src/infer/opaque_types/table.rs | 10 |
3 files changed, 10 insertions, 65 deletions
diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index a86471affaa..18a1120051e 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -146,13 +146,13 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { }) } - fn take_opaque_types_for_query_response(&self) -> Vec<(OpaqueTypeKey<'tcx>, Vec<Ty<'tcx>>)> { + fn take_opaque_types_for_query_response(&self) -> Vec<(OpaqueTypeKey<'tcx>, Ty<'tcx>)> { self.inner .borrow_mut() .opaque_type_storage .take_opaque_types() .into_iter() - .map(|(k, v)| (k, v.hidden_types.into_iter().map(|ht| ht.ty).collect())) + .map(|(k, v)| (k, v.hidden_type.ty)) .collect() } @@ -497,14 +497,11 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { let mut obligations = vec![]; // Carry all newly resolved opaque types to the caller's scope - for (key, tys) in &query_response.value.opaque_types { + for &(key, ty) in &query_response.value.opaque_types { let substs = substitute_value(self.tcx, &result_subst, key.substs); let opaque = self.tcx.mk_opaque(key.def_id, substs); - for &ty in tys { - let ty = substitute_value(self.tcx, &result_subst, ty); - obligations - .extend(self.handle_opaque_type(opaque, ty, cause, param_env)?.obligations); - } + let ty = substitute_value(self.tcx, &result_subst, ty); + obligations.extend(self.handle_opaque_type(opaque, ty, cause, param_env)?.obligations); } Ok(InferOk { value: result_subst, obligations }) diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index cf57270df29..748fe1379cd 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -6,7 +6,6 @@ use rustc_data_structures::sync::Lrc; use rustc_data_structures::vec_map::VecMap; use rustc_hir as hir; use rustc_middle::traits::ObligationCause; -use rustc_middle::ty::error::TypeError; use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::subst::{GenericArgKind, Subst}; use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeVisitor}; @@ -33,61 +32,12 @@ pub struct OpaqueTypeDecl<'tcx> { /// 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 /// to obtain the canonical hidden type. - pub hidden_types: Vec<OpaqueHiddenType<'tcx>>, + pub hidden_type: OpaqueHiddenType<'tcx>, /// The origin of the opaque type. pub origin: hir::OpaqueTyOrigin, } -impl<'tcx> OpaqueTypeDecl<'tcx> { - pub fn hidden_type( - &self, - infcx: &InferCtxt<'_, 'tcx>, - cause: &ObligationCause<'tcx>, - param_env: ty::ParamEnv<'tcx>, - ) -> Result< - InferOk<'tcx, OpaqueHiddenType<'tcx>>, - (TypeError<'tcx>, OpaqueHiddenType<'tcx>, OpaqueHiddenType<'tcx>), - > { - let mut value = self.hidden_types[0]; - let mut obligations = vec![]; - let mut error: Option<(_, _, OpaqueHiddenType<'tcx>)> = None; - for &next in self.hidden_types[1..].iter() { - // FIXME: make use of the spans to get nicer diagnostics! - let res = match infcx.at(cause, param_env).eq(value.ty, next.ty) { - Ok(res) => res, - Err(e) => { - // Try to improve the span. Sometimes we have dummy spans, sometimes we are pointing - // at an if/match instead of at the arm that gave us the type, but later spans point - // to the right thing. - if let Some((_, _, old)) = &mut error { - old.span = old.span.substitute_dummy(next.span); - // Shrink the span if possible - if old.span.contains(next.span) { - old.span = next.span; - } - } else { - let mut next = next; - next.span = next.span.substitute_dummy(cause.span(infcx.tcx)); - error = Some((e, value, next)); - } - continue; - } - }; - obligations.extend(res.obligations); - value.span = value.span.substitute_dummy(next.span); - // Shrink the span if possible - if value.span.contains(next.span) { - value.span = next.span; - } - } - match error { - None => Ok(InferOk { value, obligations }), - Some(e) => Err(e), - } - } -} - #[derive(Copy, Clone, Debug, TypeFoldable)] pub struct OpaqueHiddenType<'tcx> { /// The span of this particular definition of the opaque type. So diff --git a/compiler/rustc_infer/src/infer/opaque_types/table.rs b/compiler/rustc_infer/src/infer/opaque_types/table.rs index 1895c1a85c7..7f16a2f5332 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/table.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/table.rs @@ -20,7 +20,7 @@ impl<'tcx> OpaqueTypeStorage<'tcx> { #[instrument(level = "debug")] pub(crate) fn remove(&mut self, key: OpaqueTypeKey<'tcx>, idx: Option<OpaqueHiddenType<'tcx>>) { if let Some(idx) = idx { - self.opaque_types.get_mut(&key).unwrap().hidden_types[0] = idx; + self.opaque_types.get_mut(&key).unwrap().hidden_type = idx; } else { match self.opaque_types.remove(&key) { None => bug!("reverted opaque type inference that was never registered: {:?}", key), @@ -73,17 +73,15 @@ impl<'a, 'tcx> OpaqueTypeTable<'a, 'tcx> { &mut self, key: OpaqueTypeKey<'tcx>, opaque_type: Ty<'tcx>, - ty: OpaqueHiddenType<'tcx>, + hidden_type: OpaqueHiddenType<'tcx>, origin: OpaqueTyOrigin, ) -> Option<Ty<'tcx>> { if let Some(decl) = self.storage.opaque_types.get_mut(&key) { - assert_eq!(decl.hidden_types.len(), 1); - let prev = decl.hidden_types[0]; - decl.hidden_types = vec![ty]; + 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 { opaque_type, hidden_types: vec![ty], origin }; + let decl = OpaqueTypeDecl { opaque_type, hidden_type, origin }; self.storage.opaque_types.insert(key, decl); self.undo_log.push(UndoLog::OpaqueTypes(key, None)); None |
