Auto merge of #80558 - lcnr:gat-variance, r=matthewjasper
require gat substs to be invariant fixes #69184, fixes #80766 r? `@matthewjasper` probably
This commit is contained in:
commit
bbc01bb624
@ -207,27 +207,13 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_constraints_from_trait_ref(
|
||||
&mut self,
|
||||
current: &CurrentItem,
|
||||
trait_ref: ty::TraitRef<'tcx>,
|
||||
variance: VarianceTermPtr<'a>,
|
||||
) {
|
||||
debug!("add_constraints_from_trait_ref: trait_ref={:?} variance={:?}", trait_ref, variance);
|
||||
self.add_constraints_from_invariant_substs(current, trait_ref.substs, variance);
|
||||
}
|
||||
|
||||
#[instrument(skip(self, current))]
|
||||
fn add_constraints_from_invariant_substs(
|
||||
&mut self,
|
||||
current: &CurrentItem,
|
||||
substs: SubstsRef<'tcx>,
|
||||
variance: VarianceTermPtr<'a>,
|
||||
) {
|
||||
debug!(
|
||||
"add_constraints_from_invariant_substs: substs={:?} variance={:?}",
|
||||
substs, variance
|
||||
);
|
||||
|
||||
// Trait are always invariant so we can take advantage of that.
|
||||
let variance_i = self.invariant(variance);
|
||||
|
||||
@ -300,8 +286,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
||||
}
|
||||
|
||||
ty::Projection(ref data) => {
|
||||
let tcx = self.tcx();
|
||||
self.add_constraints_from_trait_ref(current, data.trait_ref(tcx), variance);
|
||||
self.add_constraints_from_invariant_substs(current, data.substs, variance);
|
||||
}
|
||||
|
||||
ty::Opaque(_, substs) => {
|
||||
|
24
src/test/ui/generic-associated-types/variance_constraints.rs
Normal file
24
src/test/ui/generic-associated-types/variance_constraints.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// check-pass
|
||||
// issue #69184
|
||||
#![feature(generic_associated_types)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait A {
|
||||
type B<'a>;
|
||||
|
||||
fn make_b<'a>(&'a self) -> Self::B<'a>;
|
||||
}
|
||||
|
||||
struct S {}
|
||||
impl A for S {
|
||||
type B<'a> = &'a S;
|
||||
fn make_b<'a>(&'a self) -> &'a Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
enum E<'a> {
|
||||
S(<S as A>::B<'a>),
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
x
Reference in New Issue
Block a user