Fix diagnostics for unfulfilled obligations
This commit is contained in:
parent
d60ebe366b
commit
71e162e6ca
@ -829,6 +829,14 @@ impl<'tcx> TraitPredicate<'tcx> {
|
|||||||
pub fn is_const_if_const(self) -> bool {
|
pub fn is_const_if_const(self) -> bool {
|
||||||
self.constness == BoundConstness::ConstIfConst
|
self.constness == BoundConstness::ConstIfConst
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_constness_satisfied_by(self, constness: hir::Constness) -> bool {
|
||||||
|
match (self.constness, constness) {
|
||||||
|
(BoundConstness::NotConst, _)
|
||||||
|
| (BoundConstness::ConstIfConst, hir::Constness::Const) => true,
|
||||||
|
(BoundConstness::ConstIfConst, hir::Constness::NotConst) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> PolyTraitPredicate<'tcx> {
|
impl<'tcx> PolyTraitPredicate<'tcx> {
|
||||||
|
@ -666,7 +666,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
);
|
);
|
||||||
} else if !suggested {
|
} else if !suggested {
|
||||||
// Can't show anything else useful, try to find similar impls.
|
// Can't show anything else useful, try to find similar impls.
|
||||||
let impl_candidates = self.find_similar_impl_candidates(trait_ref);
|
let impl_candidates = self.find_similar_impl_candidates(trait_predicate);
|
||||||
if !self.report_similar_impl_candidates(
|
if !self.report_similar_impl_candidates(
|
||||||
impl_candidates,
|
impl_candidates,
|
||||||
trait_ref,
|
trait_ref,
|
||||||
@ -701,7 +701,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
{
|
{
|
||||||
let trait_ref = trait_pred.to_poly_trait_ref();
|
let trait_ref = trait_pred.to_poly_trait_ref();
|
||||||
let impl_candidates =
|
let impl_candidates =
|
||||||
self.find_similar_impl_candidates(trait_ref);
|
self.find_similar_impl_candidates(trait_pred);
|
||||||
self.report_similar_impl_candidates(
|
self.report_similar_impl_candidates(
|
||||||
impl_candidates,
|
impl_candidates,
|
||||||
trait_ref,
|
trait_ref,
|
||||||
@ -1325,7 +1325,7 @@ trait InferCtxtPrivExt<'hir, 'tcx> {
|
|||||||
|
|
||||||
fn find_similar_impl_candidates(
|
fn find_similar_impl_candidates(
|
||||||
&self,
|
&self,
|
||||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) -> Vec<ImplCandidate<'tcx>>;
|
) -> Vec<ImplCandidate<'tcx>>;
|
||||||
|
|
||||||
fn report_similar_impl_candidates(
|
fn report_similar_impl_candidates(
|
||||||
@ -1694,18 +1694,22 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
fn find_similar_impl_candidates(
|
fn find_similar_impl_candidates(
|
||||||
&self,
|
&self,
|
||||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) -> Vec<ImplCandidate<'tcx>> {
|
) -> Vec<ImplCandidate<'tcx>> {
|
||||||
self.tcx
|
self.tcx
|
||||||
.all_impls(trait_ref.def_id())
|
.all_impls(trait_pred.def_id())
|
||||||
.filter_map(|def_id| {
|
.filter_map(|def_id| {
|
||||||
if self.tcx.impl_polarity(def_id) == ty::ImplPolarity::Negative {
|
if self.tcx.impl_polarity(def_id) == ty::ImplPolarity::Negative
|
||||||
|
|| !trait_pred
|
||||||
|
.skip_binder()
|
||||||
|
.is_constness_satisfied_by(self.tcx.constness(def_id))
|
||||||
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let imp = self.tcx.impl_trait_ref(def_id).unwrap();
|
let imp = self.tcx.impl_trait_ref(def_id).unwrap();
|
||||||
|
|
||||||
self.fuzzy_match_tys(trait_ref.skip_binder().self_ty(), imp.self_ty(), false)
|
self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false)
|
||||||
.map(|similarity| ImplCandidate { trait_ref: imp, similarity })
|
.map(|similarity| ImplCandidate { trait_ref: imp, similarity })
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -10,7 +10,6 @@ note: the trait `PartialEq<_>` is implemented for `TypeId`, but that implementat
|
|||||||
|
|
|
|
||||||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
||||||
| ^^
|
| ^^
|
||||||
= help: the trait `PartialEq` is implemented for `TypeId`
|
|
||||||
|
|
||||||
error[E0277]: can't compare `TypeId` with `_` in const contexts
|
error[E0277]: can't compare `TypeId` with `_` in const contexts
|
||||||
--> $DIR/issue-90318.rs:21:28
|
--> $DIR/issue-90318.rs:21:28
|
||||||
@ -24,7 +23,6 @@ note: the trait `PartialEq<_>` is implemented for `TypeId`, but that implementat
|
|||||||
|
|
|
|
||||||
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
|
||||||
| ^^
|
| ^^
|
||||||
= help: the trait `PartialEq` is implemented for `TypeId`
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -10,16 +10,6 @@ note: the trait `PartialEq<_>` is implemented for `fn()`, but that implementatio
|
|||||||
|
|
|
|
||||||
LL | unsafe { x == y }
|
LL | unsafe { x == y }
|
||||||
| ^^
|
| ^^
|
||||||
= help: the following other types implement trait `PartialEq<Rhs>`:
|
|
||||||
extern "C" fn() -> Ret
|
|
||||||
extern "C" fn(A, B) -> Ret
|
|
||||||
extern "C" fn(A, B, ...) -> Ret
|
|
||||||
extern "C" fn(A, B, C) -> Ret
|
|
||||||
extern "C" fn(A, B, C, ...) -> Ret
|
|
||||||
extern "C" fn(A, B, C, D) -> Ret
|
|
||||||
extern "C" fn(A, B, C, D, ...) -> Ret
|
|
||||||
extern "C" fn(A, B, C, D, E) -> Ret
|
|
||||||
and 68 others
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -9,13 +9,7 @@ note: the trait `PartialEq<_>` is implemented for `T`, but that implementation i
|
|||||||
|
|
|
|
||||||
LL | *t == *t
|
LL | *t == *t
|
||||||
| ^^
|
| ^^
|
||||||
= help: the following other types implement trait `PartialEq<Rhs>`:
|
= help: the trait `PartialEq<&B>` is implemented for `&A`
|
||||||
<&A as PartialEq<&B>>
|
|
||||||
<&A as PartialEq<&mut B>>
|
|
||||||
<&mut A as PartialEq<&B>>
|
|
||||||
<&mut A as PartialEq<&mut B>>
|
|
||||||
<*const T as PartialEq>
|
|
||||||
<*mut T as PartialEq>
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user