Skip to content

Commit 0bb99b0

Browse files
committed
Switch can_eq and can_sub to DefineOpaqueTypes::Yes
They are mostly used in diagnostics anyway
1 parent e56f0d7 commit 0bb99b0

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

compiler/rustc_infer/src/infer/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,9 @@ impl<'tcx> InferCtxt<'tcx> {
936936
{
937937
let origin = &ObligationCause::dummy();
938938
self.probe(|_| {
939-
self.at(origin, param_env).sub(DefineOpaqueTypes::No, expected, actual).is_ok()
939+
// We're only answering whether there could be a subtyping relation, and with
940+
// opaque types, "there could be one", via registering a hidden type.
941+
self.at(origin, param_env).sub(DefineOpaqueTypes::Yes, expected, actual).is_ok()
940942
})
941943
}
942944

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

951955
#[instrument(skip(self), level = "debug")]
+12
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() {}
+20
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)