about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-09-12 08:46:40 +0000
committerbors <bors@rust-lang.org>2022-09-12 08:46:40 +0000
commita93214ec06b57f1eb0cc2fd07e3c4b86b1b1d949 (patch)
tree4e071ef137dd3d3626dca4c639b0753d9240c792 /src/test
parent56e7678ca97e9740f7d09206f767d5bb676917f7 (diff)
parent5599a45e58402b529ef8c724c560e8cfe6e5b72b (diff)
downloadrust-a93214ec06b57f1eb0cc2fd07e3c4b86b1b1d949.tar.gz
rust-a93214ec06b57f1eb0cc2fd07e3c4b86b1b1d949.zip
Auto merge of #101604 - compiler-errors:issue-101465, r=lcnr
Fix ICE in opt_suggest_box_span

We were _totally_ mishandling substs and obligations in `opt_suggest_box_span`, so I reworked that function pretty heavily.

Also some drive-by changes, namely removing `ret_type_span`.

Fixes #101465
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/suggestions/issue-101465.rs25
-rw-r--r--src/test/ui/suggestions/issue-101465.stderr25
2 files changed, 50 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/issue-101465.rs b/src/test/ui/suggestions/issue-101465.rs
new file mode 100644
index 00000000000..8e42e2c2224
--- /dev/null
+++ b/src/test/ui/suggestions/issue-101465.rs
@@ -0,0 +1,25 @@
+#![feature(trait_alias)]
+
+struct B;
+struct C;
+
+trait Tr {}
+
+impl Tr for B {}
+impl Tr for C {}
+
+trait Tr2<S> = Into<S>;
+
+fn foo2<T: Tr2<()>>() {}
+
+fn foo() -> impl Tr {
+    let x = foo2::<_>();
+
+    match true {
+        true => B,
+        false => C,
+        //~^ `match` arms have incompatible types
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/suggestions/issue-101465.stderr b/src/test/ui/suggestions/issue-101465.stderr
new file mode 100644
index 00000000000..e2ca7771257
--- /dev/null
+++ b/src/test/ui/suggestions/issue-101465.stderr
@@ -0,0 +1,25 @@
+error[E0308]: `match` arms have incompatible types
+  --> $DIR/issue-101465.rs:20:18
+   |
+LL | /     match true {
+LL | |         true => B,
+   | |                 - this is found to be of type `B`
+LL | |         false => C,
+   | |                  ^ expected struct `B`, found struct `C`
+LL | |
+LL | |     }
+   | |_____- `match` arms have incompatible types
+   |
+help: you could change the return type to be a boxed trait object
+   |
+LL | fn foo() -> Box<dyn Tr> {
+   |             ~~~~~~~   +
+help: if you change the return type to expect trait objects, box the returned expressions
+   |
+LL ~         true => Box::new(B),
+LL ~         false => Box::new(C),
+   |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.