Skip to content

Commit e09c71e

Browse files
author
Yuki Okushi
authored
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
2 parents 7ba37ad + a1fbc14 commit e09c71e

File tree

4 files changed

+60
-8
lines changed

4 files changed

+60
-8
lines changed

compiler/rustc_trait_selection/src/traits/project.rs

+25-5
Original file line numberDiff line numberDiff line change
@@ -2321,11 +2321,10 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
23212321
nested: &mut Vec<PredicateObligation<'tcx>>,
23222322
) {
23232323
let tcx = selcx.tcx();
2324-
for predicate in tcx
2324+
let own = tcx
23252325
.predicates_of(obligation.predicate.item_def_id)
2326-
.instantiate_own(tcx, obligation.predicate.substs)
2327-
.predicates
2328-
{
2326+
.instantiate_own(tcx, obligation.predicate.substs);
2327+
for (predicate, span) in std::iter::zip(own.predicates, own.spans) {
23292328
let normalized = normalize_with_depth_to(
23302329
selcx,
23312330
obligation.param_env,
@@ -2334,9 +2333,30 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
23342333
predicate,
23352334
nested,
23362335
);
2336+
2337+
let nested_cause = if matches!(
2338+
obligation.cause.code(),
2339+
super::CompareImplItemObligation { .. }
2340+
| super::CheckAssociatedTypeBounds { .. }
2341+
| super::AscribeUserTypeProvePredicate(..)
2342+
) {
2343+
obligation.cause.clone()
2344+
} else if span.is_dummy() {
2345+
ObligationCause::new(
2346+
obligation.cause.span,
2347+
obligation.cause.body_id,
2348+
super::ItemObligation(obligation.predicate.item_def_id),
2349+
)
2350+
} else {
2351+
ObligationCause::new(
2352+
obligation.cause.span,
2353+
obligation.cause.body_id,
2354+
super::BindingObligation(obligation.predicate.item_def_id, span),
2355+
)
2356+
};
23372357
nested.push(Obligation::with_depth(
23382358
tcx,
2339-
obligation.cause.clone(),
2359+
nested_cause,
23402360
obligation.recursion_depth + 1,
23412361
obligation.param_env,
23422362
normalized,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
struct S;
2+
3+
trait D {
4+
type P<T: Copy>;
5+
//~^ NOTE required by this bound in `D::P`
6+
//~| NOTE required by a bound in `D::P`
7+
}
8+
9+
impl D for S {
10+
type P<T: Copy> = ();
11+
}
12+
13+
fn main() {
14+
let _: <S as D>::P<String>;
15+
//~^ ERROR the trait bound `String: Copy` is not satisfied
16+
//~| NOTE the trait `Copy` is not implemented for `String`
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `String: Copy` is not satisfied
2+
--> $DIR/own-bound-span.rs:14:12
3+
|
4+
LL | let _: <S as D>::P<String>;
5+
| ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
6+
|
7+
note: required by a bound in `D::P`
8+
--> $DIR/own-bound-span.rs:4:15
9+
|
10+
LL | type P<T: Copy>;
11+
| ^^^^ required by this bound in `D::P`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/object-safety/object-safety-supertrait-mentions-GAT.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ error[E0311]: the parameter type `Self` may not live long enough
33
= help: consider adding an explicit lifetime bound `Self: 'a`...
44
= note: ...so that the type `Self` will meet its required lifetime bounds...
55
note: ...that is required by this bound
6-
--> $DIR/object-safety-supertrait-mentions-GAT.rs:9:39
6+
--> $DIR/object-safety-supertrait-mentions-GAT.rs:6:15
77
|
8-
LL | trait SuperTrait<T>: for<'a> GatTrait<Gat<'a> = T> {
9-
| ^^^^^^^^^^^
8+
LL | Self: 'a;
9+
| ^^
1010

1111
error: associated item referring to unboxed trait object for its own trait
1212
--> $DIR/object-safety-supertrait-mentions-GAT.rs:10:20

0 commit comments

Comments
 (0)