From 61b5e11c47c452ed987295b147783e8bd8e16434 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 15 Jul 2024 09:20:11 +0000 Subject: [PATCH] Don't use global caches if opaques can be defined --- compiler/rustc_trait_selection/src/traits/select/mod.rs | 8 +++++++- .../auto-traits/opaque_type_candidate_selection.rs} | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) rename tests/{crashes/119272.rs => ui/auto-traits/opaque_type_candidate_selection.rs} (91%) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index d6590322caab4..02ad361f9f59f 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1498,7 +1498,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return false; } - // Avoid using the master cache during coherence and just rely + // Avoid using the global cache during coherence and just rely // on the local cache. This effectively disables caching // during coherence. It is really just a simplification to // avoid us having to fear that coherence results "pollute" @@ -1509,6 +1509,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return false; } + // Avoid using the global cache when we're defining opaque types + // as their hidden type may impact the result of candidate selection. + if !self.infcx.defining_opaque_types().is_empty() { + return false; + } + // Otherwise, we can use the global cache. true } diff --git a/tests/crashes/119272.rs b/tests/ui/auto-traits/opaque_type_candidate_selection.rs similarity index 91% rename from tests/crashes/119272.rs rename to tests/ui/auto-traits/opaque_type_candidate_selection.rs index 02e2cfd09e2f8..d6973b76a6e1e 100644 --- a/tests/crashes/119272.rs +++ b/tests/ui/auto-traits/opaque_type_candidate_selection.rs @@ -1,4 +1,7 @@ -//@ known-bug: #119272 +//! used to ICE: #119272 + +//@ check-pass + #![feature(type_alias_impl_trait)] mod defining_scope { use super::*;