Skip to content

Commit bbc01bb

Browse files
committed
Auto merge of #80558 - lcnr:gat-variance, r=matthewjasper
require gat substs to be invariant fixes #69184, fixes #80766 r? `@matthewjasper` probably
2 parents 25f39fe + f32a6ac commit bbc01bb

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

compiler/rustc_typeck/src/variance/constraints.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -207,27 +207,13 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
207207
}
208208
}
209209

210-
fn add_constraints_from_trait_ref(
211-
&mut self,
212-
current: &CurrentItem,
213-
trait_ref: ty::TraitRef<'tcx>,
214-
variance: VarianceTermPtr<'a>,
215-
) {
216-
debug!("add_constraints_from_trait_ref: trait_ref={:?} variance={:?}", trait_ref, variance);
217-
self.add_constraints_from_invariant_substs(current, trait_ref.substs, variance);
218-
}
219-
210+
#[instrument(skip(self, current))]
220211
fn add_constraints_from_invariant_substs(
221212
&mut self,
222213
current: &CurrentItem,
223214
substs: SubstsRef<'tcx>,
224215
variance: VarianceTermPtr<'a>,
225216
) {
226-
debug!(
227-
"add_constraints_from_invariant_substs: substs={:?} variance={:?}",
228-
substs, variance
229-
);
230-
231217
// Trait are always invariant so we can take advantage of that.
232218
let variance_i = self.invariant(variance);
233219

@@ -300,8 +286,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
300286
}
301287

302288
ty::Projection(ref data) => {
303-
let tcx = self.tcx();
304-
self.add_constraints_from_trait_ref(current, data.trait_ref(tcx), variance);
289+
self.add_constraints_from_invariant_substs(current, data.substs, variance);
305290
}
306291

307292
ty::Opaque(_, substs) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
// issue #69184
3+
#![feature(generic_associated_types)]
4+
#![allow(incomplete_features)]
5+
6+
trait A {
7+
type B<'a>;
8+
9+
fn make_b<'a>(&'a self) -> Self::B<'a>;
10+
}
11+
12+
struct S {}
13+
impl A for S {
14+
type B<'a> = &'a S;
15+
fn make_b<'a>(&'a self) -> &'a Self {
16+
self
17+
}
18+
}
19+
20+
enum E<'a> {
21+
S(<S as A>::B<'a>),
22+
}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)