diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-03-07 09:08:20 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-03-11 17:19:37 +0000 |
| commit | 7348dd1950ea0f14fcf6f521a85dd27796ef386a (patch) | |
| tree | 0ead441b61f526f5bcee37a686e84a245e3b3c53 | |
| parent | 40d56095486558e8b3a9ff11a0f0298e29c3fd65 (diff) | |
| download | rust-7348dd1950ea0f14fcf6f521a85dd27796ef386a.tar.gz rust-7348dd1950ea0f14fcf6f521a85dd27796ef386a.zip | |
Eliminate `DefiningAnchor::Error`, it is indistinguishable from `DefiningAnchor::Bind` with an empty list
5 files changed, 11 insertions, 18 deletions
diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 3bd4a23faed..8a172233037 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -311,7 +311,7 @@ fn check_opaque_type_well_formed<'tcx>( parent_def_id = tcx.local_parent(parent_def_id); } - // FIXME(-Znext-solver): We probably should use `DefiningAnchor::Error` + // FIXME(-Znext-solver): We probably should use `DefiningAnchor::Bind(&[])` // and prepopulate this `InferCtxt` with known opaque values, rather than // using the `Bind` anchor here. For now it's fine. let infcx = tcx diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 323a3c4b984..89e4e88b3df 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -242,7 +242,8 @@ pub struct InferCtxt<'tcx> { /// short lived InferCtxt within queries. The opaque type obligations are forwarded /// to the outside until the end up in an `InferCtxt` for typeck or borrowck. /// - /// Its default value is `DefiningAnchor::Error`, this way it is easier to catch errors that + /// Its default value is `DefiningAnchor::Bind(&[])`, which means no opaque types may be defined. + /// This way it is easier to catch errors that /// might come up during inference or typeck. pub defining_use_anchor: DefiningAnchor<'tcx>, @@ -620,7 +621,7 @@ impl<'tcx> TyCtxt<'tcx> { fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> { InferCtxtBuilder { tcx: self, - defining_use_anchor: DefiningAnchor::Error, + defining_use_anchor: DefiningAnchor::Bind(ty::List::empty()), considering_regions: true, skip_leak_check: false, intercrate: false, @@ -1208,13 +1209,11 @@ impl<'tcx> InferCtxt<'tcx> { #[instrument(level = "debug", skip(self), ret)] pub fn take_opaque_types(&self) -> opaque_types::OpaqueTypeMap<'tcx> { - debug_assert_ne!(self.defining_use_anchor, DefiningAnchor::Error); std::mem::take(&mut self.inner.borrow_mut().opaque_type_storage.opaque_types) } #[instrument(level = "debug", skip(self), ret)] pub fn clone_opaque_types(&self) -> opaque_types::OpaqueTypeMap<'tcx> { - debug_assert_ne!(self.defining_use_anchor, DefiningAnchor::Error); self.inner.borrow().opaque_type_storage.opaque_types.clone() } diff --git a/compiler/rustc_infer/src/infer/opaque_types/mod.rs b/compiler/rustc_infer/src/infer/opaque_types/mod.rs index 46ee00247aa..a6f8115c27e 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/mod.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/mod.rs @@ -150,9 +150,6 @@ impl<'tcx> InferCtxt<'tcx> { } } DefiningAnchor::Bubble => {} - DefiningAnchor::Error => { - return None; - } } if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() { // We could accept this, but there are various ways to handle this situation, and we don't @@ -379,7 +376,7 @@ impl<'tcx> InferCtxt<'tcx> { #[instrument(skip(self), level = "trace", ret)] pub fn opaque_type_origin(&self, def_id: LocalDefId) -> Option<OpaqueTyOrigin> { let defined_opaque_types = match self.defining_use_anchor { - DefiningAnchor::Bubble | DefiningAnchor::Error => return None, + DefiningAnchor::Bubble => return None, DefiningAnchor::Bind(bind) => bind, }; diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 4113be9f6be..aea58653351 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -1004,6 +1004,10 @@ pub enum CodegenObligationError { pub enum DefiningAnchor<'tcx> { /// Define opaques which are in-scope of the current item being analyzed. /// Also, eagerly replace these opaque types in `replace_opaque_types_with_inference_vars`. + /// + /// If the list is empty, do not allow any opaques to be defined. This is used to catch type mismatch + /// errors when handling opaque types, and also should be used when we would + /// otherwise reveal opaques (such as [`Reveal::All`] reveal mode). Bind(&'tcx ty::List<LocalDefId>), /// In contexts where we don't currently know what opaques are allowed to be /// defined, such as (old solver) canonical queries, we will simply allow @@ -1013,10 +1017,6 @@ pub enum DefiningAnchor<'tcx> { /// We do not eagerly replace opaque types in `replace_opaque_types_with_inference_vars`, /// which may affect what predicates pass and fail in the old trait solver. Bubble, - /// Do not allow any opaques to be defined. This is used to catch type mismatch - /// errors when handling opaque types, and also should be used when we would - /// otherwise reveal opaques (such as [`Reveal::All`] reveal mode). - Error, } impl<'tcx> DefiningAnchor<'tcx> { diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs index 22f52c27362..3b858cb449f 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs @@ -16,7 +16,7 @@ use rustc_middle::traits::solve::{ CanonicalInput, CanonicalResponse, Certainty, IsNormalizesToHack, PredefinedOpaques, PredefinedOpaquesData, QueryResult, }; -use rustc_middle::traits::{specialization_graph, DefiningAnchor}; +use rustc_middle::traits::specialization_graph; use rustc_middle::ty::{ self, InferCtxtLike, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, @@ -258,10 +258,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { // instead of taking them. This would cause an ICE here, since we have // assertions against dropping an `InferCtxt` without taking opaques. // FIXME: Once we remove support for the old impl we can remove this. - if input.anchor != DefiningAnchor::Error { - // This seems ok, but fragile. - let _ = infcx.take_opaque_types(); - } + let _ = infcx.take_opaque_types(); result } |
