Skip to content

Commit 424d131

Browse files
committed
w
1 parent c18dcab commit 424d131

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,12 @@ impl<'tcx, D: OutlivesHandlingDelegate<'tcx>> TypeOutlivesOpCtxt<'_, 'tcx, D> {
602602
region: ty::Region<'tcx>,
603603
alias_ty: ty::AliasTy<'tcx>,
604604
) {
605-
// An optimization for a common case with opaque types.
605+
// Optimization: If an alias doesn't have any arguments then it always
606+
// outlives `'static` via the OutlivesProjectionComponent rule.
607+
//
608+
// This can only happen with opaque types, e.g. `fn foo() -> impl Sized`. Other
609+
// kinds of aliases either always have parameters (the self type in projections)
610+
// or can be normalized e.g. free and inherent associated type aliases.
606611
if alias_ty.args.is_empty() {
607612
return;
608613
}
@@ -726,14 +731,20 @@ impl<'tcx, D: OutlivesHandlingDelegate<'tcx>> TypeOutlivesOpCtxt<'_, 'tcx, D> {
726731
} else {
727732
ty::Invariant
728733
};
729-
if variance == ty::Invariant {
730-
self.delegate.push_sub_region_constraint(
731-
origin.clone(),
732-
region,
733-
lt,
734-
constraint,
735-
);
734+
735+
if variance == ty::Bivariant {
736+
return
736737
}
738+
739+
// This method is only called for the args of type aliases which are
740+
// never covariant or contravariant.
741+
assert_eq!(variance, ty::Invariant);
742+
self.delegate.push_sub_region_constraint(
743+
origin.clone(),
744+
region,
745+
lt,
746+
constraint,
747+
);
737748
}
738749
GenericArgKind::Type(ty) => {
739750
require_type_outlives(self, origin.clone(), ty, region, constraint);

0 commit comments

Comments
 (0)