Skip to content

Commit 82d1882

Browse files
don't resolve type variables twice
1 parent 7a0f2e0 commit 82d1882

File tree

4 files changed

+42
-54
lines changed

4 files changed

+42
-54
lines changed

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -347,31 +347,31 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
347347
let obligation = &mut pending_obligation.obligation;
348348

349349
debug!(?obligation, "process_obligation pre-resolve");
350+
let infcx = self.selcx.infcx();
350351

351352
if obligation.predicate.has_infer_types_or_consts() {
353+
if obligation.predicate.has_late_bound_vars_in_projection() {
354+
let mut obligations = Vec::new();
355+
let predicate = crate::traits::project::try_normalize_with_depth_to(
356+
self.selcx,
357+
obligation.param_env,
358+
obligation.cause.clone(),
359+
obligation.recursion_depth + 1,
360+
obligation.predicate,
361+
&mut obligations,
362+
);
363+
if predicate != obligation.predicate {
364+
obligations.push(obligation.with(predicate));
365+
return ProcessResult::Changed(mk_pending(obligations));
366+
}
367+
}
368+
352369
obligation.predicate =
353370
self.selcx.infcx().resolve_vars_if_possible(obligation.predicate);
354371
}
355372

356373
debug!(?obligation, ?obligation.cause, "process_obligation");
357374

358-
let infcx = self.selcx.infcx();
359-
360-
if obligation.predicate.has_late_bound_vars_in_projection() {
361-
let mut obligations = Vec::new();
362-
let predicate = crate::traits::project::try_normalize_with_depth_to(
363-
self.selcx,
364-
obligation.param_env,
365-
obligation.cause.clone(),
366-
obligation.recursion_depth + 1,
367-
obligation.predicate,
368-
&mut obligations,
369-
);
370-
if predicate != obligation.predicate {
371-
obligations.push(obligation.with(predicate));
372-
return ProcessResult::Changed(mk_pending(obligations));
373-
}
374-
}
375375
let binder = obligation.predicate.kind();
376376
match binder.no_bound_vars() {
377377
None => match binder.skip_binder() {

src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ trait SomeTrait<'a> {
77
fn give_me_ice<T>() {
88
callee::<fn(&()) -> <T as SomeTrait<'_>>::Associated>();
99
//~^ ERROR the trait bound `T: SomeTrait<'_>` is not satisfied [E0277]
10-
//~| ERROR the trait bound `T: SomeTrait<'_>` is not satisfied [E0277]
1110
}
1211

1312
fn callee<T: Fn<(&'static (),)>>() {

src/test/ui/higher-rank-trait-bounds/normalize-under-binder/issue-85455.stderr

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@ help: consider restricting type parameter `T`
99
LL | fn give_me_ice<T: SomeTrait<'_>>() {
1010
| +++++++++++++++
1111

12-
error[E0277]: the trait bound `T: SomeTrait<'_>` is not satisfied
13-
--> $DIR/issue-85455.rs:8:14
14-
|
15-
LL | callee::<fn(&()) -> <T as SomeTrait<'_>>::Associated>();
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `SomeTrait<'_>` is not implemented for `T`
17-
|
18-
help: consider restricting type parameter `T`
19-
|
20-
LL | fn give_me_ice<T: SomeTrait<'_>>() {
21-
| +++++++++++++++
22-
23-
error: aborting due to 2 previous errors
12+
error: aborting due to previous error
2413

2514
For more information about this error, try `rustc --explain E0277`.
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
error[E0271]: type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
2-
--> $DIR/issue-62203-hrtb-ice.rs:38:19
3-
|
4-
LL | let v = Unit2.m(
5-
| ^ type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
6-
|
7-
note: expected this to be `<_ as Ty<'_>>::V`
8-
--> $DIR/issue-62203-hrtb-ice.rs:21:14
9-
|
10-
LL | type O = T::Output;
11-
| ^^^^^^^^^
12-
= note: expected associated type `<_ as Ty<'_>>::V`
13-
found struct `Unit4`
14-
= help: consider constraining the associated type `<_ as Ty<'_>>::V` to `Unit4` or calling a method that returns `<_ as Ty<'_>>::V`
15-
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
16-
note: required by a bound in `T1::m`
17-
--> $DIR/issue-62203-hrtb-ice.rs:27:51
18-
|
19-
LL | fn m<'a, B: Ty<'a>, F>(&self, f: F) -> Unit1
20-
| - required by a bound in this
21-
LL | where
22-
LL | F: for<'r> T0<'r, (<Self as Ty<'r>>::V,), O = <B as Ty<'r>>::V>,
23-
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `T1::m`
24-
251
error[E0271]: type mismatch resolving `for<'r> <[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39] as FnOnce<((&'r u8,),)>>::Output == Unit3`
262
--> $DIR/issue-62203-hrtb-ice.rs:40:9
273
|
@@ -48,6 +24,30 @@ LL | where
4824
LL | F: for<'r> T0<'r, (<Self as Ty<'r>>::V,), O = <B as Ty<'r>>::V>,
4925
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `T1::m`
5026

27+
error[E0271]: type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
28+
--> $DIR/issue-62203-hrtb-ice.rs:38:19
29+
|
30+
LL | let v = Unit2.m(
31+
| ^ type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:17: 42:39]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
32+
|
33+
note: expected this to be `<_ as Ty<'_>>::V`
34+
--> $DIR/issue-62203-hrtb-ice.rs:21:14
35+
|
36+
LL | type O = T::Output;
37+
| ^^^^^^^^^
38+
= note: expected associated type `<_ as Ty<'_>>::V`
39+
found struct `Unit4`
40+
= help: consider constraining the associated type `<_ as Ty<'_>>::V` to `Unit4` or calling a method that returns `<_ as Ty<'_>>::V`
41+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
42+
note: required by a bound in `T1::m`
43+
--> $DIR/issue-62203-hrtb-ice.rs:27:51
44+
|
45+
LL | fn m<'a, B: Ty<'a>, F>(&self, f: F) -> Unit1
46+
| - required by a bound in this
47+
LL | where
48+
LL | F: for<'r> T0<'r, (<Self as Ty<'r>>::V,), O = <B as Ty<'r>>::V>,
49+
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `T1::m`
50+
5151
error: aborting due to 2 previous errors
5252

5353
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)