Auto merge of #98614 - oli-obk:take_unsound_opaque_types, r=wesleywiser
don't succeed `evaluate_obligation` query if new opaque types were registered fixes #98608 fixes #98604 The root cause of all this is that in type flag computation we entirely ignore nongeneric things like struct fields and the signature of function items. So if a flag had to be set for a struct if it is set for a field, that will only happen if the field is generic, as only the generic parameters are checked. I now believe we cannot use type flags to handle opaque types. They seem like the wrong tool for this. Instead, this PR replaces the previous logic by adding a new variant of `EvaluatedToOk`: `EvaluatedToOkModuloOpaqueTypes`, which says that there were some opaque types that got hidden types bound, but that binding may not have been legal (because we don't know if the opaque type was in its defining scope or not).
This commit is contained in:
commit
052495d001
21 changed files with 116 additions and 187 deletions
|
@ -888,6 +888,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
.region_constraints_added_in_snapshot(&snapshot.undo_snapshot)
|
||||
}
|
||||
|
||||
pub fn opaque_types_added_in_snapshot(&self, snapshot: &CombinedSnapshot<'a, 'tcx>) -> bool {
|
||||
self.inner.borrow().undo_log.opaque_types_in_snapshot(&snapshot.undo_snapshot)
|
||||
}
|
||||
|
||||
pub fn add_given(&self, sub: ty::Region<'tcx>, sup: ty::RegionVid) {
|
||||
self.inner.borrow_mut().unwrap_region_constraints().add_given(sub, sup);
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
|
||||
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
|
||||
ty::Opaque(def_id, substs) => {
|
||||
ty::Opaque(def_id, substs) if def_id.is_local() => {
|
||||
let origin = if self.defining_use_anchor.is_some() {
|
||||
// Check that this is `impl Trait` type is
|
||||
// declared by `parent_def_id` -- i.e., one whose
|
||||
|
|
|
@ -185,6 +185,10 @@ impl<'tcx> InferCtxtUndoLogs<'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn opaque_types_in_snapshot(&self, s: &Snapshot<'tcx>) -> bool {
|
||||
self.logs[s.undo_len..].iter().any(|log| matches!(log, UndoLog::OpaqueTypes(..)))
|
||||
}
|
||||
|
||||
pub(crate) fn region_constraints(
|
||||
&self,
|
||||
) -> impl Iterator<Item = &'_ region_constraints::UndoLog<'tcx>> + Clone {
|
||||
|
|
|
@ -203,7 +203,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
|
|||
Some(&ProjectionCacheEntry::NormalizedTy { ref ty, complete: _ }) => {
|
||||
info!("ProjectionCacheEntry::complete({:?}) - completing {:?}", key, ty);
|
||||
let mut ty = ty.clone();
|
||||
if result == EvaluationResult::EvaluatedToOk {
|
||||
if result.must_apply_considering_regions() {
|
||||
ty.obligations = vec![];
|
||||
}
|
||||
map.insert(key, ProjectionCacheEntry::NormalizedTy { ty, complete: Some(result) });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue