Skip to content

Commit

Permalink
Match on both reveal and solver mode at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed May 25, 2023
1 parent 980da66 commit dd98198
Showing 1 changed file with 38 additions and 41 deletions.
79 changes: 38 additions & 41 deletions compiler/rustc_trait_selection/src/solve/opaques.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,48 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
let opaque_ty = goal.predicate.projection_ty;
let expected = goal.predicate.term.ty().expect("no such thing as an opaque const");

match goal.param_env.reveal() {
Reveal::UserFacing => match self.solver_mode() {
SolverMode::Normal => {
let Some(opaque_ty_def_id) = opaque_ty.def_id.as_local() else {
return Err(NoSolution);
};
let opaque_ty =
ty::OpaqueTypeKey { def_id: opaque_ty_def_id, substs: opaque_ty.substs };
// FIXME: at some point we should call queries without defining
// new opaque types but having the existing opaque type definitions.
// This will require moving this below "Prefer opaques registered already".
if !self.can_define_opaque_ty(opaque_ty_def_id) {
return Err(NoSolution);
}
// FIXME: This may have issues when the substs contain aliases...
match self.tcx().uses_unique_placeholders_ignoring_regions(opaque_ty.substs) {
Err(NotUniqueParam::NotParam(param)) if param.is_non_region_infer() => {
return self.evaluate_added_goals_and_make_canonical_response(
Certainty::AMBIGUOUS,
);
}
Err(_) => {
return Err(NoSolution);
}
Ok(()) => {}
match (goal.param_env.reveal(), self.solver_mode()) {
(Reveal::UserFacing, SolverMode::Normal) => {
let Some(opaque_ty_def_id) = opaque_ty.def_id.as_local() else {
return Err(NoSolution);
};
let opaque_ty =
ty::OpaqueTypeKey { def_id: opaque_ty_def_id, substs: opaque_ty.substs };
// FIXME: at some point we should call queries without defining
// new opaque types but having the existing opaque type definitions.
// This will require moving this below "Prefer opaques registered already".
if !self.can_define_opaque_ty(opaque_ty_def_id) {
return Err(NoSolution);
}
// FIXME: This may have issues when the substs contain aliases...
match self.tcx().uses_unique_placeholders_ignoring_regions(opaque_ty.substs) {
Err(NotUniqueParam::NotParam(param)) if param.is_non_region_infer() => {
return self.evaluate_added_goals_and_make_canonical_response(
Certainty::AMBIGUOUS,
);
}
// Prefer opaques registered already.
let matches =
self.unify_existing_opaque_tys(goal.param_env, opaque_ty, expected);
if !matches.is_empty() {
if let Some(response) = self.try_merge_responses(&matches) {
return Ok(response);
} else {
return self.flounder(&matches);
}
Err(_) => {
return Err(NoSolution);
}
// Otherwise, define a new opaque type
self.register_opaque_ty(opaque_ty, expected, goal.param_env)?;
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
Ok(()) => {}
}
SolverMode::Coherence => {
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
// Prefer opaques registered already.
let matches = self.unify_existing_opaque_tys(goal.param_env, opaque_ty, expected);
if !matches.is_empty() {
if let Some(response) = self.try_merge_responses(&matches) {
return Ok(response);
} else {
return self.flounder(&matches);
}
}
},
Reveal::All => {
// Otherwise, define a new opaque type
self.register_opaque_ty(opaque_ty, expected, goal.param_env)?;
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
}
(Reveal::UserFacing, SolverMode::Coherence) => {
self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
}
(Reveal::All, _) => {
// FIXME: Add an assertion that opaque type storage is empty.
let actual = tcx.type_of(opaque_ty.def_id).subst(tcx, opaque_ty.substs);
self.eq(goal.param_env, expected, actual)?;
Expand Down

0 comments on commit dd98198

Please sign in to comment.