Skip to content

Commit 54fa4b0

Browse files
Use Variance glob import everywhere
1 parent 1d43fbb commit 54fa4b0

File tree

20 files changed

+74
-111
lines changed

20 files changed

+74
-111
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+6-6
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

+15-25
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

+4-4
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

+2-2
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

+1-3
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

+9-9
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

+1-6
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

+1-6
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

+5-5
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

-1
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

+1-1
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

+1-1
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

+1-1
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
},

0 commit comments

Comments
 (0)