Skip to content

Commit 137a9fd

Browse files
committed
Allow defining opaque types during trait object upcasting.
No stable code is affected, as this requires the `trait_upcasting` feature gate.
1 parent e82a1e5 commit 137a9fd

File tree

6 files changed

+47
-21
lines changed

6 files changed

+47
-21
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
26162616
nested.extend(
26172617
self.infcx
26182618
.at(&obligation.cause, obligation.param_env)
2619-
.eq(DefineOpaqueTypes::No, source_projection, target_projection)
2619+
.eq(DefineOpaqueTypes::Yes, source_projection, target_projection)
26202620
.map_err(|_| SelectionError::Unimplemented)?
26212621
.into_obligations(),
26222622
);

tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.current.stderr

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.next.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: internal compiler error: error performing operation: query type op
2-
--> $DIR/illegal-upcast-from-impl-opaque.rs:25:1
2+
--> $DIR/illegal-upcast-from-impl-opaque.rs:26:1
33
|
44
LL | fn illegal(x: &dyn Sub<Assoc = Foo>) -> &dyn Super<Assoc = i32> {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note:
8-
--> $DIR/illegal-upcast-from-impl-opaque.rs:25:1
8+
--> $DIR/illegal-upcast-from-impl-opaque.rs:26:1
99
|
1010
LL | fn illegal(x: &dyn Sub<Assoc = Foo>) -> &dyn Super<Assoc = i32> {
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//@[next] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
88
//@[next] normalize-stderr-test "delayed at .*" -> ""
99
//@[next] rustc-env:RUST_BACKTRACE=0
10+
//@[current] check-pass
1011

1112
#![feature(trait_upcasting, type_alias_impl_trait)]
1213

@@ -23,7 +24,7 @@ impl<T: ?Sized> Super for T {
2324
type Foo = impl Sized;
2425

2526
fn illegal(x: &dyn Sub<Assoc = Foo>) -> &dyn Super<Assoc = i32> {
26-
x //[current]~ mismatched types
27+
x
2728
}
2829

2930
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: internal compiler error: error performing operation: query type op
2+
--> $DIR/illegal-upcast-to-impl-opaque.rs:24:1
3+
|
4+
LL | fn illegal(x: &dyn Sub<Assoc = i32>) -> &dyn Super<Assoc = impl Sized> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note:
8+
--> $DIR/illegal-upcast-to-impl-opaque.rs:24:1
9+
|
10+
LL | fn illegal(x: &dyn Sub<Assoc = i32>) -> &dyn Super<Assoc = impl Sized> {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
query stack during panic:
14+
end of query stack
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
//@[next] failure-status: 101
4+
//@[next] known-bug: unknown
5+
//@[next] normalize-stderr-test "note: .*\n\n" -> ""
6+
//@[next] normalize-stderr-test "thread 'rustc' panicked.*\n.*\n" -> ""
7+
//@[next] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
8+
//@[next] normalize-stderr-test "delayed at .*" -> ""
9+
//@[next] rustc-env:RUST_BACKTRACE=0
10+
//@[current] check-pass
11+
12+
#![feature(trait_upcasting)]
13+
14+
trait Super {
15+
type Assoc;
16+
}
17+
18+
trait Sub: Super {}
19+
20+
impl<T: ?Sized> Super for T {
21+
type Assoc = i32;
22+
}
23+
24+
fn illegal(x: &dyn Sub<Assoc = i32>) -> &dyn Super<Assoc = impl Sized> {
25+
x
26+
}
27+
28+
fn main() {}

0 commit comments

Comments
 (0)