Rollup merge of #103328 - compiler-errors:trivial-false-const-sugg, r=jackh726
Do not suggest trivially false const predicates Pass through constness to `predicate_can_apply` and don't suggest other impls if it's satisfied but not const. Fixes #103267
This commit is contained in:
commit
1a077420f8
13 changed files with 7 additions and 66 deletions
|
@ -764,6 +764,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
self.suggest_borrowing_for_object_cast(&mut err, &root_obligation, *concrete_ty, *obj_ty);
|
||||
}
|
||||
|
||||
let mut unsatisfied_const = false;
|
||||
if trait_predicate.is_const_if_const() && obligation.param_env.is_const() {
|
||||
let non_const_predicate = trait_ref.without_const();
|
||||
let non_const_obligation = Obligation {
|
||||
|
@ -773,6 +774,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
recursion_depth: obligation.recursion_depth,
|
||||
};
|
||||
if self.predicate_may_hold(&non_const_obligation) {
|
||||
unsatisfied_const = true;
|
||||
err.span_note(
|
||||
span,
|
||||
&format!(
|
||||
|
@ -924,7 +926,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
} else if !trait_ref.has_non_region_infer()
|
||||
&& self.predicate_can_apply(obligation.param_env, trait_ref)
|
||||
&& self.predicate_can_apply(obligation.param_env, trait_predicate)
|
||||
{
|
||||
// If a where-clause may be useful, remind the
|
||||
// user that they can add it.
|
||||
|
@ -939,7 +941,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
None,
|
||||
obligation.cause.body_id,
|
||||
);
|
||||
} else if !suggested {
|
||||
} else if !suggested && !unsatisfied_const {
|
||||
// Can't show anything else useful, try to find similar impls.
|
||||
let impl_candidates = self.find_similar_impl_candidates(trait_predicate);
|
||||
if !self.report_similar_impl_candidates(
|
||||
|
@ -1436,7 +1438,7 @@ trait InferCtxtPrivExt<'tcx> {
|
|||
fn predicate_can_apply(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
pred: ty::PolyTraitRef<'tcx>,
|
||||
pred: ty::PolyTraitPredicate<'tcx>,
|
||||
) -> bool;
|
||||
|
||||
fn note_obligation_cause(&self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>);
|
||||
|
@ -2511,7 +2513,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
fn predicate_can_apply(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
pred: ty::PolyTraitRef<'tcx>,
|
||||
pred: ty::PolyTraitPredicate<'tcx>,
|
||||
) -> bool {
|
||||
struct ParamToVarFolder<'a, 'tcx> {
|
||||
infcx: &'a InferCtxt<'tcx>,
|
||||
|
@ -2555,7 +2557,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let obligation = Obligation::new(
|
||||
ObligationCause::dummy(),
|
||||
param_env,
|
||||
cleaned_pred.without_const().to_predicate(selcx.tcx()),
|
||||
cleaned_pred.to_predicate(selcx.tcx()),
|
||||
);
|
||||
|
||||
self.predicate_may_hold(&obligation)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue