Skip to content

Commit 687a68d

Browse files
committed
Auto merge of #126514 - matthiaskrgr:rollup-pnwi8ns, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #126354 (Use `Variance` glob imported variants everywhere) - #126367 (Point out failing never obligation for `DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK`) - #126469 (MIR Shl/Shr: the offset can be computed with rem_euclid) - #126471 (Use a consistent way to filter out bounds instead of splitting it into three places) - #126472 (build `libcxx-version` only when it doesn't exist) - #126497 (delegation: Fix hygiene for `self`) - #126501 (make bors ignore comments in PR template) - #126509 (std: suggest OnceLock over Once) - #126512 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1d1356d + 92ad0b1 commit 687a68d

File tree

67 files changed

+1813
-330
lines changed

Some content is hidden

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

67 files changed

+1813
-330
lines changed

.github/pull_request_template.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- homu-ignore:start -->
12
<!--
23
If this PR is related to an unstable feature or an otherwise tracked effort,
34
please link to the relevant tracking issue here. If you don't know of a related
@@ -7,4 +8,5 @@ This PR will get automatically assigned to a reviewer. In case you would like
78
a specific user to review your work, you can assign it to them by using
89
910
r​? <reviewer name>
10-
-->
11+
-->
12+
<!-- homu-ignore:end -->

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_hir_typeck/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ hir_typeck_convert_using_method = try using `{$sugg}` to convert `{$found}` to `
4545
hir_typeck_ctor_is_private = tuple struct constructor `{$def}` is private
4646
4747
hir_typeck_dependency_on_unit_never_type_fallback = this function depends on never type fallback being `()`
48+
.note = in edition 2024, the requirement `{$obligation}` will fail
4849
.help = specify the types explicitly
4950
5051
hir_typeck_deref_is_empty = this expression `Deref`s to `{$deref_ty}` which implements `is_empty`

compiler/rustc_hir_typeck/src/errors.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_errors::{
77
SubdiagMessageOp, Subdiagnostic,
88
};
99
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
10-
use rustc_middle::ty::Ty;
10+
use rustc_middle::ty::{self, Ty};
1111
use rustc_span::{
1212
edition::{Edition, LATEST_STABLE_EDITION},
1313
symbol::Ident,
@@ -186,7 +186,11 @@ pub enum NeverTypeFallbackFlowingIntoUnsafe {
186186
#[derive(LintDiagnostic)]
187187
#[help]
188188
#[diag(hir_typeck_dependency_on_unit_never_type_fallback)]
189-
pub struct DependencyOnUnitNeverTypeFallback {}
189+
pub struct DependencyOnUnitNeverTypeFallback<'tcx> {
190+
#[note]
191+
pub obligation_span: Span,
192+
pub obligation: ty::Predicate<'tcx>,
193+
}
190194

191195
#[derive(Subdiagnostic)]
192196
#[multipart_suggestion(

compiler/rustc_hir_typeck/src/fallback.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
488488
let remaining_errors_if_fallback_to = |fallback| {
489489
self.probe(|_| {
490490
let obligations = self.fulfillment_cx.borrow().pending_obligations();
491-
let ocx = ObligationCtxt::new(&self.infcx);
491+
let ocx = ObligationCtxt::new_with_diagnostics(&self.infcx);
492492
ocx.register_obligations(obligations.iter().cloned());
493493

494494
for &diverging_vid in diverging_vids {
@@ -506,14 +506,18 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
506506
// then this code will be broken by the never type fallback change.qba
507507
let unit_errors = remaining_errors_if_fallback_to(self.tcx.types.unit);
508508
if unit_errors.is_empty()
509-
&& let never_errors = remaining_errors_if_fallback_to(self.tcx.types.never)
510-
&& !never_errors.is_empty()
509+
&& let mut never_errors = remaining_errors_if_fallback_to(self.tcx.types.never)
510+
&& let [ref mut never_error, ..] = never_errors.as_mut_slice()
511511
{
512+
self.adjust_fulfillment_error_for_expr_obligation(never_error);
512513
self.tcx.emit_node_span_lint(
513514
lint::builtin::DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
514515
self.tcx.local_def_id_to_hir_id(self.body_id),
515516
self.tcx.def_span(self.body_id),
516-
errors::DependencyOnUnitNeverTypeFallback {},
517+
errors::DependencyOnUnitNeverTypeFallback {
518+
obligation_span: never_error.obligation.cause.span,
519+
obligation: never_error.obligation.predicate,
520+
},
517521
)
518522
}
519523
}

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,

0 commit comments

Comments
 (0)