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
This commit is contained in:
commit
7ca0fd18f6
12 changed files with 117 additions and 50 deletions
|
@ -194,6 +194,14 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
|||
self.variances_of(def_id)
|
||||
}
|
||||
|
||||
fn opt_alias_variances(
|
||||
self,
|
||||
kind: impl Into<ty::AliasTermKind>,
|
||||
def_id: DefId,
|
||||
) -> Option<&'tcx [ty::Variance]> {
|
||||
self.opt_alias_variances(kind, def_id)
|
||||
}
|
||||
|
||||
fn type_of(self, def_id: DefId) -> ty::EarlyBinder<'tcx, Ty<'tcx>> {
|
||||
self.type_of(def_id)
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue