From 169a045dca0e8cc7c720a962cef274fb5f8fafef Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 21 Feb 2024 14:50:17 +0000 Subject: [PATCH] Switch upcast projections to allowing opaque types and add a test showing it works. The old solver was already ICEing on this test before this change --- ...gal-upcast-from-impl-opaque.current.stderr | 17 +++++++++++ ...llegal-upcast-from-impl-opaque.next.stderr | 14 +++++++++ .../illegal-upcast-from-impl-opaque.rs | 29 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.current.stderr create mode 100644 tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.next.stderr create mode 100644 tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.rs diff --git a/tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.current.stderr b/tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.current.stderr new file mode 100644 index 00000000000..c54a1c42bad --- /dev/null +++ b/tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.current.stderr @@ -0,0 +1,17 @@ +error[E0308]: mismatched types + --> $DIR/illegal-upcast-from-impl-opaque.rs:26:5 + | +LL | type Foo = impl Sized; + | ---------- the found opaque type +LL | +LL | fn illegal(x: &dyn Sub) -> &dyn Super { + | ----------------------- expected `&dyn Super` because of return type +LL | x + | ^ expected trait `Super`, found trait `Sub` + | + = note: expected reference `&dyn Super` + found reference `&dyn Sub` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.next.stderr b/tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.next.stderr new file mode 100644 index 00000000000..3c2bc0b9190 --- /dev/null +++ b/tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.next.stderr @@ -0,0 +1,14 @@ +error: internal compiler error: error performing operation: query type op + --> $DIR/illegal-upcast-from-impl-opaque.rs:25:1 + | +LL | fn illegal(x: &dyn Sub) -> &dyn Super { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: + --> $DIR/illegal-upcast-from-impl-opaque.rs:25:1 + | +LL | fn illegal(x: &dyn Sub) -> &dyn Super { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +query stack during panic: +end of query stack diff --git a/tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.rs b/tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.rs new file mode 100644 index 00000000000..f344474054a --- /dev/null +++ b/tests/ui/traits/trait-upcasting/illegal-upcast-from-impl-opaque.rs @@ -0,0 +1,29 @@ +//@ revisions: current next +//@[next] compile-flags: -Znext-solver +//@[next] failure-status: 101 +//@[next] known-bug: unknown +//@[next] normalize-stderr-test "note: .*\n\n" -> "" +//@[next] normalize-stderr-test "thread 'rustc' panicked.*\n.*\n" -> "" +//@[next] normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: " +//@[next] normalize-stderr-test "delayed at .*" -> "" +//@[next] rustc-env:RUST_BACKTRACE=0 + +#![feature(trait_upcasting, type_alias_impl_trait)] + +trait Super { + type Assoc; +} + +trait Sub: Super {} + +impl Super for T { + type Assoc = i32; +} + +type Foo = impl Sized; + +fn illegal(x: &dyn Sub) -> &dyn Super { + x //[current]~ mismatched types +} + +fn main() {}