Skip to content

Commit 62a7694

Browse files
committed
revert leak check changes in candidate winnowing
reverts the behavior changes of rust-lang#119820 to give some additional time to `sqlx` as it is affected by this change.
1 parent d9e85b5 commit 62a7694

20 files changed

+85
-253
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
562562
obligation: &PredicateObligation<'tcx>,
563563
) -> Result<EvaluationResult, OverflowError> {
564564
debug_assert!(!self.infcx.next_trait_solver());
565-
self.evaluation_probe(|this, _outer_universe| {
565+
self.evaluation_probe(|this| {
566566
let goal =
567567
this.infcx.resolve_vars_if_possible((obligation.predicate, obligation.param_env));
568568
let mut result = this.evaluate_predicate_recursively(
@@ -585,11 +585,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
585585
/// `op`, but this can be overwritten if necessary.
586586
fn evaluation_probe(
587587
&mut self,
588-
op: impl FnOnce(&mut Self, &mut ty::UniverseIndex) -> Result<EvaluationResult, OverflowError>,
588+
op: impl FnOnce(&mut Self) -> Result<EvaluationResult, OverflowError>,
589589
) -> Result<EvaluationResult, OverflowError> {
590590
self.infcx.probe(|snapshot| -> Result<EvaluationResult, OverflowError> {
591-
let mut outer_universe = self.infcx.universe();
592-
let result = op(self, &mut outer_universe)?;
591+
let outer_universe = self.infcx.universe();
592+
let result = op(self)?;
593593

594594
match self.infcx.leak_check(outer_universe, Some(snapshot)) {
595595
Ok(()) => {}
@@ -1267,9 +1267,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12671267
&mut self,
12681268
stack: &TraitObligationStack<'o, 'tcx>,
12691269
candidate: &SelectionCandidate<'tcx>,
1270-
leak_check_higher_ranked_goal: LeakCheckHigherRankedGoal,
1270+
_leak_check_higher_ranked_goal: LeakCheckHigherRankedGoal,
12711271
) -> Result<EvaluationResult, OverflowError> {
1272-
let mut result = self.evaluation_probe(|this, outer_universe| {
1272+
let mut result = self.evaluation_probe(|this| {
12731273
// We eagerly instantiate higher ranked goals to prevent universe errors
12741274
// from impacting candidate selection. This matches the behavior of the new
12751275
// solver. This slightly weakens type inference.
@@ -1280,10 +1280,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12801280
// in an overlap error in coherence.
12811281
let p = self.infcx.enter_forall_and_leak_universe(stack.obligation.predicate);
12821282
let obligation = stack.obligation.with(this.tcx(), ty::Binder::dummy(p));
1283-
match leak_check_higher_ranked_goal {
1284-
LeakCheckHigherRankedGoal::No => *outer_universe = self.infcx.universe(),
1285-
LeakCheckHigherRankedGoal::Yes => {}
1286-
}
12871283

12881284
match this.confirm_candidate(&obligation, candidate.clone()) {
12891285
Ok(selection) => {
@@ -1710,13 +1706,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17101706
stack: &TraitObligationStack<'o, 'tcx>,
17111707
where_clause_trait_ref: ty::PolyTraitRef<'tcx>,
17121708
) -> Result<EvaluationResult, OverflowError> {
1713-
self.evaluation_probe(|this, outer_universe| {
1709+
self.evaluation_probe(|this| {
17141710
// Eagerly instantiate higher ranked goals.
17151711
//
17161712
// See the comment in `evaluate_candidate` to see why.
17171713
let p = self.infcx.enter_forall_and_leak_universe(stack.obligation.predicate);
17181714
let obligation = stack.obligation.with(this.tcx(), ty::Binder::dummy(p));
1719-
*outer_universe = self.infcx.universe();
17201715
match this.match_where_clause_trait_ref(&obligation, where_clause_trait_ref) {
17211716
Ok(obligations) => this.evaluate_predicates_recursively(stack.list(), obligations),
17221717
Err(()) => Ok(EvaluatedToErr),

tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-1.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ check-pass
12
// cc #119820
23

34
trait Trait {}
@@ -21,8 +22,6 @@ where
2122
// the leak check both candidates may apply and we prefer the
2223
// `param_env` candidate in winnowing.
2324
hr_bound::<&T>();
24-
//~^ ERROR the parameter type `T` may not live long enough
25-
//~| ERROR implementation of `Trait` is not general enough
2625
}
2726

2827
fn main() {}

tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-1.stderr

-26
This file was deleted.

tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-2.current.stderr

-25
This file was deleted.

tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-2.next.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0277]: the trait bound `for<'a> T: Trait<'a, '_>` is not satisfied
2-
--> $DIR/candidate-from-env-universe-err-2.rs:14:5
2+
--> $DIR/candidate-from-env-universe-err-2.rs:15:5
33
|
44
LL | impl_hr::<T>();
55
| ^^^^^^^^^^^^^^ the trait `for<'a> Trait<'a, '_>` is not implemented for `T`
66
|
77
note: required by a bound in `impl_hr`
8-
--> $DIR/candidate-from-env-universe-err-2.rs:11:19
8+
--> $DIR/candidate-from-env-universe-err-2.rs:12:19
99
|
1010
LL | fn impl_hr<'b, T: for<'a> Trait<'a, 'b>>() {}
1111
| ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `impl_hr`

tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-2.old.stderr

-26
This file was deleted.

tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-2.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ revisions: current next
22
//@[next] compile-flags: -Znext-solver
3+
//@[current] check-pass
34

45
// cc #119820
56

@@ -13,8 +14,6 @@ fn impl_hr<'b, T: for<'a> Trait<'a, 'b>>() {}
1314
fn not_hr<'a, T: for<'b> Trait<'a, 'b> + OtherTrait<'static>>() {
1415
impl_hr::<T>();
1516
//[next]~^ ERROR the trait bound `for<'a> T: Trait<'a, '_>` is not satisfied
16-
//[current]~^^ERROR lifetime may not live long enough
17-
//[current]~| ERROR implementation of `Trait` is not general enough
1817
}
1918

2019
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
1-
error: implementation of `Trait` is not general enough
2-
--> $DIR/candidate-from-env-universe-err-project.rs:28:5
3-
|
4-
LL | trait_bound::<T>();
5-
| ^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough
6-
|
7-
= note: `T` must implement `Trait<'0>`, for any lifetime `'0`...
8-
= note: ...but it actually implements `Trait<'static>`
9-
10-
error: implementation of `Trait` is not general enough
11-
--> $DIR/candidate-from-env-universe-err-project.rs:39:5
12-
|
13-
LL | projection_bound::<T>();
14-
| ^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough
15-
|
16-
= note: `T` must implement `Trait<'0>`, for any lifetime `'0`...
17-
= note: ...but it actually implements `Trait<'static>`
18-
191
error[E0308]: mismatched types
20-
--> $DIR/candidate-from-env-universe-err-project.rs:39:5
2+
--> $DIR/candidate-from-env-universe-err-project.rs:38:5
213
|
224
LL | projection_bound::<T>();
235
| ^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
@@ -31,7 +13,7 @@ LL | fn projection_bound<T: for<'a> Trait<'a, Assoc = usize>>() {}
3113
| ^^^^^^^^^^^^^
3214

3315
error[E0308]: mismatched types
34-
--> $DIR/candidate-from-env-universe-err-project.rs:55:30
16+
--> $DIR/candidate-from-env-universe-err-project.rs:53:30
3517
|
3618
LL | let _higher_ranked_norm: for<'a> fn(<T as Trait<'a>>::Assoc) = |_| ();
3719
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
@@ -40,7 +22,7 @@ LL | let _higher_ranked_norm: for<'a> fn(<T as Trait<'a>>::Assoc) = |_| ();
4022
found associated type `<T as Trait<'a>>::Assoc`
4123

4224
error[E0308]: mismatched types
43-
--> $DIR/candidate-from-env-universe-err-project.rs:55:30
25+
--> $DIR/candidate-from-env-universe-err-project.rs:53:30
4426
|
4527
LL | let _higher_ranked_norm: for<'a> fn(<T as Trait<'a>>::Assoc) = |_| ();
4628
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
@@ -49,6 +31,6 @@ LL | let _higher_ranked_norm: for<'a> fn(<T as Trait<'a>>::Assoc) = |_| ();
4931
found associated type `<T as Trait<'a>>::Assoc`
5032
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5133

52-
error: aborting due to 5 previous errors
34+
error: aborting due to 3 previous errors
5335

5436
For more information about this error, try `rustc --explain E0308`.

tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-project.next.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | fn function1<T: Trait<'static> + for<'a> Trait<'a>>() {
1515
| +++++++++++++++++++
1616

1717
error[E0277]: the trait bound `for<'a> T: Trait<'a>` is not satisfied
18-
--> $DIR/candidate-from-env-universe-err-project.rs:39:24
18+
--> $DIR/candidate-from-env-universe-err-project.rs:38:24
1919
|
2020
LL | projection_bound::<T>();
2121
| ^ the trait `for<'a> Trait<'a>` is not implemented for `T`
@@ -31,7 +31,7 @@ LL | fn function2<T: Trait<'static, Assoc = usize> + for<'a> Trait<'a>>() {
3131
| +++++++++++++++++++
3232

3333
error[E0271]: type mismatch resolving `<T as Trait<'a>>::Assoc == usize`
34-
--> $DIR/candidate-from-env-universe-err-project.rs:39:24
34+
--> $DIR/candidate-from-env-universe-err-project.rs:38:24
3535
|
3636
LL | projection_bound::<T>();
3737
| ^ type mismatch resolving `<T as Trait<'a>>::Assoc == usize`
@@ -48,13 +48,13 @@ LL | fn projection_bound<T: for<'a> Trait<'a, Assoc = usize>>() {}
4848
| ^^^^^^^^^^^^^ required by this bound in `projection_bound`
4949

5050
error: higher-ranked subtype error
51-
--> $DIR/candidate-from-env-universe-err-project.rs:55:30
51+
--> $DIR/candidate-from-env-universe-err-project.rs:53:30
5252
|
5353
LL | let _higher_ranked_norm: for<'a> fn(<T as Trait<'a>>::Assoc) = |_| ();
5454
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5555

5656
error: higher-ranked subtype error
57-
--> $DIR/candidate-from-env-universe-err-project.rs:55:30
57+
--> $DIR/candidate-from-env-universe-err-project.rs:53:30
5858
|
5959
LL | let _higher_ranked_norm: for<'a> fn(<T as Trait<'a>>::Assoc) = |_| ();
6060
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/higher-ranked/leak-check/candidate-from-env-universe-err-project.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ fn function1<T: Trait<'static>>() {
2727
// We prefer env candidates over impl candidatescausing this to succeed.
2828
trait_bound::<T>();
2929
//[next]~^ ERROR the trait bound `for<'a> T: Trait<'a>` is not satisfied
30-
//[current]~^^ ERROR implementation of `Trait` is not general enough
3130
}
3231

3332
fn function2<T: Trait<'static, Assoc = usize>>() {
@@ -39,8 +38,7 @@ fn function2<T: Trait<'static, Assoc = usize>>() {
3938
projection_bound::<T>();
4039
//[next]~^ ERROR type mismatch resolving `<T as Trait<'a>>::Assoc == usize`
4140
//[next]~| ERROR the trait bound `for<'a> T: Trait<'a>` is not satisfied
42-
//[current]~^^^ ERROR implementation of `Trait` is not general enough
43-
//[current]~| ERROR mismatched types
41+
//[current]~^^^ ERROR mismatched types
4442
}
4543

4644
fn function3<T: Trait<'static, Assoc = usize>>() {

tests/ui/higher-ranked/leak-check/leak-check-in-selection-2.next.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error[E0283]: type annotations needed
2-
--> $DIR/leak-check-in-selection-2.rs:16:5
2+
--> $DIR/leak-check-in-selection-2.rs:17:5
33
|
44
LL | impls_trait::<(), _>();
55
| ^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `U` declared on the function `impls_trait`
66
|
77
note: multiple `impl`s satisfying `for<'a> (): Trait<&'a str, _>` found
8-
--> $DIR/leak-check-in-selection-2.rs:9:1
8+
--> $DIR/leak-check-in-selection-2.rs:10:1
99
|
1010
LL | impl<'a> Trait<&'a str, &'a str> for () {}
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
LL |
1313
LL | impl<'a> Trait<&'a str, String> for () {}
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
note: required by a bound in `impls_trait`
16-
--> $DIR/leak-check-in-selection-2.rs:13:19
16+
--> $DIR/leak-check-in-selection-2.rs:14:19
1717
|
1818
LL | fn impls_trait<T: for<'a> Trait<&'a str, U>, U>() {}
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `impls_trait`

tests/ui/higher-ranked/leak-check/leak-check-in-selection-2.old.stderr

-23
This file was deleted.

tests/ui/higher-ranked/leak-check/leak-check-in-selection-2.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ revisions: old next
22
//@[next] compile-flags: -Znext-solver
3+
//@[old] check-pass
34

45
// cc #119820
56

@@ -14,5 +15,5 @@ fn impls_trait<T: for<'a> Trait<&'a str, U>, U>() {}
1415

1516
fn main() {
1617
impls_trait::<(), _>();
17-
//~^ ERROR type annotations needed
18+
//[next]~^ ERROR type annotations needed
1819
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
1-
error[E0283]: type annotations needed
2-
--> $DIR/leak-check-in-selection-3.rs:18:5
3-
|
4-
LL | impls_leak::<Box<_>>();
5-
| ^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `impls_leak`
6-
|
7-
note: multiple `impl`s satisfying `for<'a> Box<_>: Leak<'a>` found
8-
--> $DIR/leak-check-in-selection-3.rs:9:1
9-
|
10-
LL | impl Leak<'_> for Box<u32> {}
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
LL | impl Leak<'static> for Box<u16> {}
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14-
note: required by a bound in `impls_leak`
15-
--> $DIR/leak-check-in-selection-3.rs:12:18
16-
|
17-
LL | fn impls_leak<T: for<'a> Leak<'a>>() {}
18-
| ^^^^^^^^^^^^^^^^ required by this bound in `impls_leak`
19-
201
error[E0283]: type annotations needed
212
--> $DIR/leak-check-in-selection-3.rs:35:5
223
|
@@ -43,6 +24,6 @@ note: required by a bound in `impls_indirect_leak`
4324
LL | fn impls_indirect_leak<T: for<'a> IndirectLeak<'a>>() {}
4425
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `impls_indirect_leak`
4526

46-
error: aborting due to 2 previous errors
27+
error: aborting due to 1 previous error
4728

4829
For more information about this error, try `rustc --explain E0283`.

tests/ui/higher-ranked/leak-check/leak-check-in-selection-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn direct() {
1616
// The `Box<u16>` impls fails the leak check,
1717
// meaning that we apply the `Box<u32>` impl.
1818
impls_leak::<Box<_>>();
19-
//~^ ERROR type annotations needed
19+
//[next]~^ ERROR type annotations needed
2020
}
2121

2222
trait IndirectLeak<'a> {}

0 commit comments

Comments
 (0)