Skip to content

Commit

Permalink
Address nits
Browse files Browse the repository at this point in the history
- Remove the ValuePairs glob import
- Make DummyPairs -> ValuePairs::Dummy and make it bug more
- Fix WC
- Make interner return `impl IntoIterator`s
  • Loading branch information
compiler-errors committed Jun 13, 2024
1 parent a2fb2eb commit c8e4206
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 78 deletions.
37 changes: 23 additions & 14 deletions compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
}
}
}
Expand All @@ -359,7 +359,10 @@ impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
TypeTrace { cause: cause.clone(), values: Regions(ExpectedFound::new(a_is_expected, a, b)) }
TypeTrace {
cause: cause.clone(),
values: ValuePairs::Regions(ExpectedFound::new(a_is_expected, a, b)),
}
}
}

Expand All @@ -372,7 +375,7 @@ impl<'tcx> ToTrace<'tcx> for Const<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
}
}
}
Expand All @@ -388,13 +391,13 @@ impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
cause: cause.clone(),
values: match (a.unpack(), b.unpack()) {
(GenericArgKind::Lifetime(a), GenericArgKind::Lifetime(b)) => {
Regions(ExpectedFound::new(a_is_expected, a, b))
ValuePairs::Regions(ExpectedFound::new(a_is_expected, a, b))
}
(GenericArgKind::Type(a), GenericArgKind::Type(b)) => {
Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
}
(GenericArgKind::Const(a), GenericArgKind::Const(b)) => {
Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
}

(
Expand Down Expand Up @@ -423,7 +426,10 @@ impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
TypeTrace { cause: cause.clone(), values: Terms(ExpectedFound::new(a_is_expected, a, b)) }
TypeTrace {
cause: cause.clone(),
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a, b)),
}
}
}

Expand All @@ -436,7 +442,7 @@ impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
}
}
}
Expand All @@ -450,7 +456,7 @@ impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: Aliases(ExpectedFound::new(a_is_expected, a.into(), b.into())),
values: ValuePairs::Aliases(ExpectedFound::new(a_is_expected, a.into(), b.into())),
}
}
}
Expand All @@ -462,7 +468,10 @@ impl<'tcx> ToTrace<'tcx> for ty::AliasTerm<'tcx> {
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
TypeTrace { cause: cause.clone(), values: Aliases(ExpectedFound::new(a_is_expected, a, b)) }
TypeTrace {
cause: cause.clone(),
values: ValuePairs::Aliases(ExpectedFound::new(a_is_expected, a, b)),
}
}
}

Expand All @@ -475,7 +484,7 @@ impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: PolySigs(ExpectedFound::new(
values: ValuePairs::PolySigs(ExpectedFound::new(
a_is_expected,
ty::Binder::dummy(a),
ty::Binder::dummy(b),
Expand All @@ -493,7 +502,7 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyFnSig<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: PolySigs(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::PolySigs(ExpectedFound::new(a_is_expected, a, b)),
}
}
}
Expand All @@ -507,7 +516,7 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyExistentialTraitRef<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ExistentialTraitRef(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::ExistentialTraitRef(ExpectedFound::new(a_is_expected, a, b)),
}
}
}
Expand All @@ -521,7 +530,7 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyExistentialProjection<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: ExistentialProjection(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::ExistentialProjection(ExpectedFound::new(a_is_expected, a, b)),
}
}
}
22 changes: 13 additions & 9 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ValuePairs::ExistentialProjection(_) => {
(false, Mismatch::Fixed("existential projection"))
}
infer::DummyPair => (false, Mismatch::Fixed("values")),
ValuePairs::Dummy => {
bug!("do not expect to report a type error from a ValuePairs::Dummy")
}
};
let Some(vals) = self.values_str(values) else {
// Derived error. Cancel the emitter.
Expand Down Expand Up @@ -2251,12 +2253,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
values: ValuePairs<'tcx>,
) -> Option<(DiagStyledString, DiagStyledString, Option<PathBuf>)> {
match values {
infer::Regions(exp_found) => self.expected_found_str(exp_found),
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
infer::Aliases(exp_found) => self.expected_found_str(exp_found),
infer::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found),
infer::ExistentialProjection(exp_found) => self.expected_found_str(exp_found),
infer::TraitRefs(exp_found) => {
ValuePairs::Regions(exp_found) => self.expected_found_str(exp_found),
ValuePairs::Terms(exp_found) => self.expected_found_str_term(exp_found),
ValuePairs::Aliases(exp_found) => self.expected_found_str(exp_found),
ValuePairs::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found),
ValuePairs::ExistentialProjection(exp_found) => self.expected_found_str(exp_found),
ValuePairs::TraitRefs(exp_found) => {
let pretty_exp_found = ty::error::ExpectedFound {
expected: exp_found.expected.print_trait_sugared(),
found: exp_found.found.print_trait_sugared(),
Expand All @@ -2268,15 +2270,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ret => ret,
}
}
infer::PolySigs(exp_found) => {
ValuePairs::PolySigs(exp_found) => {
let exp_found = self.resolve_vars_if_possible(exp_found);
if exp_found.references_error() {
return None;
}
let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found);
Some((exp, fnd, None))
}
infer::DummyPair => None,
ValuePairs::Dummy => {
bug!("do not expect to report a type error from a ValuePairs::Dummy")
}
}
}

Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub use rustc_middle::ty::IntVarValue;
pub use BoundRegionConversionTime::*;
pub use RegionVariableOrigin::*;
pub use SubregionOrigin::*;
pub use ValuePairs::*;

use crate::infer::relate::{Relate, RelateResult};
use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligation, TraitEngine};
Expand Down Expand Up @@ -484,7 +483,7 @@ pub enum ValuePairs<'tcx> {
PolySigs(ExpectedFound<ty::PolyFnSig<'tcx>>),
ExistentialTraitRef(ExpectedFound<ty::PolyExistentialTraitRef<'tcx>>),
ExistentialProjection(ExpectedFound<ty::PolyExistentialProjection<'tcx>>),
DummyPair,
Dummy,
}

impl<'tcx> ValuePairs<'tcx> {
Expand Down Expand Up @@ -1880,7 +1879,7 @@ impl<'tcx> TypeTrace<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
}
}

Expand All @@ -1892,7 +1891,7 @@ impl<'tcx> TypeTrace<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
values: ValuePairs::TraitRefs(ExpectedFound::new(a_is_expected, a, b)),
}
}

Expand All @@ -1904,12 +1903,12 @@ impl<'tcx> TypeTrace<'tcx> {
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
values: ValuePairs::Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
}
}

fn dummy(cause: &ObligationCause<'tcx>) -> TypeTrace<'tcx> {
TypeTrace { cause: cause.clone(), values: ValuePairs::DummyPair }
TypeTrace { cause: cause.clone(), values: ValuePairs::Dummy }
}
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
fn bound_coroutine_hidden_types(
self,
def_id: DefId,
) -> impl Iterator<Item = ty::EarlyBinder<'tcx, ty::Binder<'tcx, Ty<'tcx>>>> {
) -> impl IntoIterator<Item = ty::EarlyBinder<'tcx, ty::Binder<'tcx, Ty<'tcx>>>> {
self.bound_coroutine_hidden_types(def_id)
}

Expand All @@ -286,14 +286,14 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
fn item_bounds(
self,
def_id: DefId,
) -> ty::EarlyBinder<'tcx, impl Iterator<Item = ty::Clause<'tcx>>> {
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
self.item_bounds(def_id).map_bound(IntoIterator::into_iter)
}

fn super_predicates_of(
self,
def_id: DefId,
) -> ty::EarlyBinder<'tcx, impl Iterator<Item = ty::Clause<'tcx>>> {
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
ty::EarlyBinder::bind(
self.super_predicates_of(def_id).instantiate_identity(self).predicates.into_iter(),
)
Expand All @@ -315,7 +315,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
)
}

fn associated_type_def_ids(self, def_id: DefId) -> impl Iterator<Item = DefId> {
fn associated_type_def_ids(self, def_id: DefId) -> impl IntoIterator<Item = DefId> {
self.associated_items(def_id)
.in_definition_order()
.filter(|assoc_item| matches!(assoc_item.kind, ty::AssocKind::Type))
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ impl<'tcx> rustc_type_ir::inherent::Predicate<TyCtxt<'tcx>> for Predicate<'tcx>
fn is_coinductive(self, interner: TyCtxt<'tcx>) -> bool {
self.is_coinductive(interner)
}

fn allow_normalization(self) -> bool {
self.allow_normalization()
}
}

impl<'tcx> rustc_type_ir::inherent::IntoKind for Predicate<'tcx> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ use crate::solve::EvalCtxt;
// For types with an "existential" binder, i.e. coroutine witnesses, we also
// instantiate the binder with placeholders eagerly.
#[instrument(level = "trace", skip(ecx), ret)]
pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
>(
pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<Infcx, I>(
ecx: &EvalCtxt<'_, Infcx>,
ty: I::Ty,
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution> {
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution>
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
{
let tcx = ecx.interner();
match ty.kind() {
ty::Uint(_)
Expand Down Expand Up @@ -79,6 +80,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<
ty::CoroutineWitness(def_id, args) => Ok(ecx
.interner()
.bound_coroutine_hidden_types(def_id)
.into_iter()
.map(|bty| bty.instantiate(tcx, &args))
.collect()),

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

#[instrument(level = "trace", skip(ecx), ret)]
pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
>(
pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<Infcx, I>(
ecx: &EvalCtxt<'_, Infcx>,
ty: I::Ty,
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution> {
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution>
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
{
match ty.kind() {
// impl Sized for u*, i*, bool, f*, FnDef, FnPtr, *(const/mut) T, char, &mut? T, [T; N], dyn* Trait, !
// impl Sized for Coroutine, CoroutineWitness, Closure, CoroutineClosure
Expand Down Expand Up @@ -168,13 +171,14 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<
}

#[instrument(level = "trace", skip(ecx), ret)]
pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
>(
pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<Infcx, I>(
ecx: &EvalCtxt<'_, Infcx>,
ty: I::Ty,
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution> {
) -> Result<Vec<ty::Binder<I, I::Ty>>, NoSolution>
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
{
match ty.kind() {
// impl Copy/Clone for FnDef, FnPtr
ty::FnDef(..) | ty::FnPtr(_) | ty::Error(_) => Ok(vec![]),
Expand Down Expand Up @@ -239,6 +243,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<
ty::CoroutineWitness(def_id, args) => Ok(ecx
.interner()
.bound_coroutine_hidden_types(def_id)
.into_iter()
.map(|bty| bty.instantiate(ecx.interner(), &args))
.collect()),
}
Expand Down Expand Up @@ -651,15 +656,16 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
// This is unsound in general and once that is fixed, we don't need to
// normalize eagerly here. See https://github.com/lcnr/solver-woes/issues/9
// for more details.
pub(in crate::solve) fn predicates_for_object_candidate<
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
>(
pub(in crate::solve) fn predicates_for_object_candidate<Infcx, I>(
ecx: &EvalCtxt<'_, Infcx>,
param_env: I::ParamEnv,
trait_ref: ty::TraitRef<I>,
object_bounds: I::BoundExistentialPredicates,
) -> Vec<Goal<I, I::Predicate>> {
) -> Vec<Goal<I, I::Predicate>>
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner,
{
let tcx = ecx.interner();
let mut requirements = vec![];
requirements
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_trait_selection/src/solve/inspect/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ use rustc_type_ir::{self as ty, InferCtxtLike, Interner};
/// trees. At the end of trait solving `ProofTreeBuilder::finalize`
/// is called to recursively convert the whole structure to a
/// finished proof tree.
pub(in crate::solve) struct ProofTreeBuilder<
pub(in crate::solve) struct ProofTreeBuilder<Infcx, I = <Infcx as InferCtxtLike>::Interner>
where
Infcx: InferCtxtLike<Interner = I>,
I: Interner = <Infcx as InferCtxtLike>::Interner,
> {
I: Interner,
{
_infcx: PhantomData<Infcx>,
state: Option<Box<DebugSolver<I>>>,
}
Expand Down
Loading

0 comments on commit c8e4206

Please sign in to comment.