Do not suggest trivially false const predicates
This commit is contained in:
parent
5ffa67d730
commit
6e21b7a9b7
@ -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);
|
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() {
|
if trait_predicate.is_const_if_const() && obligation.param_env.is_const() {
|
||||||
let non_const_predicate = trait_ref.without_const();
|
let non_const_predicate = trait_ref.without_const();
|
||||||
let non_const_obligation = Obligation {
|
let non_const_obligation = Obligation {
|
||||||
@ -773,6 +774,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
recursion_depth: obligation.recursion_depth,
|
recursion_depth: obligation.recursion_depth,
|
||||||
};
|
};
|
||||||
if self.predicate_may_hold(&non_const_obligation) {
|
if self.predicate_may_hold(&non_const_obligation) {
|
||||||
|
unsatisfied_const = true;
|
||||||
err.span_note(
|
err.span_note(
|
||||||
span,
|
span,
|
||||||
&format!(
|
&format!(
|
||||||
@ -924,7 +926,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if !trait_ref.has_non_region_infer()
|
} 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
|
// If a where-clause may be useful, remind the
|
||||||
// user that they can add it.
|
// user that they can add it.
|
||||||
@ -939,7 +941,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
None,
|
None,
|
||||||
obligation.cause.body_id,
|
obligation.cause.body_id,
|
||||||
);
|
);
|
||||||
} else if !suggested {
|
} else if !suggested && !unsatisfied_const {
|
||||||
// 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_predicate);
|
let impl_candidates = self.find_similar_impl_candidates(trait_predicate);
|
||||||
if !self.report_similar_impl_candidates(
|
if !self.report_similar_impl_candidates(
|
||||||
@ -1433,7 +1435,7 @@ trait InferCtxtPrivExt<'tcx> {
|
|||||||
fn predicate_can_apply(
|
fn predicate_can_apply(
|
||||||
&self,
|
&self,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
pred: ty::PolyTraitRef<'tcx>,
|
pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) -> bool;
|
) -> bool;
|
||||||
|
|
||||||
fn note_obligation_cause(&self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>);
|
fn note_obligation_cause(&self, err: &mut Diagnostic, obligation: &PredicateObligation<'tcx>);
|
||||||
@ -2508,7 +2510,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
fn predicate_can_apply(
|
fn predicate_can_apply(
|
||||||
&self,
|
&self,
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
pred: ty::PolyTraitRef<'tcx>,
|
pred: ty::PolyTraitPredicate<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
struct ParamToVarFolder<'a, 'tcx> {
|
struct ParamToVarFolder<'a, 'tcx> {
|
||||||
infcx: &'a InferCtxt<'tcx>,
|
infcx: &'a InferCtxt<'tcx>,
|
||||||
@ -2552,7 +2554,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
let obligation = Obligation::new(
|
let obligation = Obligation::new(
|
||||||
ObligationCause::dummy(),
|
ObligationCause::dummy(),
|
||||||
param_env,
|
param_env,
|
||||||
cleaned_pred.without_const().to_predicate(selcx.tcx()),
|
cleaned_pred.to_predicate(selcx.tcx()),
|
||||||
);
|
);
|
||||||
|
|
||||||
self.predicate_may_hold(&obligation)
|
self.predicate_may_hold(&obligation)
|
||||||
|
@ -10,16 +10,6 @@ note: the trait `PartialEq<_>` is implemented for `*const i32`, but that impleme
|
|||||||
|
|
|
|
||||||
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 };
|
LL | const X: bool = unsafe { &1 as *const i32 == &2 as *const i32 };
|
||||||
| ^^
|
| ^^
|
||||||
= help: the following other types implement trait `PartialEq<Rhs>`:
|
|
||||||
f32
|
|
||||||
f64
|
|
||||||
i128
|
|
||||||
i16
|
|
||||||
i32
|
|
||||||
i64
|
|
||||||
i8
|
|
||||||
isize
|
|
||||||
and 6 others
|
|
||||||
|
|
||||||
error[E0277]: can't compare `*const i32` with `_` in const contexts
|
error[E0277]: can't compare `*const i32` with `_` in const contexts
|
||||||
--> $DIR/const_raw_ptr_ops.rs:6:44
|
--> $DIR/const_raw_ptr_ops.rs:6:44
|
||||||
@ -33,16 +23,6 @@ note: the trait `PartialEq<_>` is implemented for `*const i32`, but that impleme
|
|||||||
|
|
|
|
||||||
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 };
|
LL | const X2: bool = unsafe { 42 as *const i32 == 43 as *const i32 };
|
||||||
| ^^
|
| ^^
|
||||||
= help: the following other types implement trait `PartialEq<Rhs>`:
|
|
||||||
f32
|
|
||||||
f64
|
|
||||||
i128
|
|
||||||
i16
|
|
||||||
i32
|
|
||||||
i64
|
|
||||||
i8
|
|
||||||
isize
|
|
||||||
and 6 others
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -10,10 +10,6 @@ note: the trait `PartialOrd` is implemented for `*const ()`, but that implementa
|
|||||||
|
|
|
|
||||||
LL | const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
|
LL | const A: bool = unsafe { id::<u8> as *const () < id::<u16> as *const () };
|
||||||
| ^
|
| ^
|
||||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
|
||||||
|
|
|
||||||
LL | fn main() where *const (): ~const PartialOrd {
|
|
||||||
| ++++++++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -23,10 +23,6 @@ note: the trait `IndexMut<usize>` is implemented for `Vec<usize>`, but that impl
|
|||||||
|
|
|
|
||||||
LL | self.bar[0] = baz.len();
|
LL | self.bar[0] = baz.len();
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
|
||||||
|
|
|
||||||
LL | impl<'a> Foo<'a> where Vec<usize>: ~const IndexMut<usize> {
|
|
||||||
| ++++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -15,10 +15,6 @@ note: required by a bound in `Foo::Bar`
|
|||||||
|
|
|
|
||||||
LL | type Bar: ~const std::ops::Add;
|
LL | type Bar: ~const std::ops::Add;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Foo::Bar`
|
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Foo::Bar`
|
||||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
|
||||||
|
|
|
||||||
LL | impl const Foo for NonConstAdd where NonConstAdd: ~const Add {
|
|
||||||
| +++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -9,10 +9,6 @@ note: the trait `Plus` is implemented for `u32`, but that implementation is not
|
|||||||
|
|
|
|
||||||
LL | a.plus(b)
|
LL | a.plus(b)
|
||||||
| ^^^^
|
| ^^^^
|
||||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
|
||||||
|
|
|
||||||
LL | pub const fn add_u32(a: u32, b: u32) -> u32 where u32: ~const Plus {
|
|
||||||
| ++++++++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ note: the trait `PartialEq<_>` is implemented for `T`, but that implementation i
|
|||||||
|
|
|
|
||||||
LL | *t == *t
|
LL | *t == *t
|
||||||
| ^^
|
| ^^
|
||||||
= help: the trait `PartialEq<&B>` is implemented for `&A`
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -11,10 +11,6 @@ note: the trait `ConstDefaultFn` is implemented for `NonConstImpl`, but that imp
|
|||||||
|
|
|
|
||||||
LL | NonConstImpl.a();
|
LL | NonConstImpl.a();
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
|
||||||
|
|
|
||||||
LL | const fn test() where NonConstImpl: ~const ConstDefaultFn {
|
|
||||||
| +++++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -11,10 +11,6 @@ note: the trait `cross_crate::MyTrait` is implemented for `cross_crate::NonConst
|
|||||||
|
|
|
|
||||||
LL | NonConst.func();
|
LL | NonConst.func();
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
|
||||||
|
|
|
||||||
LL | const fn const_context() where cross_crate::NonConst: ~const cross_crate::MyTrait {
|
|
||||||
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -11,10 +11,6 @@ note: the trait `cross_crate::MyTrait` is implemented for `cross_crate::NonConst
|
|||||||
|
|
|
|
||||||
LL | NonConst.func();
|
LL | NonConst.func();
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
|
||||||
|
|
|
||||||
LL | const fn const_context() where cross_crate::NonConst: ~const cross_crate::MyTrait {
|
|
||||||
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -14,10 +14,6 @@ note: required by a bound in `foo`
|
|||||||
|
|
|
|
||||||
LL | const fn foo<T>() where T: ~const Tr {}
|
LL | const fn foo<T>() where T: ~const Tr {}
|
||||||
| ^^^^^^^^^ required by this bound in `foo`
|
| ^^^^^^^^^ required by this bound in `foo`
|
||||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
|
||||||
|
|
|
||||||
LL | pub trait Foo where (): ~const Tr {
|
|
||||||
| +++++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -11,10 +11,6 @@ note: the trait `Tr` is implemented for `()`, but that implementation is not `co
|
|||||||
|
|
|
|
||||||
LL | ().a()
|
LL | ().a()
|
||||||
| ^^
|
| ^^
|
||||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
|
||||||
|
|
|
||||||
LL | pub trait Tr where (): ~const Tr {
|
|
||||||
| +++++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -14,10 +14,6 @@ note: required by a bound in `Bar`
|
|||||||
|
|
|
|
||||||
LL | trait Bar: ~const Foo {}
|
LL | trait Bar: ~const Foo {}
|
||||||
| ^^^^^^^^^^ required by this bound in `Bar`
|
| ^^^^^^^^^^ required by this bound in `Bar`
|
||||||
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
|
||||||
|
|
|
||||||
LL | impl const Bar for S where S: ~const Foo {}
|
|
||||||
| +++++++++++++++++++
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user