Skip to content

Commit

Permalink
Use sup instead of eq when unifying self type
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Apr 22, 2024
1 parent 93c6c04 commit 8995c2c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 75 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Expand Up @@ -1376,8 +1376,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
(xform_self_ty, xform_ret_ty) =
self.xform_self_ty(probe.item, impl_ty, impl_args);
xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
// FIXME: Make this `ocx.eq` once we define opaques more eagerly.
match self.at(cause, self.param_env).eq(
// FIXME: Make this `ocx.sup` once we define opaques more eagerly.
match self.at(cause, self.param_env).sup(
DefineOpaqueTypes::No,
xform_self_ty,
self_ty,
Expand Down Expand Up @@ -1437,8 +1437,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
(xform_self_ty, xform_ret_ty) =
self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
// FIXME: Make this `ocx.eq` once we define opaques more eagerly.
match self.at(cause, self.param_env).eq(
// FIXME: Make this `ocx.sup` once we define opaques more eagerly.
match self.at(cause, self.param_env).sup(
DefineOpaqueTypes::No,
xform_self_ty,
self_ty,
Expand Down Expand Up @@ -1489,8 +1489,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
(xform_self_ty, xform_ret_ty) =
self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
// FIXME: Make this `ocx.eq` once we define opaques more eagerly.
match self.at(cause, self.param_env).eq(
// FIXME: Make this `ocx.sup` once we define opaques more eagerly.
match self.at(cause, self.param_env).sup(
DefineOpaqueTypes::No,
xform_self_ty,
self_ty,
Expand Down
11 changes: 8 additions & 3 deletions tests/ui/impl-trait/issues/issue-62742.rs
@@ -1,12 +1,17 @@
use std::marker::PhantomData;

fn _alias_check() {
fn a() {
WrongImpl::foo(0i32);
//~^ ERROR the trait bound `RawImpl<_>: Raw<_>` is not satisfied
//~| ERROR the function or associated item `foo` exists for struct `SafeImpl<_, RawImpl<_>>`, but its trait bounds were not satisfied
//~^ ERROR overflow assigning `_` to `[_]`
}

fn b() {
WrongImpl::<()>::foo(0i32);
//~^ ERROR the trait bound `RawImpl<()>: Raw<()>` is not satisfied
//~| ERROR trait bounds were not satisfied
}

fn c() {
CorrectImpl::foo(0i32);
}

Expand Down
52 changes: 10 additions & 42 deletions tests/ui/impl-trait/issues/issue-62742.stderr
@@ -1,30 +1,11 @@
error[E0599]: the function or associated item `foo` exists for struct `SafeImpl<_, RawImpl<_>>`, but its trait bounds were not satisfied
error[E0275]: overflow assigning `_` to `[_]`
--> $DIR/issue-62742.rs:4:16
|
LL | WrongImpl::foo(0i32);
| ^^^ function or associated item cannot be called on `SafeImpl<_, RawImpl<_>>` due to unsatisfied trait bounds
...
LL | pub struct RawImpl<T>(PhantomData<T>);
| --------------------- doesn't satisfy `RawImpl<_>: Raw<_>`
...
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
| ----------------------------------------- function or associated item `foo` not found for this struct
|
note: trait bound `RawImpl<_>: Raw<_>` was not satisfied
--> $DIR/issue-62742.rs:29:20
|
LL | impl<T: ?Sized, A: Raw<T>> SafeImpl<T, A> {
| ^^^^^^ --------------
| |
| unsatisfied trait bound introduced here
note: the trait `Raw` must be implemented
--> $DIR/issue-62742.rs:13:1
|
LL | pub trait Raw<T: ?Sized> {
| ^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^

error[E0599]: the function or associated item `foo` exists for struct `SafeImpl<(), RawImpl<()>>`, but its trait bounds were not satisfied
--> $DIR/issue-62742.rs:7:22
--> $DIR/issue-62742.rs:9:22
|
LL | WrongImpl::<()>::foo(0i32);
| ^^^ function or associated item cannot be called on `SafeImpl<(), RawImpl<()>>` due to unsatisfied trait bounds
Expand All @@ -36,46 +17,33 @@ LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
| ----------------------------------------- function or associated item `foo` not found for this struct
|
note: trait bound `RawImpl<()>: Raw<()>` was not satisfied
--> $DIR/issue-62742.rs:29:20
--> $DIR/issue-62742.rs:34:20
|
LL | impl<T: ?Sized, A: Raw<T>> SafeImpl<T, A> {
| ^^^^^^ --------------
| |
| unsatisfied trait bound introduced here
note: the trait `Raw` must be implemented
--> $DIR/issue-62742.rs:13:1
--> $DIR/issue-62742.rs:18:1
|
LL | pub trait Raw<T: ?Sized> {
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `RawImpl<_>: Raw<_>` is not satisfied
--> $DIR/issue-62742.rs:4:5
|
LL | WrongImpl::foo(0i32);
| ^^^^^^^^^ the trait `Raw<_>` is not implemented for `RawImpl<_>`
|
= help: the trait `Raw<[_]>` is implemented for `RawImpl<_>`
note: required by a bound in `SafeImpl`
--> $DIR/issue-62742.rs:27:35
|
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
| ^^^^^^ required by this bound in `SafeImpl`

error[E0277]: the trait bound `RawImpl<()>: Raw<()>` is not satisfied
--> $DIR/issue-62742.rs:7:5
--> $DIR/issue-62742.rs:9:5
|
LL | WrongImpl::<()>::foo(0i32);
| ^^^^^^^^^^^^^^^ the trait `Raw<()>` is not implemented for `RawImpl<()>`
|
= help: the trait `Raw<[()]>` is implemented for `RawImpl<()>`
= help: for that trait implementation, expected `[()]`, found `()`
note: required by a bound in `SafeImpl`
--> $DIR/issue-62742.rs:27:35
--> $DIR/issue-62742.rs:32:35
|
LL | pub struct SafeImpl<T: ?Sized, A: Raw<T>>(PhantomData<(A, T)>);
| ^^^^^^ required by this bound in `SafeImpl`

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
Some errors have detailed explanations: E0275, E0277, E0599.
For more information about an error, try `rustc --explain E0275`.
2 changes: 1 addition & 1 deletion tests/ui/impl-trait/issues/issue-84073.rs
Expand Up @@ -30,5 +30,5 @@ where

fn main() {
Race::new(|race| race.when());
//~^ ERROR the method `when` exists for struct `RaceBuilder<_, Never<_>>`, but its trait bounds were not satisfied
//~^ ERROR overflow assigning `_` to `Option<_>`
}
26 changes: 3 additions & 23 deletions tests/ui/impl-trait/issues/issue-84073.stderr
@@ -1,29 +1,9 @@
error[E0599]: the method `when` exists for struct `RaceBuilder<_, Never<_>>`, but its trait bounds were not satisfied
error[E0275]: overflow assigning `_` to `Option<_>`
--> $DIR/issue-84073.rs:32:27
|
LL | pub struct Never<T>(PhantomData<T>);
| ------------------- doesn't satisfy `Never<_>: StatefulFuture<Option<_>>`
...
LL | pub struct RaceBuilder<F, S> {
| ---------------------------- method `when` not found for this struct
...
LL | Race::new(|race| race.when());
| ^^^^ method cannot be called on `RaceBuilder<_, Never<_>>` due to unsatisfied trait bounds
|
note: trait bound `Never<_>: StatefulFuture<Option<_>>` was not satisfied
--> $DIR/issue-84073.rs:14:8
|
LL | impl<T, F> RaceBuilder<T, F>
| -----------------
LL | where
LL | F: StatefulFuture<Option<T>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced here
note: the trait `StatefulFuture` must be implemented
--> $DIR/issue-84073.rs:3:1
|
LL | pub trait StatefulFuture<S> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0599`.
For more information about this error, try `rustc --explain E0275`.
24 changes: 24 additions & 0 deletions tests/ui/methods/self-type-is-sup-no-eq.rs
@@ -0,0 +1,24 @@
//@ check-pass

// Test that we use `sup` not `eq` during method probe, since this has an effect
// on the leak check. This is (conceptually) minimized from a crater run for
// `wrend 0.3.6`.

use std::ops::Deref;

struct A;

impl Deref for A {
type Target = B<dyn Fn(&())>;

fn deref(&self) -> &<Self as Deref>::Target { todo!() }
}

struct B<T: ?Sized>(T);
impl<T> B<dyn Fn(T)> {
fn method(&self) {}
}

fn main() {
A.method();
}

0 comments on commit 8995c2c

Please sign in to comment.