Skip to content

Commit c8e4206

Browse files
Address nits
- Remove the ValuePairs glob import - Make DummyPairs -> ValuePairs::Dummy and make it bug more - Fix WC - Make interner return `impl IntoIterator`s
1 parent a2fb2eb commit c8e4206

File tree

9 files changed

+85
-78
lines changed

9 files changed

+85
-78
lines changed

compiler/rustc_infer/src/infer/at.rs

+23-14
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
347347
) -> TypeTrace<'tcx> {
348348
TypeTrace {
349349
cause: cause.clone(),
350-
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
350+
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
351351
}
352352
}
353353
}
@@ -359,7 +359,10 @@ impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
359359
a: Self,
360360
b: Self,
361361
) -> TypeTrace<'tcx> {
362-
TypeTrace { cause: cause.clone(), values: Regions(ExpectedFound::new(a_is_expected, a, b)) }
362+
TypeTrace {
363+
cause: cause.clone(),
364+
values: ValuePairs::Regions(ExpectedFound::new(a_is_expected, a, b)),
365+
}
363366
}
364367
}
365368

@@ -372,7 +375,7 @@ impl<'tcx> ToTrace<'tcx> for Const<'tcx> {
372375
) -> TypeTrace<'tcx> {
373376
TypeTrace {
374377
cause: cause.clone(),
375-
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
378+
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
376379
}
377380
}
378381
}
@@ -388,13 +391,13 @@ impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
388391
cause: cause.clone(),
389392
values: match (a.unpack(), b.unpack()) {
390393
(GenericArgKind::Lifetime(a), GenericArgKind::Lifetime(b)) => {
391-
Regions(ExpectedFound::new(a_is_expected, a, b))
394+
ValuePairs::Regions(ExpectedFound::new(a_is_expected, a, b))
392395
}
393396
(GenericArgKind::Type(a), GenericArgKind::Type(b)) => {
394-
Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
397+
ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
395398
}
396399
(GenericArgKind::Const(a), GenericArgKind::Const(b)) => {
397-
Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
400+
ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
398401
}
399402

400403
(
@@ -423,7 +426,10 @@ impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
423426
a: Self,
424427
b: Self,
425428
) -> TypeTrace<'tcx> {
426-
TypeTrace { cause: cause.clone(), values: Terms(ExpectedFound::new(a_is_expected, a, b)) }
429+
TypeTrace {
430+
cause: cause.clone(),
431+
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a, b)),
432+
}
427433
}
428434
}
429435

@@ -436,7 +442,7 @@ impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
436442
) -> TypeTrace<'tcx> {
437443
TypeTrace {
438444
cause: cause.clone(),
439-
values: TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
445+
values: ValuePairs::TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
440446
}
441447
}
442448
}
@@ -450,7 +456,7 @@ impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> {
450456
) -> TypeTrace<'tcx> {
451457
TypeTrace {
452458
cause: cause.clone(),
453-
values: Aliases(ExpectedFound::new(a_is_expected, a.into(), b.into())),
459+
values: ValuePairs::Aliases(ExpectedFound::new(a_is_expected, a.into(), b.into())),
454460
}
455461
}
456462
}
@@ -462,7 +468,10 @@ impl<'tcx> ToTrace<'tcx> for ty::AliasTerm<'tcx> {
462468
a: Self,
463469
b: Self,
464470
) -> TypeTrace<'tcx> {
465-
TypeTrace { cause: cause.clone(), values: Aliases(ExpectedFound::new(a_is_expected, a, b)) }
471+
TypeTrace {
472+
cause: cause.clone(),
473+
values: ValuePairs::Aliases(ExpectedFound::new(a_is_expected, a, b)),
474+
}
466475
}
467476
}
468477

@@ -475,7 +484,7 @@ impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
475484
) -> TypeTrace<'tcx> {
476485
TypeTrace {
477486
cause: cause.clone(),
478-
values: PolySigs(ExpectedFound::new(
487+
values: ValuePairs::PolySigs(ExpectedFound::new(
479488
a_is_expected,
480489
ty::Binder::dummy(a),
481490
ty::Binder::dummy(b),
@@ -493,7 +502,7 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyFnSig<'tcx> {
493502
) -> TypeTrace<'tcx> {
494503
TypeTrace {
495504
cause: cause.clone(),
496-
values: PolySigs(ExpectedFound::new(a_is_expected, a, b)),
505+
values: ValuePairs::PolySigs(ExpectedFound::new(a_is_expected, a, b)),
497506
}
498507
}
499508
}
@@ -507,7 +516,7 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyExistentialTraitRef<'tcx> {
507516
) -> TypeTrace<'tcx> {
508517
TypeTrace {
509518
cause: cause.clone(),
510-
values: ExistentialTraitRef(ExpectedFound::new(a_is_expected, a, b)),
519+
values: ValuePairs::ExistentialTraitRef(ExpectedFound::new(a_is_expected, a, b)),
511520
}
512521
}
513522
}
@@ -521,7 +530,7 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyExistentialProjection<'tcx> {
521530
) -> TypeTrace<'tcx> {
522531
TypeTrace {
523532
cause: cause.clone(),
524-
values: ExistentialProjection(ExpectedFound::new(a_is_expected, a, b)),
533+
values: ValuePairs::ExistentialProjection(ExpectedFound::new(a_is_expected, a, b)),
525534
}
526535
}
527536
}

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

+13-9
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
17071707
ValuePairs::ExistentialProjection(_) => {
17081708
(false, Mismatch::Fixed("existential projection"))
17091709
}
1710-
infer::DummyPair => (false, Mismatch::Fixed("values")),
1710+
ValuePairs::Dummy => {
1711+
bug!("do not expect to report a type error from a ValuePairs::Dummy")
1712+
}
17111713
};
17121714
let Some(vals) = self.values_str(values) else {
17131715
// Derived error. Cancel the emitter.
@@ -2251,12 +2253,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22512253
values: ValuePairs<'tcx>,
22522254
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
22532255
match values {
2254-
infer::Regions(exp_found) => self.expected_found_str(exp_found),
2255-
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
2256-
infer::Aliases(exp_found) => self.expected_found_str(exp_found),
2257-
infer::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found),
2258-
infer::ExistentialProjection(exp_found) => self.expected_found_str(exp_found),
2259-
infer::TraitRefs(exp_found) => {
2256+
ValuePairs::Regions(exp_found) => self.expected_found_str(exp_found),
2257+
ValuePairs::Terms(exp_found) => self.expected_found_str_term(exp_found),
2258+
ValuePairs::Aliases(exp_found) => self.expected_found_str(exp_found),
2259+
ValuePairs::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found),
2260+
ValuePairs::ExistentialProjection(exp_found) => self.expected_found_str(exp_found),
2261+
ValuePairs::TraitRefs(exp_found) => {
22602262
let pretty_exp_found = ty::error::ExpectedFound {
22612263
expected: exp_found.expected.print_trait_sugared(),
22622264
found: exp_found.found.print_trait_sugared(),
@@ -2268,15 +2270,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
22682270
ret => ret,
22692271
}
22702272
}
2271-
infer::PolySigs(exp_found) => {
2273+
ValuePairs::PolySigs(exp_found) => {
22722274
let exp_found = self.resolve_vars_if_possible(exp_found);
22732275
if exp_found.references_error() {
22742276
return None;
22752277
}
22762278
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found);
22772279
Some((exp, fnd, None))
22782280
}
2279-
infer::DummyPair => None,
2281+
ValuePairs::Dummy => {
2282+
bug!("do not expect to report a type error from a ValuePairs::Dummy")
2283+
}
22802284
}
22812285
}
22822286

compiler/rustc_infer/src/infer/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub use rustc_middle::ty::IntVarValue;
99
pub use BoundRegionConversionTime::*;
1010
pub use RegionVariableOrigin::*;
1111
pub use SubregionOrigin::*;
12-
pub use ValuePairs::*;
1312

1413
use crate::infer::relate::{Relate, RelateResult};
1514
use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligation, TraitEngine};
@@ -484,7 +483,7 @@ pub enum ValuePairs<'tcx> {
484483
PolySigs(ExpectedFound<ty::PolyFnSig<'tcx>>),
485484
ExistentialTraitRef(ExpectedFound<ty::PolyExistentialTraitRef<'tcx>>),
486485
ExistentialProjection(ExpectedFound<ty::PolyExistentialProjection<'tcx>>),
487-
DummyPair,
486+
Dummy,
488487
}
489488

490489
impl<'tcx> ValuePairs<'tcx> {
@@ -1880,7 +1879,7 @@ impl<'tcx> TypeTrace<'tcx> {
18801879
) -> TypeTrace<'tcx> {
18811880
TypeTrace {
18821881
cause: cause.clone(),
1883-
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
1882+
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
18841883
}
18851884
}
18861885

@@ -1892,7 +1891,7 @@ impl<'tcx> TypeTrace<'tcx> {
18921891
) -> TypeTrace<'tcx> {
18931892
TypeTrace {
18941893
cause: cause.clone(),
1895-
values: TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
1894+
values: ValuePairs::TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
18961895
}
18971896
}
18981897

@@ -1904,12 +1903,12 @@ impl<'tcx> TypeTrace<'tcx> {
19041903
) -> TypeTrace<'tcx> {
19051904
TypeTrace {
19061905
cause: cause.clone(),
1907-
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
1906+
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
19081907
}
19091908
}
19101909

19111910
fn dummy(cause: &ObligationCause<'tcx>) -> TypeTrace<'tcx> {
1912-
TypeTrace { cause: cause.clone(), values: ValuePairs::DummyPair }
1911+
TypeTrace { cause: cause.clone(), values: ValuePairs::Dummy }
19131912
}
19141913
}
19151914

compiler/rustc_middle/src/ty/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
263263
fn bound_coroutine_hidden_types(
264264
self,
265265
def_id: DefId,
266-
) -> impl Iterator<Item = ty::EarlyBinder<'tcx, ty::Binder<'tcx, Ty<'tcx>>>> {
266+
) -> impl IntoIterator<Item = ty::EarlyBinder<'tcx, ty::Binder<'tcx, Ty<'tcx>>>> {
267267
self.bound_coroutine_hidden_types(def_id)
268268
}
269269

@@ -286,14 +286,14 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
286286
fn item_bounds(
287287
self,
288288
def_id: DefId,
289-
) -> ty::EarlyBinder<'tcx, impl Iterator<Item = ty::Clause<'tcx>>> {
289+
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
290290
self.item_bounds(def_id).map_bound(IntoIterator::into_iter)
291291
}
292292

293293
fn super_predicates_of(
294294
self,
295295
def_id: DefId,
296-
) -> ty::EarlyBinder<'tcx, impl Iterator<Item = ty::Clause<'tcx>>> {
296+
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
297297
ty::EarlyBinder::bind(
298298
self.super_predicates_of(def_id).instantiate_identity(self).predicates.into_iter(),
299299
)
@@ -315,7 +315,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
315315
)
316316
}
317317

318-
fn associated_type_def_ids(self, def_id: DefId) -> impl Iterator<Item = DefId> {
318+
fn associated_type_def_ids(self, def_id: DefId) -> impl IntoIterator<Item = DefId> {
319319
self.associated_items(def_id)
320320
.in_definition_order()
321321
.filter(|assoc_item| matches!(assoc_item.kind, ty::AssocKind::Type))

compiler/rustc_middle/src/ty/predicate.rs

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ impl<'tcx> rustc_type_ir::inherent::Predicate<TyCtxt<'tcx>> for Predicate<'tcx>
4949
fn is_coinductive(self, interner: TyCtxt<'tcx>) -> bool {
5050
self.is_coinductive(interner)
5151
}
52+
53+
fn allow_normalization(self) -> bool {
54+
self.allow_normalization()
55+
}
5256
}
5357

5458
impl<'tcx> rustc_type_ir::inherent::IntoKind for Predicate<'tcx> {

compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

+26-20
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ use crate::solve::EvalCtxt;
1717
// For types with an "existential" binder, i.e. coroutine witnesses, we also
1818
// instantiate the binder with placeholders eagerly.
1919
#[instrument(level = "trace", skip(ecx), ret)]
20-
pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<
21-
Infcx: InferCtxtLike<Interner = I>,
22-
I: Interner,
23-
>(
20+
pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<Infcx, I>(
2421
ecx: &EvalCtxt<'_, Infcx>,
2522
ty: I::Ty,
26-
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution> {
23+
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution>
24+
where
25+
Infcx: InferCtxtLike<Interner = I>,
26+
I: Interner,
27+
{
2728
let tcx = ecx.interner();
2829
match ty.kind() {
2930
ty::Uint(_)
@@ -79,6 +80,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<
7980
ty::CoroutineWitness(def_id, args) => Ok(ecx
8081
.interner()
8182
.bound_coroutine_hidden_types(def_id)
83+
.into_iter()
8284
.map(|bty| bty.instantiate(tcx, &args))
8385
.collect()),
8486

@@ -101,13 +103,14 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<
101103
}
102104

103105
#[instrument(level = "trace", skip(ecx), ret)]
104-
pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<
105-
Infcx: InferCtxtLike<Interner = I>,
106-
I: Interner,
107-
>(
106+
pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<Infcx, I>(
108107
ecx: &EvalCtxt<'_, Infcx>,
109108
ty: I::Ty,
110-
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution> {
109+
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution>
110+
where
111+
Infcx: InferCtxtLike<Interner = I>,
112+
I: Interner,
113+
{
111114
match ty.kind() {
112115
// impl Sized for u*, i*, bool, f*, FnDef, FnPtr, *(const/mut) T, char, &mut? T, [T; N], dyn* Trait, !
113116
// impl Sized for Coroutine, CoroutineWitness, Closure, CoroutineClosure
@@ -168,13 +171,14 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<
168171
}
169172

170173
#[instrument(level = "trace", skip(ecx), ret)]
171-
pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<
172-
Infcx: InferCtxtLike<Interner = I>,
173-
I: Interner,
174-
>(
174+
pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<Infcx, I>(
175175
ecx: &EvalCtxt<'_, Infcx>,
176176
ty: I::Ty,
177-
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution> {
177+
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution>
178+
where
179+
Infcx: InferCtxtLike<Interner = I>,
180+
I: Interner,
181+
{
178182
match ty.kind() {
179183
// impl Copy/Clone for FnDef, FnPtr
180184
ty::FnDef(..) | ty::FnPtr(_) | ty::Error(_) => Ok(vec![]),
@@ -239,6 +243,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<
239243
ty::CoroutineWitness(def_id, args) => Ok(ecx
240244
.interner()
241245
.bound_coroutine_hidden_types(def_id)
246+
.into_iter()
242247
.map(|bty| bty.instantiate(ecx.interner(), &args))
243248
.collect()),
244249
}
@@ -651,15 +656,16 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
651656
// This is unsound in general and once that is fixed, we don't need to
652657
// normalize eagerly here. See https://github.com/lcnr/solver-woes/issues/9
653658
// for more details.
654-
pub(in crate::solve) fn predicates_for_object_candidate<
655-
Infcx: InferCtxtLike<Interner = I>,
656-
I: Interner,
657-
>(
659+
pub(in crate::solve) fn predicates_for_object_candidate<Infcx, I>(
658660
ecx: &EvalCtxt<'_, Infcx>,
659661
param_env: I::ParamEnv,
660662
trait_ref: ty::TraitRef<I>,
661663
object_bounds: I::BoundExistentialPredicates,
662-
) -> Vec<Goal<I, I::Predicate>> {
664+
) -> Vec<Goal<I, I::Predicate>>
665+
where
666+
Infcx: InferCtxtLike<Interner = I>,
667+
I: Interner,
668+
{
663669
let tcx = ecx.interner();
664670
let mut requirements = vec![];
665671
requirements

compiler/rustc_trait_selection/src/solve/inspect/build.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ use rustc_type_ir::{self as ty, InferCtxtLike, Interner};
3434
/// trees. At the end of trait solving `ProofTreeBuilder::finalize`
3535
/// is called to recursively convert the whole structure to a
3636
/// finished proof tree.
37-
pub(in crate::solve) struct ProofTreeBuilder<
37+
pub(in crate::solve) struct ProofTreeBuilder<Infcx, I = <Infcx as InferCtxtLike>::Interner>
38+
where
3839
Infcx: InferCtxtLike<Interner = I>,
39-
I: Interner = <Infcx as InferCtxtLike>::Interner,
40-
> {
40+
I: Interner,
41+
{
4142
_infcx: PhantomData<Infcx>,
4243
state: Option<Box<DebugSolver<I>>>,
4344
}

0 commit comments

Comments
 (0)