Skip to content

Commit 30bf3a6

Browse files
Uplift VarianceDiagInfo
1 parent d202a90 commit 30bf3a6

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
@@ -114,7 +114,7 @@ pub use self::rvalue_scopes::RvalueScopes;
114114
pub use self::sty::{
115115
AliasTy, Article, Binder, BoundTy, BoundTyKind, BoundVariableKind, CanonicalPolyFnSig,
116116
CoroutineArgsExt, EarlyBinder, FnSig, InlineConstArgs, InlineConstArgsParts, ParamConst,
117-
ParamTy, PolyFnSig, TyKind, TypeAndMut, UpvarArgs, VarianceDiagInfo,
117+
ParamTy, PolyFnSig, TyKind, TypeAndMut, UpvarArgs,
118118
};
119119
pub use self::trait_def::TraitDef;
120120
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
@@ -1790,43 +1790,6 @@ impl<'tcx> rustc_type_ir::inherent::Tys<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx
17901790
}
17911791
}
17921792

1793-
/// Extra information about why we ended up with a particular variance.
1794-
/// This is only used to add more information to error messages, and
1795-
/// has no effect on soundness. While choosing the 'wrong' `VarianceDiagInfo`
1796-
/// may lead to confusing notes in error messages, it will never cause
1797-
/// a miscompilation or unsoundness.
1798-
///
1799-
/// When in doubt, use `VarianceDiagInfo::default()`
1800-
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
1801-
pub enum VarianceDiagInfo<'tcx> {
1802-
/// No additional information - this is the default.
1803-
/// We will not add any additional information to error messages.
1804-
#[default]
1805-
None,
1806-
/// We switched our variance because a generic argument occurs inside
1807-
/// the invariant generic argument of another type.
1808-
Invariant {
1809-
/// The generic type containing the generic parameter
1810-
/// that changes the variance (e.g. `*mut T`, `MyStruct<T>`)
1811-
ty: Ty<'tcx>,
1812-
/// The index of the generic parameter being used
1813-
/// (e.g. `0` for `*mut T`, `1` for `MyStruct<'CovariantParam, 'InvariantParam>`)
1814-
param_index: u32,
1815-
},
1816-
}
1817-
1818-
impl<'tcx> VarianceDiagInfo<'tcx> {
1819-
/// Mirrors `Variance::xform` - used to 'combine' the existing
1820-
/// and new `VarianceDiagInfo`s when our variance changes.
1821-
pub fn xform(self, other: VarianceDiagInfo<'tcx>) -> VarianceDiagInfo<'tcx> {
1822-
// For now, just use the first `VarianceDiagInfo::Invariant` that we see
1823-
match self {
1824-
VarianceDiagInfo::None => other,
1825-
VarianceDiagInfo::Invariant { .. } => self,
1826-
}
1827-
}
1828-
}
1829-
18301793
// Some types are used a lot. Make sure they don't unintentionally get bigger.
18311794
#[cfg(target_pointer_width = "64")]
18321795
mod size_asserts {

0 commit comments

Comments
 (0)