Rollup merge of #105324 - compiler-errors:gat-where-clause-binding-obl, r=jackh726

Point at GAT `where` clause when an obligation is unsatisfied

Slightly helps with #105306
This commit is contained in:
Yuki Okushi 2022-12-06 12:48:54 +09:00 committed by GitHub
commit e09c71e4c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 8 deletions

View File

@ -2321,11 +2321,10 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
nested: &mut Vec<PredicateObligation<'tcx>>,
) {
let tcx = selcx.tcx();
for predicate in tcx
let own = tcx
.predicates_of(obligation.predicate.item_def_id)
.instantiate_own(tcx, obligation.predicate.substs)
.predicates
{
.instantiate_own(tcx, obligation.predicate.substs);
for (predicate, span) in std::iter::zip(own.predicates, own.spans) {
let normalized = normalize_with_depth_to(
selcx,
obligation.param_env,
@ -2334,9 +2333,30 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
predicate,
nested,
);
let nested_cause = if matches!(
obligation.cause.code(),
super::CompareImplItemObligation { .. }
| super::CheckAssociatedTypeBounds { .. }
| super::AscribeUserTypeProvePredicate(..)
) {
obligation.cause.clone()
} else if span.is_dummy() {
ObligationCause::new(
obligation.cause.span,
obligation.cause.body_id,
super::ItemObligation(obligation.predicate.item_def_id),
)
} else {
ObligationCause::new(
obligation.cause.span,
obligation.cause.body_id,
super::BindingObligation(obligation.predicate.item_def_id, span),
)
};
nested.push(Obligation::with_depth(
tcx,
obligation.cause.clone(),
nested_cause,
obligation.recursion_depth + 1,
obligation.param_env,
normalized,

View File

@ -0,0 +1,17 @@
struct S;
trait D {
type P<T: Copy>;
//~^ NOTE required by this bound in `D::P`
//~| NOTE required by a bound in `D::P`
}
impl D for S {
type P<T: Copy> = ();
}
fn main() {
let _: <S as D>::P<String>;
//~^ ERROR the trait bound `String: Copy` is not satisfied
//~| NOTE the trait `Copy` is not implemented for `String`
}

View File

@ -0,0 +1,15 @@
error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/own-bound-span.rs:14:12
|
LL | let _: <S as D>::P<String>;
| ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
note: required by a bound in `D::P`
--> $DIR/own-bound-span.rs:4:15
|
LL | type P<T: Copy>;
| ^^^^ required by this bound in `D::P`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -3,10 +3,10 @@ error[E0311]: the parameter type `Self` may not live long enough
= help: consider adding an explicit lifetime bound `Self: 'a`...
= note: ...so that the type `Self` will meet its required lifetime bounds...
note: ...that is required by this bound
--> $DIR/object-safety-supertrait-mentions-GAT.rs:9:39
--> $DIR/object-safety-supertrait-mentions-GAT.rs:6:15
|
LL | trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
| ^^^^^^^^^^^
LL | Self: 'a;
| ^^
error: associated item referring to unboxed trait object for its own trait
--> $DIR/object-safety-supertrait-mentions-GAT.rs:10:20