about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/mismatched_types/transforming-option-ref-issue-127545.rs12
-rw-r--r--tests/ui/mismatched_types/transforming-option-ref-issue-127545.stderr74
2 files changed, 85 insertions, 1 deletions
diff --git a/tests/ui/mismatched_types/transforming-option-ref-issue-127545.rs b/tests/ui/mismatched_types/transforming-option-ref-issue-127545.rs
index 5ba58e74275..f589e88f68e 100644
--- a/tests/ui/mismatched_types/transforming-option-ref-issue-127545.rs
+++ b/tests/ui/mismatched_types/transforming-option-ref-issue-127545.rs
@@ -4,3 +4,15 @@
 pub fn foo(arg: Option<&Vec<i32>>) -> Option<&[i32]> {
     arg //~ ERROR 5:5: 5:8: mismatched types [E0308]
 }
+
+pub fn bar(arg: Option<&Vec<i32>>) -> &[i32] {
+    arg.unwrap_or(&[]) //~ ERROR 9:19: 9:22: mismatched types [E0308]
+}
+
+pub fn barzz<'a>(arg: Option<&'a Vec<i32>>, v: &'a [i32]) -> &'a [i32] {
+    arg.unwrap_or(v) //~ ERROR 13:19: 13:20: mismatched types [E0308]
+}
+
+pub fn convert_result(arg: Result<&Vec<i32>, ()>) -> &[i32] {
+    arg.unwrap_or(&[]) //~ ERROR 17:19: 17:22: mismatched types [E0308]
+}
diff --git a/tests/ui/mismatched_types/transforming-option-ref-issue-127545.stderr b/tests/ui/mismatched_types/transforming-option-ref-issue-127545.stderr
index b7c7202113a..ad423f86ef9 100644
--- a/tests/ui/mismatched_types/transforming-option-ref-issue-127545.stderr
+++ b/tests/ui/mismatched_types/transforming-option-ref-issue-127545.stderr
@@ -13,6 +13,78 @@ help: try using `.map(|v| &**v)` to convert `Option<&Vec<i32>>` to `Option<&[i32
 LL |     arg.map(|v| &**v)
    |        ++++++++++++++
 
-error: aborting due to 1 previous error
+error[E0308]: mismatched types
+  --> $DIR/transforming-option-ref-issue-127545.rs:9:19
+   |
+LL |     arg.unwrap_or(&[])
+   |         --------- ^^^ expected `&Vec<i32>`, found `&[_; 0]`
+   |         |
+   |         arguments to this method are incorrect
+   |
+   = note: expected reference `&Vec<i32>`
+              found reference `&[_; 0]`
+help: the return type of this call is `&[_; 0]` due to the type of the argument passed
+  --> $DIR/transforming-option-ref-issue-127545.rs:9:5
+   |
+LL |     arg.unwrap_or(&[])
+   |     ^^^^^^^^^^^^^^---^
+   |                   |
+   |                   this argument influences the return type of `unwrap_or`
+note: method defined here
+  --> $SRC_DIR/core/src/option.rs:LL:COL
+help: use `Option::map_or` to deref inner value of `Option`
+   |
+LL |     arg.map_or(&[], |v| v)
+   |         ~~~~~~    +++++++
+
+error[E0308]: mismatched types
+  --> $DIR/transforming-option-ref-issue-127545.rs:13:19
+   |
+LL |     arg.unwrap_or(v)
+   |         --------- ^ expected `&Vec<i32>`, found `&[i32]`
+   |         |
+   |         arguments to this method are incorrect
+   |
+   = note: expected reference `&Vec<i32>`
+              found reference `&'a [i32]`
+help: the return type of this call is `&'a [i32]` due to the type of the argument passed
+  --> $DIR/transforming-option-ref-issue-127545.rs:13:5
+   |
+LL |     arg.unwrap_or(v)
+   |     ^^^^^^^^^^^^^^-^
+   |                   |
+   |                   this argument influences the return type of `unwrap_or`
+note: method defined here
+  --> $SRC_DIR/core/src/option.rs:LL:COL
+help: use `Option::map_or` to deref inner value of `Option`
+   |
+LL |     arg.map_or(v, |v| v)
+   |         ~~~~~~  +++++++
+
+error[E0308]: mismatched types
+  --> $DIR/transforming-option-ref-issue-127545.rs:17:19
+   |
+LL |     arg.unwrap_or(&[])
+   |         --------- ^^^ expected `&Vec<i32>`, found `&[_; 0]`
+   |         |
+   |         arguments to this method are incorrect
+   |
+   = note: expected reference `&Vec<i32>`
+              found reference `&[_; 0]`
+help: the return type of this call is `&[_; 0]` due to the type of the argument passed
+  --> $DIR/transforming-option-ref-issue-127545.rs:17:5
+   |
+LL |     arg.unwrap_or(&[])
+   |     ^^^^^^^^^^^^^^---^
+   |                   |
+   |                   this argument influences the return type of `unwrap_or`
+note: method defined here
+  --> $SRC_DIR/core/src/result.rs:LL:COL
+help: use `Result::map_or` to deref inner value of `Result`
+   |
+LL |     arg.map_or(&[], |v| v)
+   |         ~~~~~~    +++++++
+
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0308`.