diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-07 21:31:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-07 21:31:00 +0100 |
| commit | 7ca0fd18f6c7927de9f50bd3a229967d0c88e9f7 (patch) | |
| tree | 9277e38e1db825f419a8e5bee503d02736a4f832 /compiler/rustc_middle/src/ty/util.rs | |
| parent | c49fc911f451b6e27dcd7fbfac77ab2902fd3ae5 (diff) | |
| parent | d17a4a7f9ac94ea0901cd6f200ea73833eac6c05 (diff) | |
| download | rust-7ca0fd18f6c7927de9f50bd3a229967d0c88e9f7.tar.gz rust-7ca0fd18f6c7927de9f50bd3a229967d0c88e9f7.zip | |
Rollup merge of #136554 - compiler-errors:opt-alias-variances, r=lcnr
Add `opt_alias_variances` and use it in outlives code ...so to fix some subtle outlives bugs with precise capturing in traits, and eventually make it easier to compute variances for "forced unconstrained" trait lifetimes. r? lcnr
Diffstat (limited to 'compiler/rustc_middle/src/ty/util.rs')
| -rw-r--r-- | compiler/rustc_middle/src/ty/util.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 6fd0fb9a0a4..398ed57faeb 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -948,6 +948,29 @@ impl<'tcx> TyCtxt<'tcx> { ty } + + // Computes the variances for an alias (opaque or RPITIT) that represent + // its (un)captured regions. + pub fn opt_alias_variances( + self, + kind: impl Into<ty::AliasTermKind>, + def_id: DefId, + ) -> Option<&'tcx [ty::Variance]> { + match kind.into() { + ty::AliasTermKind::ProjectionTy => { + if self.is_impl_trait_in_trait(def_id) { + Some(self.variances_of(def_id)) + } else { + None + } + } + ty::AliasTermKind::OpaqueTy => Some(self.variances_of(def_id)), + ty::AliasTermKind::InherentTy + | ty::AliasTermKind::WeakTy + | ty::AliasTermKind::UnevaluatedConst + | ty::AliasTermKind::ProjectionConst => None, + } + } } struct OpaqueTypeExpander<'tcx> { |
