Skip to content

Commit 93b52c9

Browse files
committed
Auto merge of #126486 - matthiaskrgr:rollup-yrcxb34, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #125722 (Indicate in `non_local_defs` lint that the macro needs to change) - #125829 (rustc_span: Add conveniences for working with span formats) - #126192 (Various Redox OS fixes and add i686 Redox OS target) - #126352 (ci: Update centos:7 to use vault repos) - #126354 (Use `Variance` glob imported variants everywhere) - #126469 (MIR Shl/Shr: the offset can be computed with rem_euclid) - #126472 (build `libcxx-version` only when it doesn't exist) - #126476 (Fix running bootstrap tests with a local Rust toolchain as the stage0) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f8e5660 + d97c040 commit 93b52c9

File tree

46 files changed

+450
-258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+450
-258
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_const_eval/src/interpret/operator.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
112112

113113
// Shift ops can have an RHS with a different numeric type.
114114
if matches!(bin_op, Shl | ShlUnchecked | Shr | ShrUnchecked) {
115-
let size = left.layout.size.bits();
115+
let l_bits = left.layout.size.bits();
116116
// Compute the equivalent shift modulo `size` that is in the range `0..size`. (This is
117117
// the one MIR operator that does *not* directly map to a single LLVM operation.)
118118
let (shift_amount, overflow) = if right.layout.abi.is_signed() {
119119
let shift_amount = r_signed();
120-
let overflow = shift_amount < 0 || shift_amount >= i128::from(size);
121-
// Deliberately wrapping `as` casts: shift_amount *can* be negative, but the result
122-
// of the `as` will be equal modulo `size` (since it is a power of two).
123-
let masked_amount = (shift_amount as u128) % u128::from(size);
124-
assert_eq!(overflow, shift_amount != i128::try_from(masked_amount).unwrap());
125-
(masked_amount, overflow)
120+
let rem = shift_amount.rem_euclid(l_bits.into());
121+
// `rem` is guaranteed positive, so the `unwrap` cannot fail
122+
(u128::try_from(rem).unwrap(), rem != shift_amount)
126123
} else {
127124
let shift_amount = r_unsigned();
128-
let overflow = shift_amount >= u128::from(size);
129-
let masked_amount = shift_amount % u128::from(size);
130-
assert_eq!(overflow, shift_amount != masked_amount);
131-
(masked_amount, overflow)
125+
let rem = shift_amount.rem_euclid(l_bits.into());
126+
(rem, rem != shift_amount)
132127
};
133-
let shift_amount = u32::try_from(shift_amount).unwrap(); // we masked so this will always fit
128+
let shift_amount = u32::try_from(shift_amount).unwrap(); // we brought this in the range `0..size` so this will always fit
134129
// Compute the shifted result.
135130
let result = if left.layout.abi.is_signed() {
136131
let l = l_signed();

compiler/rustc_data_structures/src/flock.rs

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ cfg_match! {
99
mod linux;
1010
use linux as imp;
1111
}
12+
cfg(target_os = "redox") => {
13+
mod linux;
14+
use linux as imp;
15+
}
1216
cfg(unix) => {
1317
mod unix;
1418
use unix as imp;

compiler/rustc_expand/src/mbe/transcribe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl MutVisitor for Marker {
3131
// it's some advanced case with macro-generated macros. So if we cache the marked version
3232
// of that context once, we'll typically have a 100% cache hit rate after that.
3333
let Marker(expn_id, transparency, ref mut cache) = *self;
34-
span.update_ctxt(|ctxt| {
34+
*span = span.map_ctxt(|ctxt| {
3535
*cache
3636
.entry(ctxt)
3737
.or_insert_with(|| ctxt.apply_mark(expn_id.to_expn_id(), transparency))

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())?))

0 commit comments

Comments
 (0)