Skip to content

Commit dcbc704

Browse files
Uplift VarianceDiagInfo
1 parent f5ff4ae commit dcbc704

File tree

13 files changed

+14
-51
lines changed

13 files changed

+14
-51
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub struct OutlivesConstraint<'tcx> {
9797
pub category: ConstraintCategory<'tcx>,
9898

9999
/// Variance diagnostic information
100-
pub variance_info: VarianceDiagInfo<'tcx>,
100+
pub variance_info: VarianceDiagInfo<TyCtxt<'tcx>>,
101101

102102
/// If this constraint is promoted from closure requirements.
103103
pub from_closure: bool,

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2304,5 +2304,5 @@ pub struct BlameConstraint<'tcx> {
23042304
pub category: ConstraintCategory<'tcx>,
23052305
pub from_closure: bool,
23062306
pub cause: ObligationCause<'tcx>,
2307-
pub variance_info: ty::VarianceDiagInfo<'tcx>,
2307+
pub variance_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
23082308
}

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub struct NllTypeRelating<'me, 'bccx, 'tcx> {
8282
/// - Bivariant means that it doesn't matter.
8383
ambient_variance: ty::Variance,
8484

85-
ambient_variance_info: ty::VarianceDiagInfo<'tcx>,
85+
ambient_variance_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
8686
}
8787

8888
impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
@@ -296,7 +296,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
296296
&mut self,
297297
sup: ty::Region<'tcx>,
298298
sub: ty::Region<'tcx>,
299-
info: ty::VarianceDiagInfo<'tcx>,
299+
info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
300300
) {
301301
let sub = self.type_checker.borrowck_context.universal_regions.to_region_vid(sub);
302302
let sup = self.type_checker.borrowck_context.universal_regions.to_region_vid(sup);
@@ -327,7 +327,7 @@ impl<'bccx, 'tcx> TypeRelation<'tcx> for NllTypeRelating<'_, 'bccx, 'tcx> {
327327
fn relate_with_variance<T: Relate<'tcx>>(
328328
&mut self,
329329
variance: ty::Variance,
330-
info: ty::VarianceDiagInfo<'tcx>,
330+
info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
331331
a: T,
332332
b: T,
333333
) -> RelateResult<'tcx, T> {

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,7 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
27072707
fn relate_with_variance<T: relate::Relate<'tcx>>(
27082708
&mut self,
27092709
_variance: ty::Variance,
2710-
_info: ty::VarianceDiagInfo<'tcx>,
2710+
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
27112711
a: T,
27122712
b: T,
27132713
) -> relate::RelateResult<'tcx, T> {

compiler/rustc_infer/src/infer/outlives/test_type_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
148148
fn relate_with_variance<T: Relate<'tcx>>(
149149
&mut self,
150150
variance: ty::Variance,
151-
_: ty::VarianceDiagInfo<'tcx>,
151+
_: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
152152
a: T,
153153
b: T,
154154
) -> RelateResult<'tcx, T> {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
425425
fn relate_with_variance<T: Relate<'tcx>>(
426426
&mut self,
427427
variance: ty::Variance,
428-
_info: ty::VarianceDiagInfo<'tcx>,
428+
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
429429
a: T,
430430
b: T,
431431
) -> RelateResult<'tcx, T> {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
3333
fn relate_with_variance<T: Relate<'tcx>>(
3434
&mut self,
3535
variance: ty::Variance,
36-
_info: ty::VarianceDiagInfo<'tcx>,
36+
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
3737
a: T,
3838
b: T,
3939
) -> RelateResult<'tcx, T> {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
3333
fn relate_with_variance<T: Relate<'tcx>>(
3434
&mut self,
3535
variance: ty::Variance,
36-
_info: ty::VarianceDiagInfo<'tcx>,
36+
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
3737
a: T,
3838
b: T,
3939
) -> RelateResult<'tcx, T> {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'tcx> TypeRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
5959
fn relate_with_variance<T: Relate<'tcx>>(
6060
&mut self,
6161
variance: ty::Variance,
62-
_info: ty::VarianceDiagInfo<'tcx>,
62+
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
6363
a: T,
6464
b: T,
6565
) -> RelateResult<'tcx, T> {

compiler/rustc_middle/src/ty/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstFreshVars<'tcx> {
4141
fn relate_with_variance<T: Relate<'tcx>>(
4242
&mut self,
4343
_: ty::Variance,
44-
_: ty::VarianceDiagInfo<'tcx>,
44+
_: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
4545
a: T,
4646
b: T,
4747
) -> RelateResult<'tcx, T> {

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub use self::sty::{
116116
ClosureArgs, ClosureArgsParts, CoroutineArgs, CoroutineArgsParts, CoroutineClosureArgs,
117117
CoroutineClosureArgsParts, CoroutineClosureSignature, EarlyBinder, FnSig, GenSig,
118118
InlineConstArgs, InlineConstArgsParts, ParamConst, ParamTy, PolyFnSig, TyKind, TypeAndMut,
119-
UpvarArgs, VarianceDiagInfo,
119+
UpvarArgs,
120120
};
121121
pub use self::trait_def::TraitDef;
122122
pub use self::typeck_results::{

compiler/rustc_middle/src/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub trait TypeRelation<'tcx>: Sized {
5454
fn relate_with_variance<T: Relate<'tcx>>(
5555
&mut self,
5656
variance: ty::Variance,
57-
info: ty::VarianceDiagInfo<'tcx>,
57+
info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
5858
a: T,
5959
b: T,
6060
) -> RelateResult<'tcx, T>;

compiler/rustc_middle/src/ty/sty.rs

-37
Original file line numberDiff line numberDiff line change
@@ -2419,43 +2419,6 @@ impl<'tcx> rustc_type_ir::inherent::Tys<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx
24192419
}
24202420
}
24212421

2422-
/// Extra information about why we ended up with a particular variance.
2423-
/// This is only used to add more information to error messages, and
2424-
/// has no effect on soundness. While choosing the 'wrong' `VarianceDiagInfo`
2425-
/// may lead to confusing notes in error messages, it will never cause
2426-
/// a miscompilation or unsoundness.
2427-
///
2428-
/// When in doubt, use `VarianceDiagInfo::default()`
2429-
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
2430-
pub enum VarianceDiagInfo<'tcx> {
2431-
/// No additional information - this is the default.
2432-
/// We will not add any additional information to error messages.
2433-
#[default]
2434-
None,
2435-
/// We switched our variance because a generic argument occurs inside
2436-
/// the invariant generic argument of another type.
2437-
Invariant {
2438-
/// The generic type containing the generic parameter
2439-
/// that changes the variance (e.g. `*mut T`, `MyStruct<T>`)
2440-
ty: Ty<'tcx>,
2441-
/// The index of the generic parameter being used
2442-
/// (e.g. `0` for `*mut T`, `1` for `MyStruct<'CovariantParam, 'InvariantParam>`)
2443-
param_index: u32,
2444-
},
2445-
}
2446-
2447-
impl<'tcx> VarianceDiagInfo<'tcx> {
2448-
/// Mirrors `Variance::xform` - used to 'combine' the existing
2449-
/// and new `VarianceDiagInfo`s when our variance changes.
2450-
pub fn xform(self, other: VarianceDiagInfo<'tcx>) -> VarianceDiagInfo<'tcx> {
2451-
// For now, just use the first `VarianceDiagInfo::Invariant` that we see
2452-
match self {
2453-
VarianceDiagInfo::None => other,
2454-
VarianceDiagInfo::Invariant { .. } => self,
2455-
}
2456-
}
2457-
}
2458-
24592422
// Some types are used a lot. Make sure they don't unintentionally get bigger.
24602423
#[cfg(target_pointer_width = "64")]
24612424
mod size_asserts {

0 commit comments

Comments
 (0)