Implement do_not_recommend in the new solver

This commit is contained in:
Michael Goulet 2024-05-04 12:37:14 -04:00
parent d7ea27808d
commit b33599485b
5 changed files with 68 additions and 1 deletions

View file

@ -11,6 +11,7 @@ use rustc_infer::traits::{
};
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::{self, TyCtxt};
use rustc_span::symbol::sym;
use super::eval_ctxt::GenerateProofTree;
use super::inspect::{ProofTreeInferCtxtExt, ProofTreeVisitor};
@ -320,6 +321,14 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
return ControlFlow::Break(self.obligation.clone());
};
// Don't walk into impls that have `do_not_recommend`.
if let ProbeKind::TraitCandidate { source: CandidateSource::Impl(impl_def_id), result: _ } =
candidate.kind()
&& goal.infcx().tcx.has_attr(impl_def_id, sym::do_not_recommend)
{
return ControlFlow::Break(self.obligation.clone());
}
// FIXME: Could we extract a trait ref from a projection here too?
// FIXME: Also, what about considering >1 layer up the stack? May be necessary
// for normalizes-to.