Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 335e320

Browse files
authoredJun 15, 2024
Rollup merge of #126354 - compiler-errors:variance, r=lcnr
Use `Variance` glob imported variants everywhere Fully commit to using the globbed variance. Could be convinced the other way, and change this PR to not use the globbed variants anywhere, but I'd rather we do one or the other. r? lcnr
2 parents 8217b41 + 54fa4b0 commit 335e320

File tree

20 files changed

+74
-111
lines changed

20 files changed

+74
-111
lines changed
 

‎compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
328328
if let Some(annotation_index) = constant.user_ty {
329329
if let Err(terr) = self.cx.relate_type_and_user_type(
330330
constant.const_.ty(),
331-
ty::Variance::Invariant,
331+
ty::Invariant,
332332
&UserTypeProjection { base: annotation_index, projs: vec![] },
333333
locations,
334334
ConstraintCategory::Boring,
@@ -451,7 +451,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
451451

452452
if let Err(terr) = self.cx.relate_type_and_user_type(
453453
ty,
454-
ty::Variance::Invariant,
454+
ty::Invariant,
455455
user_ty,
456456
Locations::All(*span),
457457
ConstraintCategory::TypeAnnotation,
@@ -1095,7 +1095,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10951095
) -> Result<(), NoSolution> {
10961096
// Use this order of parameters because the sup type is usually the
10971097
// "expected" type in diagnostics.
1098-
self.relate_types(sup, ty::Variance::Contravariant, sub, locations, category)
1098+
self.relate_types(sup, ty::Contravariant, sub, locations, category)
10991099
}
11001100

11011101
#[instrument(skip(self, category), level = "debug")]
@@ -1106,7 +1106,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11061106
locations: Locations,
11071107
category: ConstraintCategory<'tcx>,
11081108
) -> Result<(), NoSolution> {
1109-
self.relate_types(expected, ty::Variance::Invariant, found, locations, category)
1109+
self.relate_types(expected, ty::Invariant, found, locations, category)
11101110
}
11111111

11121112
#[instrument(skip(self), level = "debug")]
@@ -1146,7 +1146,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11461146
trace!(?curr_projected_ty);
11471147

11481148
let ty = curr_projected_ty.ty;
1149-
self.relate_types(ty, v.xform(ty::Variance::Contravariant), a, locations, category)?;
1149+
self.relate_types(ty, v.xform(ty::Contravariant), a, locations, category)?;
11501150

11511151
Ok(())
11521152
}
@@ -1248,7 +1248,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12481248
if let Some(annotation_index) = self.rvalue_user_ty(rv) {
12491249
if let Err(terr) = self.relate_type_and_user_type(
12501250
rv_ty,
1251-
ty::Variance::Invariant,
1251+
ty::Invariant,
12521252
&UserTypeProjection { base: annotation_index, projs: vec![] },
12531253
location.to_locations(),
12541254
ConstraintCategory::Boring,

‎compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
5050
locations: Locations,
5151
category: ConstraintCategory<'tcx>,
5252
) -> Result<(), NoSolution> {
53-
NllTypeRelating::new(
54-
self,
55-
locations,
56-
category,
57-
UniverseInfo::other(),
58-
ty::Variance::Invariant,
59-
)
60-
.relate(a, b)?;
53+
NllTypeRelating::new(self, locations, category, UniverseInfo::other(), ty::Invariant)
54+
.relate(a, b)?;
6155
Ok(())
6256
}
6357
}
@@ -106,15 +100,15 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
106100

107101
fn ambient_covariance(&self) -> bool {
108102
match self.ambient_variance {
109-
ty::Variance::Covariant | ty::Variance::Invariant => true,
110-
ty::Variance::Contravariant | ty::Variance::Bivariant => false,
103+
ty::Covariant | ty::Invariant => true,
104+
ty::Contravariant | ty::Bivariant => false,
111105
}
112106
}
113107

114108
fn ambient_contravariance(&self) -> bool {
115109
match self.ambient_variance {
116-
ty::Variance::Contravariant | ty::Variance::Invariant => true,
117-
ty::Variance::Covariant | ty::Variance::Bivariant => false,
110+
ty::Contravariant | ty::Invariant => true,
111+
ty::Covariant | ty::Bivariant => false,
118112
}
119113
}
120114

@@ -336,11 +330,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
336330

337331
debug!(?self.ambient_variance);
338332
// In a bivariant context this always succeeds.
339-
let r = if self.ambient_variance == ty::Variance::Bivariant {
340-
Ok(a)
341-
} else {
342-
self.relate(a, b)
343-
};
333+
let r = if self.ambient_variance == ty::Bivariant { Ok(a) } else { self.relate(a, b) };
344334

345335
self.ambient_variance = old_ambient_variance;
346336

@@ -474,7 +464,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
474464
}
475465

476466
match self.ambient_variance {
477-
ty::Variance::Covariant => {
467+
ty::Covariant => {
478468
// Covariance, so we want `for<..> A <: for<..> B` --
479469
// therefore we compare any instantiation of A (i.e., A
480470
// instantiated with existentials) against every
@@ -489,7 +479,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
489479
})?;
490480
}
491481

492-
ty::Variance::Contravariant => {
482+
ty::Contravariant => {
493483
// Contravariance, so we want `for<..> A :> for<..> B` --
494484
// therefore we compare every instantiation of A (i.e., A
495485
// instantiated with universals) against any
@@ -504,7 +494,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
504494
})?;
505495
}
506496

507-
ty::Variance::Invariant => {
497+
ty::Invariant => {
508498
// Invariant, so we want `for<..> A == for<..> B` --
509499
// therefore we want `exists<..> A == for<..> B` and
510500
// `exists<..> B == for<..> A`.
@@ -525,7 +515,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
525515
})?;
526516
}
527517

528-
ty::Variance::Bivariant => {}
518+
ty::Bivariant => {}
529519
}
530520

531521
Ok(a)
@@ -584,23 +574,23 @@ impl<'bccx, 'tcx> PredicateEmittingRelation<'tcx> for NllTypeRelating<'_, 'bccx,
584574

585575
fn register_alias_relate_predicate(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
586576
self.register_predicates([ty::Binder::dummy(match self.ambient_variance {
587-
ty::Variance::Covariant => ty::PredicateKind::AliasRelate(
577+
ty::Covariant => ty::PredicateKind::AliasRelate(
588578
a.into(),
589579
b.into(),
590580
ty::AliasRelationDirection::Subtype,
591581
),
592582
// a :> b is b <: a
593-
ty::Variance::Contravariant => ty::PredicateKind::AliasRelate(
583+
ty::Contravariant => ty::PredicateKind::AliasRelate(
594584
b.into(),
595585
a.into(),
596586
ty::AliasRelationDirection::Subtype,
597587
),
598-
ty::Variance::Invariant => ty::PredicateKind::AliasRelate(
588+
ty::Invariant => ty::PredicateKind::AliasRelate(
599589
a.into(),
600590
b.into(),
601591
ty::AliasRelationDirection::Equate,
602592
),
603-
ty::Variance::Bivariant => {
593+
ty::Bivariant => {
604594
unreachable!("cannot defer an alias-relate goal with Bivariant variance (yet?)")
605595
}
606596
})]);

‎compiler/rustc_infer/src/infer/at.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,16 @@ impl<'a, 'tcx> At<'a, 'tcx> {
212212
T: ToTrace<'tcx>,
213213
{
214214
match variance {
215-
ty::Variance::Covariant => self.sub(define_opaque_types, expected, actual),
216-
ty::Variance::Invariant => self.eq(define_opaque_types, expected, actual),
217-
ty::Variance::Contravariant => self.sup(define_opaque_types, expected, actual),
215+
ty::Covariant => self.sub(define_opaque_types, expected, actual),
216+
ty::Invariant => self.eq(define_opaque_types, expected, actual),
217+
ty::Contravariant => self.sup(define_opaque_types, expected, actual),
218218

219219
// We could make this make sense but it's not readily
220220
// exposed and I don't feel like dealing with it. Note
221221
// that bivariance in general does a bit more than just
222222
// *nothing*, it checks that the types are the same
223223
// "modulo variance" basically.
224-
ty::Variance::Bivariant => panic!("Bivariant given to `relate()`"),
224+
ty::Bivariant => panic!("Bivariant given to `relate()`"),
225225
}
226226
}
227227

‎compiler/rustc_infer/src/infer/opaque_types/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl<'tcx> InferCtxt<'tcx> {
345345
.args
346346
.iter()
347347
.enumerate()
348-
.filter(|(i, _)| variances[*i] == ty::Variance::Invariant)
348+
.filter(|(i, _)| variances[*i] == ty::Invariant)
349349
.filter_map(|(_, arg)| match arg.unpack() {
350350
GenericArgKind::Lifetime(r) => Some(r),
351351
GenericArgKind::Type(_) | GenericArgKind::Const(_) => None,
@@ -441,7 +441,7 @@ where
441441
let variances = self.tcx.variances_of(*def_id);
442442

443443
for (v, s) in std::iter::zip(variances, args.iter()) {
444-
if *v != ty::Variance::Bivariant {
444+
if *v != ty::Bivariant {
445445
s.visit_with(self);
446446
}
447447
}

‎compiler/rustc_infer/src/infer/outlives/for_liveness.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ where
102102
};
103103

104104
for (idx, s) in args.iter().enumerate() {
105-
if variances.map(|variances| variances[idx])
106-
!= Some(ty::Variance::Bivariant)
107-
{
105+
if variances.map(|variances| variances[idx]) != Some(ty::Bivariant) {
108106
s.visit_with(self);
109107
}
110108
}

‎compiler/rustc_infer/src/infer/relate/generalize.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ impl<'tcx> InferCtxt<'tcx> {
8383
// mention `?0`.
8484
if self.next_trait_solver() {
8585
let (lhs, rhs, direction) = match instantiation_variance {
86-
ty::Variance::Invariant => {
86+
ty::Invariant => {
8787
(generalized_ty.into(), source_ty.into(), AliasRelationDirection::Equate)
8888
}
89-
ty::Variance::Covariant => {
89+
ty::Covariant => {
9090
(generalized_ty.into(), source_ty.into(), AliasRelationDirection::Subtype)
9191
}
92-
ty::Variance::Contravariant => {
92+
ty::Contravariant => {
9393
(source_ty.into(), generalized_ty.into(), AliasRelationDirection::Subtype)
9494
}
95-
ty::Variance::Bivariant => unreachable!("bivariant generalization"),
95+
ty::Bivariant => unreachable!("bivariant generalization"),
9696
};
9797

9898
relation.register_predicates([ty::PredicateKind::AliasRelate(lhs, rhs, direction)]);
@@ -192,7 +192,7 @@ impl<'tcx> InferCtxt<'tcx> {
192192
relation.span(),
193193
relation.structurally_relate_aliases(),
194194
target_vid,
195-
ty::Variance::Invariant,
195+
ty::Invariant,
196196
source_ct,
197197
)?;
198198

@@ -210,14 +210,14 @@ impl<'tcx> InferCtxt<'tcx> {
210210
// generalized const and the source.
211211
if target_is_expected {
212212
relation.relate_with_variance(
213-
ty::Variance::Invariant,
213+
ty::Invariant,
214214
ty::VarianceDiagInfo::default(),
215215
generalized_ct,
216216
source_ct,
217217
)?;
218218
} else {
219219
relation.relate_with_variance(
220-
ty::Variance::Invariant,
220+
ty::Invariant,
221221
ty::VarianceDiagInfo::default(),
222222
source_ct,
223223
generalized_ct,
@@ -411,7 +411,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
411411
a_arg: ty::GenericArgsRef<'tcx>,
412412
b_arg: ty::GenericArgsRef<'tcx>,
413413
) -> RelateResult<'tcx, ty::GenericArgsRef<'tcx>> {
414-
if self.ambient_variance == ty::Variance::Invariant {
414+
if self.ambient_variance == ty::Invariant {
415415
// Avoid fetching the variance if we are in an invariant
416416
// context; no need, and it can induce dependency cycles
417417
// (e.g., #41849).
@@ -667,7 +667,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
667667
// structural.
668668
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args }) => {
669669
let args = self.relate_with_variance(
670-
ty::Variance::Invariant,
670+
ty::Invariant,
671671
ty::VarianceDiagInfo::default(),
672672
args,
673673
args,

‎compiler/rustc_infer/src/infer/relate/glb.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
9494
// When higher-ranked types are involved, computing the GLB is
9595
// very challenging, switch to invariance. This is obviously
9696
// overly conservative but works ok in practice.
97-
self.relate_with_variance(
98-
ty::Variance::Invariant,
99-
ty::VarianceDiagInfo::default(),
100-
a,
101-
b,
102-
)?;
97+
self.relate_with_variance(ty::Invariant, ty::VarianceDiagInfo::default(), a, b)?;
10398
Ok(a)
10499
} else {
105100
Ok(ty::Binder::dummy(self.relate(a.skip_binder(), b.skip_binder())?))

‎compiler/rustc_infer/src/infer/relate/lub.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
9494
// When higher-ranked types are involved, computing the LUB is
9595
// very challenging, switch to invariance. This is obviously
9696
// overly conservative but works ok in practice.
97-
self.relate_with_variance(
98-
ty::Variance::Invariant,
99-
ty::VarianceDiagInfo::default(),
100-
a,
101-
b,
102-
)?;
97+
self.relate_with_variance(ty::Invariant, ty::VarianceDiagInfo::default(), a, b)?;
10398
Ok(a)
10499
} else {
105100
Ok(ty::Binder::dummy(self.relate(a.skip_binder(), b.skip_binder())?))

‎compiler/rustc_infer/src/infer/relate/type_relating.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
4242
a_arg: ty::GenericArgsRef<'tcx>,
4343
b_arg: ty::GenericArgsRef<'tcx>,
4444
) -> RelateResult<'tcx, ty::GenericArgsRef<'tcx>> {
45-
if self.ambient_variance == ty::Variance::Invariant {
45+
if self.ambient_variance == ty::Invariant {
4646
// Avoid fetching the variance if we are in an invariant
4747
// context; no need, and it can induce dependency cycles
4848
// (e.g., #41849).
@@ -325,23 +325,23 @@ impl<'tcx> PredicateEmittingRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
325325

326326
fn register_alias_relate_predicate(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
327327
self.register_predicates([ty::Binder::dummy(match self.ambient_variance {
328-
ty::Variance::Covariant => ty::PredicateKind::AliasRelate(
328+
ty::Covariant => ty::PredicateKind::AliasRelate(
329329
a.into(),
330330
b.into(),
331331
ty::AliasRelationDirection::Subtype,
332332
),
333333
// a :> b is b <: a
334-
ty::Variance::Contravariant => ty::PredicateKind::AliasRelate(
334+
ty::Contravariant => ty::PredicateKind::AliasRelate(
335335
b.into(),
336336
a.into(),
337337
ty::AliasRelationDirection::Subtype,
338338
),
339-
ty::Variance::Invariant => ty::PredicateKind::AliasRelate(
339+
ty::Invariant => ty::PredicateKind::AliasRelate(
340340
a.into(),
341341
b.into(),
342342
ty::AliasRelationDirection::Equate,
343343
),
344-
ty::Variance::Bivariant => {
344+
ty::Bivariant => {
345345
unreachable!("Expected bivariance to be handled in relate_with_variance")
346346
}
347347
})]);

‎compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub use self::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeV
1616
pub use self::AssocItemContainer::*;
1717
pub use self::BorrowKind::*;
1818
pub use self::IntVarValue::*;
19-
pub use self::Variance::*;
2019
use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason};
2120
use crate::metadata::ModChild;
2221
use crate::middle::privacy::EffectiveVisibilities;

‎compiler/rustc_middle/src/values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for &[ty::Variance] {
142142
&& let Some(def_id) = frame.query.def_id
143143
{
144144
let n = tcx.generics_of(def_id).own_params.len();
145-
vec![ty::Variance::Bivariant; n].leak()
145+
vec![ty::Bivariant; n].leak()
146146
} else {
147147
span_bug!(
148148
cycle_error.usage.as_ref().unwrap().0,

‎compiler/rustc_mir_build/src/build/matches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
699699
// exactly `T` (i.e., with invariance). The variance field, in
700700
// contrast, is intended to be used to relate `T` to the type of
701701
// `<expr>`.
702-
ty::Variance::Invariant,
702+
ty::Invariant,
703703
),
704704
},
705705
);

‎compiler/rustc_mir_build/src/thir/cx/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'tcx> Cx<'tcx> {
9292
kind: PatKind::AscribeUserType {
9393
ascription: Ascription {
9494
annotation,
95-
variance: ty::Variance::Covariant,
95+
variance: ty::Covariant,
9696
},
9797
subpattern: pattern,
9898
},

‎compiler/rustc_mir_build/src/thir/pattern/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
525525
};
526526
kind = PatKind::AscribeUserType {
527527
subpattern: Box::new(Pat { span, ty, kind }),
528-
ascription: Ascription { annotation, variance: ty::Variance::Covariant },
528+
ascription: Ascription { annotation, variance: ty::Covariant },
529529
};
530530
}
531531

@@ -612,7 +612,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
612612
annotation,
613613
// Note that use `Contravariant` here. See the
614614
// `variance` field documentation for details.
615-
variance: ty::Variance::Contravariant,
615+
variance: ty::Contravariant,
616616
},
617617
},
618618
ty: const_.ty(),

‎compiler/rustc_mir_transform/src/inline.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,8 @@ impl<'tcx> Inliner<'tcx> {
225225
// Normally, this shouldn't be required, but trait normalization failure can create a
226226
// validation ICE.
227227
let output_type = callee_body.return_ty();
228-
if !util::relate_types(
229-
self.tcx,
230-
self.param_env,
231-
ty::Variance::Covariant,
232-
output_type,
233-
destination_ty,
234-
) {
228+
if !util::relate_types(self.tcx, self.param_env, ty::Covariant, output_type, destination_ty)
229+
{
235230
trace!(?output_type, ?destination_ty);
236231
return Err("failed to normalize return type");
237232
}
@@ -261,13 +256,8 @@ impl<'tcx> Inliner<'tcx> {
261256
self_arg_ty.into_iter().chain(arg_tuple_tys).zip(callee_body.args_iter())
262257
{
263258
let input_type = callee_body.local_decls[input].ty;
264-
if !util::relate_types(
265-
self.tcx,
266-
self.param_env,
267-
ty::Variance::Covariant,
268-
input_type,
269-
arg_ty,
270-
) {
259+
if !util::relate_types(self.tcx, self.param_env, ty::Covariant, input_type, arg_ty)
260+
{
271261
trace!(?arg_ty, ?input_type);
272262
return Err("failed to normalize tuple argument type");
273263
}
@@ -276,13 +266,8 @@ impl<'tcx> Inliner<'tcx> {
276266
for (arg, input) in args.iter().zip(callee_body.args_iter()) {
277267
let input_type = callee_body.local_decls[input].ty;
278268
let arg_ty = arg.node.ty(&caller_body.local_decls, self.tcx);
279-
if !util::relate_types(
280-
self.tcx,
281-
self.param_env,
282-
ty::Variance::Covariant,
283-
input_type,
284-
arg_ty,
285-
) {
269+
if !util::relate_types(self.tcx, self.param_env, ty::Covariant, input_type, arg_ty)
270+
{
286271
trace!(?arg_ty, ?input_type);
287272
return Err("failed to normalize argument type");
288273
}

‎compiler/rustc_smir/src/rustc_smir/convert/ty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -866,10 +866,10 @@ impl<'tcx> Stable<'tcx> for ty::Variance {
866866
type T = stable_mir::mir::Variance;
867867
fn stable(&self, _: &mut Tables<'_>) -> Self::T {
868868
match self {
869-
ty::Variance::Bivariant => stable_mir::mir::Variance::Bivariant,
870-
ty::Variance::Contravariant => stable_mir::mir::Variance::Contravariant,
871-
ty::Variance::Covariant => stable_mir::mir::Variance::Covariant,
872-
ty::Variance::Invariant => stable_mir::mir::Variance::Invariant,
869+
ty::Bivariant => stable_mir::mir::Variance::Bivariant,
870+
ty::Contravariant => stable_mir::mir::Variance::Contravariant,
871+
ty::Covariant => stable_mir::mir::Variance::Covariant,
872+
ty::Invariant => stable_mir::mir::Variance::Invariant,
873873
}
874874
}
875875
}

‎compiler/rustc_trait_selection/src/solve/alias_relate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
6161
trace!(?lhs, ?rhs);
6262

6363
let variance = match direction {
64-
ty::AliasRelationDirection::Equate => ty::Variance::Invariant,
65-
ty::AliasRelationDirection::Subtype => ty::Variance::Covariant,
64+
ty::AliasRelationDirection::Equate => ty::Invariant,
65+
ty::AliasRelationDirection::Subtype => ty::Covariant,
6666
};
6767
match (lhs.to_alias_term(), rhs.to_alias_term()) {
6868
(None, None) => {
@@ -78,7 +78,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
7878
self.relate_rigid_alias_non_alias(
7979
param_env,
8080
alias,
81-
variance.xform(ty::Variance::Contravariant),
81+
variance.xform(ty::Contravariant),
8282
lhs,
8383
)?;
8484
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)

‎compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'tcx> EvalCtxt<'_, InferCtxt<'tcx>> {
4040
Ok(res) => Ok(res),
4141
Err(NoSolution) => {
4242
let Goal { param_env, predicate: NormalizesTo { alias, term } } = goal;
43-
self.relate_rigid_alias_non_alias(param_env, alias, ty::Variance::Invariant, term)?;
43+
self.relate_rigid_alias_non_alias(param_env, alias, ty::Invariant, term)?;
4444
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
4545
}
4646
}

‎compiler/rustc_type_ir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub use DynKind::*;
7474
pub use InferTy::*;
7575
pub use RegionKind::*;
7676
pub use TyKind::*;
77+
pub use Variance::*;
7778

7879
rustc_index::newtype_index! {
7980
/// A [De Bruijn index][dbi] is a standard means of representing

‎compiler/rustc_type_ir/src/relate.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub fn relate_args_invariantly<I: Interner, R: TypeRelation<I>>(
128128
b_arg: I::GenericArgs,
129129
) -> RelateResult<I, I::GenericArgs> {
130130
relation.tcx().mk_args_from_iter(iter::zip(a_arg, b_arg).map(|(a, b)| {
131-
relation.relate_with_variance(ty::Variance::Invariant, VarianceDiagInfo::default(), a, b)
131+
relation.relate_with_variance(ty::Invariant, VarianceDiagInfo::default(), a, b)
132132
}))
133133
}
134134

@@ -145,7 +145,7 @@ pub fn relate_args_with_variances<I: Interner, R: TypeRelation<I>>(
145145
let mut cached_ty = None;
146146
let params = iter::zip(a_arg, b_arg).enumerate().map(|(i, (a, b))| {
147147
let variance = variances[i];
148-
let variance_info = if variance == ty::Variance::Invariant && fetch_ty_for_diag {
148+
let variance_info = if variance == ty::Invariant && fetch_ty_for_diag {
149149
let ty =
150150
*cached_ty.get_or_insert_with(|| tcx.type_of(ty_def_id).instantiate(tcx, &a_arg));
151151
VarianceDiagInfo::Invariant { ty, param_index: i.try_into().unwrap() }
@@ -191,7 +191,7 @@ impl<I: Interner> Relate<I> for ty::FnSig<I> {
191191
relation.relate(a, b)
192192
} else {
193193
relation.relate_with_variance(
194-
ty::Variance::Contravariant,
194+
ty::Contravariant,
195195
VarianceDiagInfo::default(),
196196
a,
197197
b,
@@ -311,13 +311,13 @@ impl<I: Interner> Relate<I> for ty::ExistentialProjection<I> {
311311
}))
312312
} else {
313313
let term = relation.relate_with_variance(
314-
ty::Variance::Invariant,
314+
ty::Invariant,
315315
VarianceDiagInfo::default(),
316316
a.term,
317317
b.term,
318318
)?;
319319
let args = relation.relate_with_variance(
320-
ty::Variance::Invariant,
320+
ty::Invariant,
321321
VarianceDiagInfo::default(),
322322
a.args,
323323
b.args,
@@ -466,9 +466,9 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>(
466466
}
467467

468468
let (variance, info) = match a_mutbl {
469-
Mutability::Not => (ty::Variance::Covariant, VarianceDiagInfo::None),
469+
Mutability::Not => (ty::Covariant, VarianceDiagInfo::None),
470470
Mutability::Mut => {
471-
(ty::Variance::Invariant, VarianceDiagInfo::Invariant { ty: a, param_index: 0 })
471+
(ty::Invariant, VarianceDiagInfo::Invariant { ty: a, param_index: 0 })
472472
}
473473
};
474474

@@ -483,9 +483,9 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>(
483483
}
484484

485485
let (variance, info) = match a_mutbl {
486-
Mutability::Not => (ty::Variance::Covariant, VarianceDiagInfo::None),
486+
Mutability::Not => (ty::Covariant, VarianceDiagInfo::None),
487487
Mutability::Mut => {
488-
(ty::Variance::Invariant, VarianceDiagInfo::Invariant { ty: a, param_index: 0 })
488+
(ty::Invariant, VarianceDiagInfo::Invariant { ty: a, param_index: 0 })
489489
}
490490
};
491491

@@ -612,7 +612,7 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>(
612612
}
613613

614614
let args = relation.relate_with_variance(
615-
ty::Variance::Invariant,
615+
ty::Invariant,
616616
VarianceDiagInfo::default(),
617617
au.args,
618618
bu.args,

0 commit comments

Comments
 (0)
Please sign in to comment.