Skip to content

Commit 8a03a02

Browse files
Use leaf obligation to create selection error code
1 parent c53125f commit 8a03a02

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

compiler/rustc_trait_selection/src/solve/fulfill.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,10 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
196196

197197
fn fulfillment_error_for_no_solution<'tcx>(
198198
infcx: &InferCtxt<'tcx>,
199-
obligation: PredicateObligation<'tcx>,
199+
root_obligation: PredicateObligation<'tcx>,
200200
) -> FulfillmentError<'tcx> {
201+
let obligation = find_best_leaf_obligation(infcx, &root_obligation);
202+
201203
let code = match obligation.predicate.kind().skip_binder() {
202204
ty::PredicateKind::Clause(ty::ClauseKind::Projection(_)) => {
203205
FulfillmentErrorCode::ProjectionError(
@@ -217,14 +219,14 @@ fn fulfillment_error_for_no_solution<'tcx>(
217219
}
218220
ty::PredicateKind::Subtype(pred) => {
219221
let (a, b) = infcx.enter_forall_and_leak_universe(
220-
obligation.predicate.kind().rebind((pred.a, pred.b)),
222+
root_obligation.predicate.kind().rebind((pred.a, pred.b)),
221223
);
222224
let expected_found = ExpectedFound::new(true, a, b);
223225
FulfillmentErrorCode::SubtypeError(expected_found, TypeError::Sorts(expected_found))
224226
}
225227
ty::PredicateKind::Coerce(pred) => {
226228
let (a, b) = infcx.enter_forall_and_leak_universe(
227-
obligation.predicate.kind().rebind((pred.a, pred.b)),
229+
root_obligation.predicate.kind().rebind((pred.a, pred.b)),
228230
);
229231
let expected_found = ExpectedFound::new(false, a, b);
230232
FulfillmentErrorCode::SubtypeError(expected_found, TypeError::Sorts(expected_found))
@@ -239,11 +241,7 @@ fn fulfillment_error_for_no_solution<'tcx>(
239241
}
240242
};
241243

242-
FulfillmentError {
243-
obligation: find_best_leaf_obligation(infcx, &obligation),
244-
code,
245-
root_obligation: obligation,
246-
}
244+
FulfillmentError { obligation, code, root_obligation }
247245
}
248246

249247
fn fulfillment_error_for_stalled<'tcx>(

tests/ui/traits/next-solver/env-shadows-impls/param-candidate-shadows-project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn foo<T: Foo>() {
2525
//
2626
// https://github.com/rust-lang/trait-system-refactor-initiative/issues/76
2727
require_bar::<T>();
28-
//~^ ERROR the trait bound `T: Bar` is not satisfied
28+
//~^ ERROR type mismatch resolving `<T as Foo>::Assoc == i32`
2929
}
3030

3131
fn main() {}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
error[E0277]: the trait bound `T: Bar` is not satisfied
1+
error[E0271]: type mismatch resolving `<T as Foo>::Assoc == i32`
22
--> $DIR/param-candidate-shadows-project.rs:27:19
33
|
44
LL | require_bar::<T>();
5-
| ^ the trait `Bar` is not implemented for `T`
5+
| ^ type mismatch resolving `<T as Foo>::Assoc == i32`
66
|
7+
note: types differ
8+
--> $DIR/param-candidate-shadows-project.rs:10:18
9+
|
10+
LL | type Assoc = i32;
11+
| ^^^
12+
note: required for `T` to implement `Bar`
13+
--> $DIR/param-candidate-shadows-project.rs:13:9
14+
|
15+
LL | impl<T> Bar for T where T: Foo<Assoc = i32> {}
16+
| ^^^ ^ ----------- unsatisfied trait bound introduced here
717
note: required by a bound in `require_bar`
818
--> $DIR/param-candidate-shadows-project.rs:15:19
919
|
1020
LL | fn require_bar<T: Bar>() {}
1121
| ^^^ required by this bound in `require_bar`
12-
help: consider further restricting this bound
13-
|
14-
LL | fn foo<T: Foo + Bar>() {
15-
| +++++
1622

1723
error: aborting due to 1 previous error
1824

19-
For more information about this error, try `rustc --explain E0277`.
25+
For more information about this error, try `rustc --explain E0271`.

tests/ui/traits/next-solver/more-object-bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trait Trait: SuperTrait<A = <Self as SuperTrait>::B> {}
1010

1111
fn transmute<A, B>(x: A) -> B {
1212
foo::<A, B, dyn Trait<A = A, B = B>>(x)
13-
//~^ ERROR the trait bound `dyn Trait<A = A, B = B>: Trait` is not satisfied
13+
//~^ ERROR type mismatch resolving `<dyn Trait<A = A, B = B> as SuperTrait>::A == B`
1414
}
1515

1616
fn foo<A, B, T: ?Sized>(x: T::A) -> B
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: the trait bound `dyn Trait<A = A, B = B>: Trait` is not satisfied
1+
error[E0271]: type mismatch resolving `<dyn Trait<A = A, B = B> as SuperTrait>::A == B`
22
--> $DIR/more-object-bound.rs:12:5
33
|
44
LL | foo::<A, B, dyn Trait<A = A, B = B>>(x)
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `dyn Trait<A = A, B = B>`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ
66
|
77
note: required by a bound in `foo`
88
--> $DIR/more-object-bound.rs:18:8
@@ -12,11 +12,7 @@ LL | fn foo<A, B, T: ?Sized>(x: T::A) -> B
1212
LL | where
1313
LL | T: Trait<B = B>,
1414
| ^^^^^^^^^^^^ required by this bound in `foo`
15-
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
16-
|
17-
LL | fn transmute<A, B>(x: A) -> B where dyn Trait<A = A, B = B>: Trait {
18-
| ++++++++++++++++++++++++++++++++++++
1915

2016
error: aborting due to 1 previous error
2117

22-
For more information about this error, try `rustc --explain E0277`.
18+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)