Skip to content

Commit 685ba72

Browse files
Use sup instead of eq when unifying self type
1 parent a0cbd7a commit 685ba72

File tree

6 files changed

+52
-75
lines changed

6 files changed

+52
-75
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1375,8 +1375,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
13751375
(xform_self_ty, xform_ret_ty) =
13761376
self.xform_self_ty(probe.item, impl_ty, impl_args);
13771377
xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
1378-
// FIXME: Make this `ocx.eq` once we define opaques more eagerly.
1379-
match self.at(cause, self.param_env).eq(
1378+
// FIXME: Make this `ocx.sup` once we define opaques more eagerly.
1379+
match self.at(cause, self.param_env).sup(
13801380
DefineOpaqueTypes::No,
13811381
xform_self_ty,
13821382
self_ty,
@@ -1436,8 +1436,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14361436
(xform_self_ty, xform_ret_ty) =
14371437
self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
14381438
xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
1439-
// FIXME: Make this `ocx.eq` once we define opaques more eagerly.
1440-
match self.at(cause, self.param_env).eq(
1439+
// FIXME: Make this `ocx.sup` once we define opaques more eagerly.
1440+
match self.at(cause, self.param_env).sup(
14411441
DefineOpaqueTypes::No,
14421442
xform_self_ty,
14431443
self_ty,
@@ -1488,8 +1488,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14881488
(xform_self_ty, xform_ret_ty) =
14891489
self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
14901490
xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
1491-
// FIXME: Make this `ocx.eq` once we define opaques more eagerly.
1492-
match self.at(cause, self.param_env).eq(
1491+
// FIXME: Make this `ocx.sup` once we define opaques more eagerly.
1492+
match self.at(cause, self.param_env).sup(
14931493
DefineOpaqueTypes::No,
14941494
xform_self_ty,
14951495
self_ty,

tests/ui/impl-trait/issues/issue-62742.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
use std::marker::PhantomData;
22

3-
fn _alias_check() {
3+
fn a() {
44
WrongImpl::foo(0i32);
5-
//~^ ERROR the trait bound `RawImpl<_>: Raw<_>` is not satisfied
6-
//~| ERROR the function or associated item `foo` exists for struct `SafeImpl<_, RawImpl<_>>`, but its trait bounds were not satisfied
5+
//~^ ERROR overflow assigning `_` to `[_]`
6+
}
7+
8+
fn b() {
79
WrongImpl::<()>::foo(0i32);
810
//~^ ERROR the trait bound `RawImpl<()>: Raw<()>` is not satisfied
911
//~| ERROR trait bounds were not satisfied
12+
}
13+
14+
fn c() {
1015
CorrectImpl::foo(0i32);
1116
}
1217

+10-42
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
1-
error[E0599]: the function or associated item `foo` exists for struct `SafeImpl<_, RawImpl<_>>`, but its trait bounds were not satisfied
1+
error[E0275]: overflow assigning `_` to `[_]`
22
--> $DIR/issue-62742.rs:4:16
33
|
44
LL | WrongImpl::foo(0i32);
5-
| ^^^ function or associated item cannot be called on `SafeImpl<_, RawImpl<_>>` due to unsatisfied trait bounds
6-
...
7-
LL | pub struct RawImpl<T>(PhantomData<T>);
8-
| --------------------- doesn't satisfy `RawImpl<_>: Raw<_>`
9-
...
10-
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
11-
| ----------------------------------------- function or associated item `foo` not found for this struct
12-
|
13-
note: trait bound `RawImpl<_>: Raw<_>` was not satisfied
14-
--> $DIR/issue-62742.rs:29:20
15-
|
16-
LL | impl<T: ?Sized, A: Raw<T>> SafeImpl<T, A> {
17-
| ^^^^^^ --------------
18-
| |
19-
| unsatisfied trait bound introduced here
20-
note: the trait `Raw` must be implemented
21-
--> $DIR/issue-62742.rs:13:1
22-
|
23-
LL | pub trait Raw<T: ?Sized> {
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^
256

267
error[E0599]: the function or associated item `foo` exists for struct `SafeImpl<(), RawImpl<()>>`, but its trait bounds were not satisfied
27-
--> $DIR/issue-62742.rs:7:22
8+
--> $DIR/issue-62742.rs:9:22
289
|
2910
LL | WrongImpl::<()>::foo(0i32);
3011
| ^^^ function or associated item cannot be called on `SafeImpl<(), RawImpl<()>>` due to unsatisfied trait bounds
@@ -36,46 +17,33 @@ LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
3617
| ----------------------------------------- function or associated item `foo` not found for this struct
3718
|
3819
note: trait bound `RawImpl<()>: Raw<()>` was not satisfied
39-
--> $DIR/issue-62742.rs:29:20
20+
--> $DIR/issue-62742.rs:34:20
4021
|
4122
LL | impl<T: ?Sized, A: Raw<T>> SafeImpl<T, A> {
4223
| ^^^^^^ --------------
4324
| |
4425
| unsatisfied trait bound introduced here
4526
note: the trait `Raw` must be implemented
46-
--> $DIR/issue-62742.rs:13:1
27+
--> $DIR/issue-62742.rs:18:1
4728
|
4829
LL | pub trait Raw<T: ?Sized> {
4930
| ^^^^^^^^^^^^^^^^^^^^^^^^
5031

51-
error[E0277]: the trait bound `RawImpl<_>: Raw<_>` is not satisfied
52-
--> $DIR/issue-62742.rs:4:5
53-
|
54-
LL | WrongImpl::foo(0i32);
55-
| ^^^^^^^^^ the trait `Raw<_>` is not implemented for `RawImpl<_>`
56-
|
57-
= help: the trait `Raw<[_]>` is implemented for `RawImpl<_>`
58-
note: required by a bound in `SafeImpl`
59-
--> $DIR/issue-62742.rs:27:35
60-
|
61-
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
62-
| ^^^^^^ required by this bound in `SafeImpl`
63-
6432
error[E0277]: the trait bound `RawImpl<()>: Raw<()>` is not satisfied
65-
--> $DIR/issue-62742.rs:7:5
33+
--> $DIR/issue-62742.rs:9:5
6634
|
6735
LL | WrongImpl::<()>::foo(0i32);
6836
| ^^^^^^^^^^^^^^^ the trait `Raw<()>` is not implemented for `RawImpl<()>`
6937
|
7038
= help: the trait `Raw<[()]>` is implemented for `RawImpl<()>`
7139
= help: for that trait implementation, expected `[()]`, found `()`
7240
note: required by a bound in `SafeImpl`
73-
--> $DIR/issue-62742.rs:27:35
41+
--> $DIR/issue-62742.rs:32:35
7442
|
7543
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
7644
| ^^^^^^ required by this bound in `SafeImpl`
7745

78-
error: aborting due to 4 previous errors
46+
error: aborting due to 3 previous errors
7947

80-
Some errors have detailed explanations: E0277, E0599.
81-
For more information about an error, try `rustc --explain E0277`.
48+
Some errors have detailed explanations: E0275, E0277, E0599.
49+
For more information about an error, try `rustc --explain E0275`.

tests/ui/impl-trait/issues/issue-84073.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ where
3030

3131
fn main() {
3232
Race::new(|race| race.when());
33-
//~^ ERROR the method `when` exists for struct `RaceBuilder<_, Never<_>>`, but its trait bounds were not satisfied
33+
//~^ ERROR overflow assigning `_` to `Option<_>`
3434
}
+3-23
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
1-
error[E0599]: the method `when` exists for struct `RaceBuilder<_, Never<_>>`, but its trait bounds were not satisfied
1+
error[E0275]: overflow assigning `_` to `Option<_>`
22
--> $DIR/issue-84073.rs:32:27
33
|
4-
LL | pub struct Never<T>(PhantomData<T>);
5-
| ------------------- doesn't satisfy `Never<_>: StatefulFuture<Option<_>>`
6-
...
7-
LL | pub struct RaceBuilder<F, S> {
8-
| ---------------------------- method `when` not found for this struct
9-
...
104
LL | Race::new(|race| race.when());
11-
| ^^^^ method cannot be called on `RaceBuilder<_, Never<_>>` due to unsatisfied trait bounds
12-
|
13-
note: trait bound `Never<_>: StatefulFuture<Option<_>>` was not satisfied
14-
--> $DIR/issue-84073.rs:14:8
15-
|
16-
LL | impl<T, F> RaceBuilder<T, F>
17-
| -----------------
18-
LL | where
19-
LL | F: StatefulFuture<Option<T>>,
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
21-
note: the trait `StatefulFuture` must be implemented
22-
--> $DIR/issue-84073.rs:3:1
23-
|
24-
LL | pub trait StatefulFuture<S> {}
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^
266

277
error: aborting due to 1 previous error
288

29-
For more information about this error, try `rustc --explain E0599`.
9+
For more information about this error, try `rustc --explain E0275`.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ check-pass
2+
3+
// Test that we use `sup` not `eq` during method probe, since this has an effect
4+
// on the leak check. This is (conceptually) minimized from a crater run for
5+
// `wrend 0.3.6`.
6+
7+
use std::ops::Deref;
8+
9+
struct A;
10+
11+
impl Deref for A {
12+
type Target = B<dyn Fn(&())>;
13+
14+
fn deref(&self) -> &<Self as Deref>::Target { todo!() }
15+
}
16+
17+
struct B<T: ?Sized>(T);
18+
impl<T> B<dyn Fn(T)> {
19+
fn method(&self) {}
20+
}
21+
22+
fn main() {
23+
A.method();
24+
}

0 commit comments

Comments
 (0)