Skip to content

Commit

Permalink
Point at GAT where clause when unsatisfied
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Dec 5, 2022
1 parent d144956 commit a1fbc14
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
30 changes: 25 additions & 5 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/generic-associated-types/own-bound-span.rs
Original file line number Diff line number Diff line change
@@ -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`
}
15 changes: 15 additions & 0 deletions src/test/ui/generic-associated-types/own-bound-span.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1fbc14

Please sign in to comment.