Skip to content

Commit cdcca7e

Browse files
committed
Switch can_eq and can_sub to DefineOpaqueTypes::Yes
They are mostly used in diagnostics anyway
1 parent 10e8bca commit cdcca7e

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,9 @@ impl<'tcx> InferCtxt<'tcx> {
843843
{
844844
let origin = &ObligationCause::dummy();
845845
self.probe(|_| {
846-
self.at(origin, param_env).sub(DefineOpaqueTypes::No, expected, actual).is_ok()
846+
// We're only answering whether there could be a subtyping relation, and with
847+
// opaque types, "there could be one", via registering a hidden type.
848+
self.at(origin, param_env).sub(DefineOpaqueTypes::Yes, expected, actual).is_ok()
847849
})
848850
}
849851

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

858862
#[instrument(skip(self), level = "debug")]

tests/ui/impl-trait/nested_impl_trait.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
4242
|
4343
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
4444

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

54-
error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
54+
error[E0277]: the trait bound `impl Into<u32>: Into<impl Debug>` is not satisfied
5555
--> $DIR/nested_impl_trait.rs:19:34
5656
|
5757
LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
58-
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Debug`, which is required by `impl Into<u32>: Into<impl Debug>`
58+
| ^^^^^^^^^^^^^^^^^^^^^ the trait `From<impl Into<u32>>` is not implemented for `impl Into<u32>`, which is required by `impl Into<u32>: Into<impl Debug>`
5959
|
6060
= help: the trait `Into<U>` is implemented for `T`
6161
= note: required for `impl Into<u32>` to implement `Into<impl Debug>`
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(type_alias_impl_trait)]
2+
struct Foo;
3+
4+
type Bar = impl Sized;
5+
//~^ ERROR unconstrained opaque type
6+
7+
impl Foo {
8+
fn foo(self: Bar) {}
9+
//~^ ERROR: invalid `self` parameter type: Bar
10+
}
11+
12+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: unconstrained opaque type
2+
--> $DIR/arbitrary-self-opaque.rs:4:12
3+
|
4+
LL | type Bar = impl Sized;
5+
| ^^^^^^^^^^
6+
|
7+
= note: `Bar` must be used in combination with a concrete type within the same module
8+
9+
error[E0307]: invalid `self` parameter type: Bar
10+
--> $DIR/arbitrary-self-opaque.rs:8:18
11+
|
12+
LL | fn foo(self: Bar) {}
13+
| ^^^
14+
|
15+
= note: type of `self` must be `Self` or a type that dereferences to it
16+
= 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`)
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0307`.

0 commit comments

Comments
 (0)