Skip to content

Commit

Permalink
Switch can_eq and can_sub to DefineOpaqueTypes::Yes
Browse files Browse the repository at this point in the history
They are mostly used in diagnostics anyway
  • Loading branch information
oli-obk committed Apr 4, 2024
1 parent 10e8bca commit cdcca7e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,9 @@ impl<'tcx> InferCtxt<'tcx> {
{
let origin = &ObligationCause::dummy();
self.probe(|_| {
self.at(origin, param_env).sub(DefineOpaqueTypes::No, expected, actual).is_ok()
// We're only answering whether there could be a subtyping relation, and with
// opaque types, "there could be one", via registering a hidden type.
self.at(origin, param_env).sub(DefineOpaqueTypes::Yes, expected, actual).is_ok()
})
}

Expand All @@ -852,7 +854,9 @@ impl<'tcx> InferCtxt<'tcx> {
T: at::ToTrace<'tcx>,
{
let origin = &ObligationCause::dummy();
self.probe(|_| self.at(origin, param_env).eq(DefineOpaqueTypes::No, a, b).is_ok())
// We're only answering whether the types could be the same, and with
// opaque types, "they can be the same", via registering a hidden type.
self.probe(|_| self.at(origin, param_env).eq(DefineOpaqueTypes::Yes, a, b).is_ok())
}

#[instrument(skip(self), level = "debug")]
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/impl-trait/nested_impl_trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods

error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
--> $DIR/nested_impl_trait.rs:6:46
|
LL | fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Debug`, which is required by `impl Into<u32>: Into<impl Debug>`
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Into<u32>`, which is required by `impl Into<u32>: Into<impl Debug>`
|
= help: the trait `Into<U>` is implemented for `T`
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`

error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
--> $DIR/nested_impl_trait.rs:19:34
|
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Debug`, which is required by `impl Into<u32>: Into<impl Debug>`
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Into<u32>`, which is required by `impl Into<u32>: Into<impl Debug>`
|
= help: the trait `Into<U>` is implemented for `T`
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/self/arbitrary-self-opaque.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(type_alias_impl_trait)]
struct Foo;

type Bar = impl Sized;
//~^ ERROR unconstrained opaque type

impl Foo {
fn foo(self: Bar) {}
//~^ ERROR: invalid `self` parameter type: Bar
}

fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/self/arbitrary-self-opaque.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: unconstrained opaque type
--> $DIR/arbitrary-self-opaque.rs:4:12
|
LL | type Bar = impl Sized;
| ^^^^^^^^^^
|
= note: `Bar` must be used in combination with a concrete type within the same module

error[E0307]: invalid `self` parameter type: Bar
--> $DIR/arbitrary-self-opaque.rs:8:18
|
LL | fn foo(self: Bar) {}
| ^^^
|
= note: type of `self` must be `Self` or a type that dereferences to it
= help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)

error: aborting due to 2 previous errors

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

0 comments on commit cdcca7e

Please sign in to comment.