Use sup instead of eq when unifying self type

This commit is contained in:
Michael Goulet 2024-04-05 22:00:43 -04:00
parent 93c6c0445d
commit 8995c2c4a2
6 changed files with 52 additions and 75 deletions

View File

@ -1376,8 +1376,8 @@ fn consider_probe(
(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,
@ -1437,8 +1437,8 @@ fn consider_probe(
(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,
@ -1489,8 +1489,8 @@ fn consider_probe(
(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,

View File

@ -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);
}

View File

@ -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
@ -36,33 +17,20 @@ 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<()>`
@ -70,12 +38,12 @@ LL | WrongImpl::<()>::foo(0i32);
= 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`.

View File

@ -30,5 +30,5 @@ pub fn new(race: R) {}
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<_>`
}

View File

@ -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`.

View File

@ -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();
}