diff options
| author | Cameron Steffen <cam.steffen94@gmail.com> | 2022-10-23 17:32:40 -0500 |
|---|---|---|
| committer | Cameron Steffen <cam.steffen94@gmail.com> | 2022-11-20 19:04:11 -0600 |
| commit | cc8dddbac9e04f125c7e81dbe9fb6a01990e8b25 (patch) | |
| tree | d3e9773b74566031a5d1baff33bba3e8906e38be /compiler/rustc_middle | |
| parent | 34cbe727806429a8a034f492cff1b588e70c33dc (diff) | |
| download | rust-cc8dddbac9e04f125c7e81dbe9fb6a01990e8b25.tar.gz rust-cc8dddbac9e04f125c7e81dbe9fb6a01990e8b25.zip | |
Factor out conservative_is_privately_uninhabited
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/inhabitedness/mod.rs | 9 |
3 files changed, 16 insertions, 11 deletions
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 02772013437..21097b1fec6 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -2078,17 +2078,6 @@ rustc_queries! { desc { "normalizing opaque types in `{:?}`", key } } - /// Checks whether a type is definitely uninhabited. This is - /// conservative: for some types that are uninhabited we return `false`, - /// but we only return `true` for types that are definitely uninhabited. - /// `ty.conservative_is_privately_uninhabited` implies that any value of type `ty` - /// will be `Abi::Uninhabited`. (Note that uninhabited types may have nonzero - /// size, to account for partial initialisation. See #49298 for details.) - query conservative_is_privately_uninhabited(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool { - desc { "conservatively checking if `{}` is privately uninhabited", key.value } - remap_env_constness - } - query limits(key: ()) -> Limits { desc { "looking up limits" } } diff --git a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs index b7aa455727d..33f72729798 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs @@ -41,6 +41,13 @@ impl<'tcx> InhabitedPredicate<'tcx> { self.apply_inner(tcx, param_env, &|_| Err(())).ok() } + /// Same as `apply`, but `NotInModule(_)` predicates yield `false`. That is, + /// privately uninhabited types are considered always uninhabited. + pub fn apply_ignore_module(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> bool { + let Ok(result) = self.apply_inner::<!>(tcx, param_env, &|_| Ok(true)); + result + } + fn apply_inner<E>( self, tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index ce9ec5c2b69..ace81bc4f83 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -169,6 +169,15 @@ impl<'tcx> Ty<'tcx> { ) -> bool { self.inhabited_predicate(tcx).apply(tcx, param_env, module) } + + /// Returns true if the type is uninhabited without regard to visibility + pub fn is_privately_uninhabited( + self, + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + ) -> bool { + !self.inhabited_predicate(tcx).apply_ignore_module(tcx, param_env) + } } /// N.B. this query should only be called through `Ty::inhabited_predicate` |
