about summary refs log tree commit diff
path: root/tests/ui/sized
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-03-06 23:41:50 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-03-19 20:56:45 +0000
commit3f2159fda5019f5b599dd3cdf53f430878e82ed2 (patch)
tree449414376a23c4026ec995abfd1c8e1796611add /tests/ui/sized
parent3cdcdaf31b45f8045164aae9604573d23091970b (diff)
downloadrust-3f2159fda5019f5b599dd3cdf53f430878e82ed2.tar.gz
rust-3f2159fda5019f5b599dd3cdf53f430878e82ed2.zip
Add test for #117846
Diffstat (limited to 'tests/ui/sized')
-rw-r--r--tests/ui/sized/expr-type-error-plus-sized-obligation.rs22
-rw-r--r--tests/ui/sized/expr-type-error-plus-sized-obligation.stderr30
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/ui/sized/expr-type-error-plus-sized-obligation.rs b/tests/ui/sized/expr-type-error-plus-sized-obligation.rs
new file mode 100644
index 00000000000..4c76d2d2488
--- /dev/null
+++ b/tests/ui/sized/expr-type-error-plus-sized-obligation.rs
@@ -0,0 +1,22 @@
+#![allow(warnings)]
+
+fn issue_117846_repro() {
+    let (a, _) = if true { //~ ERROR E0277
+        produce()
+    } else {
+        (Vec::new(), &[]) //~ ERROR E0308
+    };
+
+    accept(&a);
+}
+
+struct Foo;
+struct Bar;
+
+fn produce() -> (Vec<Foo>, &'static [Bar]) {
+    todo!()
+}
+
+fn accept(c: &[Foo]) {}
+
+fn main() {}
diff --git a/tests/ui/sized/expr-type-error-plus-sized-obligation.stderr b/tests/ui/sized/expr-type-error-plus-sized-obligation.stderr
new file mode 100644
index 00000000000..6a2810be107
--- /dev/null
+++ b/tests/ui/sized/expr-type-error-plus-sized-obligation.stderr
@@ -0,0 +1,30 @@
+error[E0308]: `if` and `else` have incompatible types
+  --> $DIR/expr-type-error-plus-sized-obligation.rs:7:9
+   |
+LL |       let (a, _) = if true {
+   |  __________________-
+LL | |         produce()
+   | |         --------- expected because of this
+LL | |     } else {
+LL | |         (Vec::new(), &[])
+   | |         ^^^^^^^^^^^^^^^^^ expected `(Vec<Foo>, &[Bar])`, found `(Vec<_>, &[_; 0])`
+LL | |     };
+   | |_____- `if` and `else` have incompatible types
+   |
+   = note: expected tuple `(Vec<Foo>, &[Bar])`
+              found tuple `(Vec<_>, &[_; 0])`
+
+error[E0277]: the size for values of type `[Foo]` cannot be known at compilation time
+  --> $DIR/expr-type-error-plus-sized-obligation.rs:4:10
+   |
+LL |     let (a, _) = if true {
+   |          ^ doesn't have a size known at compile-time
+   |
+   = help: the trait `Sized` is not implemented for `[Foo]`
+   = note: all local variables must have a statically known size
+   = help: unsized locals are gated as an unstable feature
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0277, E0308.
+For more information about an error, try `rustc --explain E0277`.