Note binding obligation causes for const equate errors

This commit is contained in:
Michael Goulet 2022-08-12 03:13:45 +00:00
parent 4e976262a1
commit 4ff587263e
6 changed files with 101 additions and 3 deletions

View File

@ -469,6 +469,13 @@ impl<'tcx> ObligationCauseCode<'tcx> {
_ => None,
}
}
pub fn peel_match_impls(&self) -> &Self {
match self {
MatchImpl(cause, _) => cause.code(),
_ => self,
}
}
}
// `ObligationCauseCode` is used a lot. Make sure it doesn't unintentionally get bigger.

View File

@ -1506,13 +1506,26 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
.emit();
}
FulfillmentErrorCode::CodeConstEquateError(ref expected_found, ref err) => {
self.report_mismatched_consts(
let mut diag = self.report_mismatched_consts(
&error.obligation.cause,
expected_found.expected,
expected_found.found,
err.clone(),
)
.emit();
);
let code = error.obligation.cause.code().peel_derives().peel_match_impls();
if let ObligationCauseCode::BindingObligation(..)
| ObligationCauseCode::ItemObligation(..) = code
{
self.note_obligation_cause_code(
&mut diag,
&error.obligation.predicate,
error.obligation.param_env,
code,
&mut vec![],
&mut Default::default(),
);
}
diag.emit();
}
}
}

View File

@ -24,6 +24,11 @@ LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as u128 }>>();
|
= note: expected constant `{ N as u128 }`
found constant `{ O as u128 }`
note: required by a bound in `use_trait_impl::assert_impl`
--> $DIR/abstract-const-as-cast-3.rs:14:23
|
LL | fn assert_impl<T: Trait>() {}
| ^^^^^ required by this bound in `use_trait_impl::assert_impl`
error: unconstrained generic constant
--> $DIR/abstract-const-as-cast-3.rs:20:19
@ -51,6 +56,11 @@ LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as _ }>>();
|
= note: expected constant `{ N as _ }`
found constant `{ O as u128 }`
note: required by a bound in `use_trait_impl::assert_impl`
--> $DIR/abstract-const-as-cast-3.rs:14:23
|
LL | fn assert_impl<T: Trait>() {}
| ^^^^^ required by this bound in `use_trait_impl::assert_impl`
error[E0308]: mismatched types
--> $DIR/abstract-const-as-cast-3.rs:23:5
@ -60,6 +70,11 @@ LL | assert_impl::<HasCastInTraitImpl<13, { 12 as u128 }>>();
|
= note: expected constant `12`
found constant `13`
note: required by a bound in `use_trait_impl::assert_impl`
--> $DIR/abstract-const-as-cast-3.rs:14:23
|
LL | fn assert_impl<T: Trait>() {}
| ^^^^^ required by this bound in `use_trait_impl::assert_impl`
error[E0308]: mismatched types
--> $DIR/abstract-const-as-cast-3.rs:25:5
@ -69,6 +84,11 @@ LL | assert_impl::<HasCastInTraitImpl<14, 13>>();
|
= note: expected constant `13`
found constant `14`
note: required by a bound in `use_trait_impl::assert_impl`
--> $DIR/abstract-const-as-cast-3.rs:14:23
|
LL | fn assert_impl<T: Trait>() {}
| ^^^^^ required by this bound in `use_trait_impl::assert_impl`
error: unconstrained generic constant
--> $DIR/abstract-const-as-cast-3.rs:35:19
@ -96,6 +116,11 @@ LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as u128 }>>();
|
= note: expected constant `{ N as u128 }`
found constant `{ O as u128 }`
note: required by a bound in `use_trait_impl_2::assert_impl`
--> $DIR/abstract-const-as-cast-3.rs:32:23
|
LL | fn assert_impl<T: Trait>() {}
| ^^^^^ required by this bound in `use_trait_impl_2::assert_impl`
error: unconstrained generic constant
--> $DIR/abstract-const-as-cast-3.rs:38:19
@ -123,6 +148,11 @@ LL | assert_impl::<HasCastInTraitImpl<{ N + 1 }, { N as _ }>>();
|
= note: expected constant `{ N as _ }`
found constant `{ O as u128 }`
note: required by a bound in `use_trait_impl_2::assert_impl`
--> $DIR/abstract-const-as-cast-3.rs:32:23
|
LL | fn assert_impl<T: Trait>() {}
| ^^^^^ required by this bound in `use_trait_impl_2::assert_impl`
error[E0308]: mismatched types
--> $DIR/abstract-const-as-cast-3.rs:41:5
@ -132,6 +162,11 @@ LL | assert_impl::<HasCastInTraitImpl<13, { 12 as u128 }>>();
|
= note: expected constant `12`
found constant `13`
note: required by a bound in `use_trait_impl_2::assert_impl`
--> $DIR/abstract-const-as-cast-3.rs:32:23
|
LL | fn assert_impl<T: Trait>() {}
| ^^^^^ required by this bound in `use_trait_impl_2::assert_impl`
error[E0308]: mismatched types
--> $DIR/abstract-const-as-cast-3.rs:43:5
@ -141,6 +176,11 @@ LL | assert_impl::<HasCastInTraitImpl<14, 13>>();
|
= note: expected constant `13`
found constant `14`
note: required by a bound in `use_trait_impl_2::assert_impl`
--> $DIR/abstract-const-as-cast-3.rs:32:23
|
LL | fn assert_impl<T: Trait>() {}
| ^^^^^ required by this bound in `use_trait_impl_2::assert_impl`
error: aborting due to 12 previous errors

View File

@ -6,6 +6,13 @@ LL | let x: Arr<{usize::MAX}> = Arr {};
|
= note: expected constant `false`
found constant `true`
note: required by a bound in `Arr`
--> $DIR/issue-72819-generic-in-const-eval.rs:8:39
|
LL | struct Arr<const N: usize>
| --- required by a bound in this
LL | where Assert::<{N < usize::MAX / 2}>: IsTrue,
| ^^^^^^ required by this bound in `Arr`
error[E0308]: mismatched types
--> $DIR/issue-72819-generic-in-const-eval.rs:20:32
@ -15,6 +22,13 @@ LL | let x: Arr<{usize::MAX}> = Arr {};
|
= note: expected constant `false`
found constant `true`
note: required by a bound in `Arr`
--> $DIR/issue-72819-generic-in-const-eval.rs:8:39
|
LL | struct Arr<const N: usize>
| --- required by a bound in this
LL | where Assert::<{N < usize::MAX / 2}>: IsTrue,
| ^^^^^^ required by this bound in `Arr`
error: aborting due to 2 previous errors

View File

@ -6,6 +6,14 @@ LL | let x: Arr<{usize::MAX}> = Arr {};
|
= note: expected constant `false`
found constant `true`
note: required by a bound in `Arr`
--> $DIR/issue-73260.rs:6:37
|
LL | struct Arr<const N: usize>
| --- required by a bound in this
LL | where
LL | Assert::<{N < usize::MAX / 2}>: IsTrue,
| ^^^^^^ required by this bound in `Arr`
error[E0308]: mismatched types
--> $DIR/issue-73260.rs:16:32
@ -15,6 +23,14 @@ LL | let x: Arr<{usize::MAX}> = Arr {};
|
= note: expected constant `false`
found constant `true`
note: required by a bound in `Arr`
--> $DIR/issue-73260.rs:6:37
|
LL | struct Arr<const N: usize>
| --- required by a bound in this
LL | where
LL | Assert::<{N < usize::MAX / 2}>: IsTrue,
| ^^^^^^ required by this bound in `Arr`
error: aborting due to 2 previous errors

View File

@ -6,6 +6,14 @@ LL | requires_distinct("str", 12);
|
= note: expected constant `true`
found constant `false`
note: required by a bound in `requires_distinct`
--> $DIR/issue-79674.rs:23:37
|
LL | fn requires_distinct<A, B>(_a: A, _b: B) where
| ----------------- required by a bound in this
LL | A: MiniTypeId, B: MiniTypeId,
LL | Lift<{is_same_type::<A, B>()}>: IsFalse {}
| ^^^^^^^ required by this bound in `requires_distinct`
error: aborting due to previous error