Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for CoerceVisitor<'_, 'tcx> {
ControlFlow::Break(())
}
}
Ok(Certainty::Maybe { .. }) => {
Ok(Certainty::Maybe(_)) => {
// FIXME: structurally normalize?
if self.fcx.tcx.is_lang_item(pred.def_id(), LangItem::Unsize)
&& let ty::Dynamic(..) = pred.skip_binder().trait_ref.args.type_at(1).kind()
Expand Down
20 changes: 11 additions & 9 deletions compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use derive_where::derive_where;
use rustc_type_ir::inherent::*;
use rustc_type_ir::lang_items::SolverTraitLangItem;
use rustc_type_ir::search_graph::CandidateHeadUsages;
use rustc_type_ir::solve::{AliasBoundKind, SizedTraitKind};
use rustc_type_ir::solve::{AliasBoundKind, MaybeInfo, SizedTraitKind, StalledOnCoroutines};
use rustc_type_ir::{
self as ty, AliasTy, Interner, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Unnormalized,
Expand Down Expand Up @@ -501,7 +501,7 @@ where

pub(super) fn forced_ambiguity(
&mut self,
cause: MaybeCause,
maybe: MaybeInfo,
) -> Result<Candidate<I>, NoSolution> {
// This may fail if `try_evaluate_added_goals` overflows because it
// fails to reach a fixpoint but ends up getting an error after
Expand All @@ -512,7 +512,7 @@ where
// created a minimization for an ICE in typenum, but that one no
// longer fails here. cc trait-system-refactor-initiative#105.
let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
let certainty = Certainty::Maybe { cause, opaque_types_jank: OpaqueTypesJank::AllGood };
let certainty = Certainty::Maybe(maybe);
self.probe_trait_candidate(source)
.enter(|this| this.evaluate_added_goals_and_make_canonical_response(certainty))
}
Expand Down Expand Up @@ -1031,7 +1031,7 @@ where
};

if opaque_types.is_empty() {
candidates.extend(self.forced_ambiguity(MaybeCause::Ambiguity));
candidates.extend(self.forced_ambiguity(MaybeInfo::AMBIGUOUS));
return;
}

Expand Down Expand Up @@ -1122,10 +1122,11 @@ where

if candidates.is_empty() {
let source = CandidateSource::BuiltinImpl(BuiltinImplSource::Misc);
let certainty = Certainty::Maybe {
let certainty = Certainty::Maybe(MaybeInfo {
cause: MaybeCause::Ambiguity,
opaque_types_jank: OpaqueTypesJank::ErrorIfRigidSelfTy,
};
stalled_on_coroutines: StalledOnCoroutines::No,
});
candidates
.extend(self.probe_trait_candidate(source).enter(|this| {
this.evaluate_added_goals_and_make_canonical_response(certainty)
Expand Down Expand Up @@ -1178,7 +1179,7 @@ where
//
// We use `forced_ambiguity` here over `make_ambiguous_response_no_constraints`
// because the former will also record a built-in candidate in the inspector.
return self.forced_ambiguity(MaybeCause::Ambiguity).map(|cand| cand.result);
return self.forced_ambiguity(MaybeInfo::AMBIGUOUS).map(|cand| cand.result);
};

match proven_via {
Expand Down Expand Up @@ -1326,13 +1327,14 @@ where
{
self.recursion_depth += 1;
if self.recursion_depth > self.ecx.cx().recursion_limit() {
return ControlFlow::Break(Ok(Certainty::Maybe {
return ControlFlow::Break(Ok(Certainty::Maybe(MaybeInfo {
cause: MaybeCause::Overflow {
suggest_increasing_limit: true,
keep_constraints: false,
},
opaque_types_jank: OpaqueTypesJank::AllGood,
}));
stalled_on_coroutines: StalledOnCoroutines::No,
})));
}
let result = ty.super_visit_with(self);
self.recursion_depth -= 1;
Expand Down
26 changes: 16 additions & 10 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_type_ir::inherent::*;
use rustc_type_ir::relate::Relate;
use rustc_type_ir::relate::solver_relating::RelateExt;
use rustc_type_ir::search_graph::{CandidateHeadUsages, PathKind};
use rustc_type_ir::solve::OpaqueTypesJank;
use rustc_type_ir::solve::{MaybeInfo, OpaqueTypesJank};
use rustc_type_ir::{
self as ty, CanonicalVarValues, InferCtxtLike, Interner, TypeFoldable, TypeFolder,
TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
Expand Down Expand Up @@ -217,7 +217,11 @@ where
})
.is_ok_and(|r| match r.certainty {
Certainty::Yes => true,
Certainty::Maybe { cause: _, opaque_types_jank } => match opaque_types_jank {
Certainty::Maybe(MaybeInfo {
cause: _,
opaque_types_jank,
stalled_on_coroutines: _,
}) => match opaque_types_jank {
OpaqueTypesJank::AllGood => true,
OpaqueTypesJank::ErrorIfRigidSelfTy => false,
},
Expand Down Expand Up @@ -1268,10 +1272,13 @@ where
}
};

if let Certainty::Maybe {
cause: cause @ MaybeCause::Overflow { keep_constraints: false, .. },
opaque_types_jank,
} = certainty
if let Certainty::Maybe(
maybe_info @ MaybeInfo {
cause: MaybeCause::Overflow { keep_constraints: false, .. },
opaque_types_jank: _,
stalled_on_coroutines: _,
},
) = certainty
{
// If we have overflow, it's probable that we're substituting a type
// into itself infinitely and any partial substitutions in the query
Expand All @@ -1284,7 +1291,7 @@ where
//
// Changing this to retain some constraints in the future
// won't be a breaking change, so this is good enough for now.
return Ok(self.make_ambiguous_response_no_constraints(cause, opaque_types_jank));
return Ok(self.make_ambiguous_response_no_constraints(maybe_info));
}

let external_constraints =
Expand Down Expand Up @@ -1317,14 +1324,13 @@ where
/// ambiguity but return constrained variables to guide inference.
pub(in crate::solve) fn make_ambiguous_response_no_constraints(
&self,
cause: MaybeCause,
opaque_types_jank: OpaqueTypesJank,
maybe: MaybeInfo,
) -> CanonicalResponse<I> {
response_no_constraints_raw(
self.cx(),
self.max_input_universe,
self.var_kinds,
Certainty::Maybe { cause, opaque_types_jank },
Certainty::Maybe(maybe),
)
}

Expand Down
30 changes: 11 additions & 19 deletions compiler/rustc_next_trait_solver/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ where
if self.may_use_unstable_feature(param_env, symbol) {
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
} else {
self.evaluate_added_goals_and_make_canonical_response(Certainty::Maybe {
cause: MaybeCause::Ambiguity,
opaque_types_jank: OpaqueTypesJank::AllGood,
})
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
}
}

Expand Down Expand Up @@ -279,21 +276,16 @@ where

fn bail_with_ambiguity(&mut self, candidates: &[Candidate<I>]) -> CanonicalResponse<I> {
debug_assert!(candidates.len() > 1);
let (cause, opaque_types_jank) = candidates.iter().fold(
(MaybeCause::Ambiguity, OpaqueTypesJank::AllGood),
|(c, jank), candidates| {
// We pull down the certainty of `Certainty::Yes` to ambiguity when combining
// these responses, b/c we're combining more than one response and this we
// don't know which one applies.
match candidates.result.value.certainty {
Certainty::Yes => (c, jank),
Certainty::Maybe { cause, opaque_types_jank } => {
(c.or(cause), jank.or(opaque_types_jank))
}
}
},
);
self.make_ambiguous_response_no_constraints(cause, opaque_types_jank)
let maybe = candidates.iter().fold(MaybeInfo::AMBIGUOUS, |maybe, candidate| {
// We pull down the certainty of `Certainty::Yes` to ambiguity when combining
// these responses, b/c we're combining more than one response and this we
// don't know which one applies.
match candidate.result.value.certainty {
Certainty::Yes => maybe,
Certainty::Maybe(cand_maybe) => maybe.or(cand_maybe),
}
});
self.make_ambiguous_response_no_constraints(maybe)
}

/// If we fail to merge responses we flounder and return overflow or ambiguity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod opaque_types;
use rustc_type_ir::fast_reject::DeepRejectCtxt;
use rustc_type_ir::inherent::*;
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::solve::SizedTraitKind;
use rustc_type_ir::{
self as ty, FieldInfo, Interner, NormalizesTo, PredicateKind, Unnormalized, Upcast as _,
};
Expand All @@ -17,8 +16,8 @@ use crate::solve::assembly::structural_traits::{self, AsyncCallableRelevantTypes
use crate::solve::assembly::{self, Candidate};
use crate::solve::inspect::ProbeKind;
use crate::solve::{
BuiltinImplSource, CandidateSource, Certainty, EvalCtxt, Goal, GoalSource, MaybeCause,
NoSolution, QueryResult,
BuiltinImplSource, CandidateSource, Certainty, EvalCtxt, Goal, GoalSource, MaybeInfo,
NoSolution, QueryResult, SizedTraitKind,
};

impl<D, I> EvalCtxt<'_, D>
Expand Down Expand Up @@ -460,7 +459,7 @@ where
goal_kind,
)?
else {
return ecx.forced_ambiguity(MaybeCause::Ambiguity);
return ecx.forced_ambiguity(MaybeInfo::AMBIGUOUS);
};
let (inputs, output) = ecx.instantiate_binder_with_infer(tupled_inputs_and_output);

Expand Down Expand Up @@ -588,7 +587,7 @@ where

// Bail if the upvars haven't been constrained.
if tupled_upvars_ty.expect_ty().is_ty_var() {
return ecx.forced_ambiguity(MaybeCause::Ambiguity);
return ecx.forced_ambiguity(MaybeInfo::AMBIGUOUS);
}

let Some(closure_kind) = closure_fn_kind_ty.expect_ty().to_opt_closure_kind() else {
Expand Down
20 changes: 13 additions & 7 deletions compiler/rustc_next_trait_solver/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use rustc_type_ir::fast_reject::DeepRejectCtxt;
use rustc_type_ir::inherent::*;
use rustc_type_ir::lang_items::SolverTraitLangItem;
use rustc_type_ir::solve::{
AliasBoundKind, CandidatePreferenceMode, CanonicalResponse, SizedTraitKind,
AliasBoundKind, CandidatePreferenceMode, CanonicalResponse, MaybeInfo, OpaqueTypesJank,
SizedTraitKind,
};
use rustc_type_ir::{
self as ty, FieldInfo, Interner, Movability, PredicatePolarity, TraitPredicate, TraitRef,
Expand All @@ -21,7 +22,8 @@ use crate::solve::assembly::{
use crate::solve::inspect::ProbeKind;
use crate::solve::{
BuiltinImplSource, CandidateSource, Certainty, EvalCtxt, Goal, GoalSource, MaybeCause,
MergeCandidateInfo, NoSolution, ParamEnvSource, QueryResult, has_only_region_constraints,
MergeCandidateInfo, NoSolution, ParamEnvSource, QueryResult, StalledOnCoroutines,
has_only_region_constraints,
};

impl<D, I> assembly::GoalKind<D> for TraitPredicate<I>
Expand Down Expand Up @@ -372,7 +374,7 @@ where
goal_kind,
)?
else {
return ecx.forced_ambiguity(MaybeCause::Ambiguity);
return ecx.forced_ambiguity(MaybeInfo::AMBIGUOUS);
};
let (inputs, output) = ecx.instantiate_binder_with_infer(tupled_inputs_and_output);

Expand Down Expand Up @@ -671,7 +673,7 @@ where
// Match the old solver by treating unresolved inference variables as
// ambiguous until `rustc_transmute` can compute their layout.
if goal.has_non_region_infer() {
return ecx.forced_ambiguity(MaybeCause::Ambiguity);
return ecx.forced_ambiguity(MaybeInfo::AMBIGUOUS);
}

ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
Expand Down Expand Up @@ -823,7 +825,7 @@ where
(ty::Infer(ty::TyVar(..)), ..) => panic!("unexpected infer {a_ty:?} {b_ty:?}"),

(_, ty::Infer(ty::TyVar(..))) => {
result_to_single(ecx.forced_ambiguity(MaybeCause::Ambiguity))
result_to_single(ecx.forced_ambiguity(MaybeInfo::AMBIGUOUS))
}

// Trait upcasting, or `dyn Trait + Auto + 'a` -> `dyn Trait + 'b`.
Expand Down Expand Up @@ -1248,7 +1250,7 @@ where
// we probably don't want to treat an `impl !AutoTrait for i32` as
// disqualifying the built-in auto impl for `i64: AutoTrait` either.
ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) => {
Some(self.forced_ambiguity(MaybeCause::Ambiguity))
Some(self.forced_ambiguity(MaybeInfo::AMBIGUOUS))
}

// Backward compatibility for default auto traits.
Expand Down Expand Up @@ -1564,7 +1566,11 @@ where
} => {
if def_id.as_local().is_some_and(|def_id| stalled_generators.contains(&def_id))
{
return Some(self.forced_ambiguity(MaybeCause::Ambiguity));
return Some(self.forced_ambiguity(MaybeInfo {
cause: MaybeCause::Ambiguity,
opaque_types_jank: OpaqueTypesJank::AllGood,
stalled_on_coroutines: StalledOnCoroutines::Yes,
}));
}
}
TypingMode::Coherence
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod normalize;
mod select;

pub(crate) use delegate::SolverDelegate;
pub use fulfill::{FulfillmentCtxt, NextSolverError, StalledOnCoroutines};
pub use fulfill::{FulfillmentCtxt, NextSolverError};
pub(crate) use normalize::deeply_normalize_for_diagnostics;
pub use normalize::{
deeply_normalize, deeply_normalize_with_skipped_universes,
Expand Down
Loading
Loading