about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/expect_fun_call.fixed27
-rw-r--r--tests/ui/expect_fun_call.rs17
-rw-r--r--tests/ui/expect_fun_call.stderr28
3 files changed, 53 insertions, 19 deletions
diff --git a/tests/ui/expect_fun_call.fixed b/tests/ui/expect_fun_call.fixed
index 73eaebf773c..0d815ace7b3 100644
--- a/tests/ui/expect_fun_call.fixed
+++ b/tests/ui/expect_fun_call.fixed
@@ -90,17 +90,23 @@ fn main() {
             "foo"
         }
 
-        Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
+        const fn const_evaluable() -> &'static str {
+            "foo"
+        }
+
+        Some("foo").unwrap_or_else(|| panic!("{}", get_string()));
         //~^ expect_fun_call
-        Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
+        Some("foo").unwrap_or_else(|| panic!("{}", get_string()));
         //~^ expect_fun_call
-        Some("foo").unwrap_or_else(|| { panic!("{}", get_string()) });
+        Some("foo").unwrap_or_else(|| panic!("{}", get_string()));
         //~^ expect_fun_call
 
-        Some("foo").unwrap_or_else(|| { panic!("{}", get_static_str()) });
+        Some("foo").unwrap_or_else(|| panic!("{}", get_static_str()));
         //~^ expect_fun_call
-        Some("foo").unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) });
+        Some("foo").unwrap_or_else(|| panic!("{}", get_non_static_str(&0)));
         //~^ expect_fun_call
+
+        Some("foo").expect(const_evaluable());
     }
 
     //Issue #3839
@@ -122,4 +128,15 @@ fn main() {
     let format_capture_and_value: Option<i32> = None;
     format_capture_and_value.unwrap_or_else(|| panic!("{error_code}, {}", 1));
     //~^ expect_fun_call
+
+    // Issue #15056
+    let a = false;
+    Some(5).expect(if a { "a" } else { "b" });
+
+    let return_in_expect: Option<i32> = None;
+    return_in_expect.expect(if true {
+        "Error"
+    } else {
+        return;
+    });
 }
diff --git a/tests/ui/expect_fun_call.rs b/tests/ui/expect_fun_call.rs
index ecebc9ebfb6..160bbe64c65 100644
--- a/tests/ui/expect_fun_call.rs
+++ b/tests/ui/expect_fun_call.rs
@@ -90,6 +90,10 @@ fn main() {
             "foo"
         }
 
+        const fn const_evaluable() -> &'static str {
+            "foo"
+        }
+
         Some("foo").expect(&get_string());
         //~^ expect_fun_call
         Some("foo").expect(get_string().as_ref());
@@ -101,6 +105,8 @@ fn main() {
         //~^ expect_fun_call
         Some("foo").expect(get_non_static_str(&0));
         //~^ expect_fun_call
+
+        Some("foo").expect(const_evaluable());
     }
 
     //Issue #3839
@@ -122,4 +128,15 @@ fn main() {
     let format_capture_and_value: Option<i32> = None;
     format_capture_and_value.expect(&format!("{error_code}, {}", 1));
     //~^ expect_fun_call
+
+    // Issue #15056
+    let a = false;
+    Some(5).expect(if a { "a" } else { "b" });
+
+    let return_in_expect: Option<i32> = None;
+    return_in_expect.expect(if true {
+        "Error"
+    } else {
+        return;
+    });
 }
diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr
index 36713196cb9..7988e8fc238 100644
--- a/tests/ui/expect_fun_call.stderr
+++ b/tests/ui/expect_fun_call.stderr
@@ -38,55 +38,55 @@ LL |     Some("foo").expect(format!("{} {}", 1, 2).as_ref());
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{} {}", 1, 2))`
 
 error: function call inside of `expect`
-  --> tests/ui/expect_fun_call.rs:93:21
+  --> tests/ui/expect_fun_call.rs:97:21
    |
 LL |         Some("foo").expect(&get_string());
-   |                     ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })`
+   |                     ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{}", get_string()))`
 
 error: function call inside of `expect`
-  --> tests/ui/expect_fun_call.rs:95:21
+  --> tests/ui/expect_fun_call.rs:99:21
    |
 LL |         Some("foo").expect(get_string().as_ref());
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })`
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{}", get_string()))`
 
 error: function call inside of `expect`
-  --> tests/ui/expect_fun_call.rs:97:21
+  --> tests/ui/expect_fun_call.rs:101:21
    |
 LL |         Some("foo").expect(get_string().as_str());
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_string()) })`
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{}", get_string()))`
 
 error: function call inside of `expect`
-  --> tests/ui/expect_fun_call.rs:100:21
+  --> tests/ui/expect_fun_call.rs:104:21
    |
 LL |         Some("foo").expect(get_static_str());
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_static_str()) })`
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{}", get_static_str()))`
 
 error: function call inside of `expect`
-  --> tests/ui/expect_fun_call.rs:102:21
+  --> tests/ui/expect_fun_call.rs:106:21
    |
 LL |         Some("foo").expect(get_non_static_str(&0));
-   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })`
+   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{}", get_non_static_str(&0)))`
 
 error: function call inside of `expect`
-  --> tests/ui/expect_fun_call.rs:107:16
+  --> tests/ui/expect_fun_call.rs:113:16
    |
 LL |     Some(true).expect(&format!("key {}, {}", 1, 2));
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))`
 
 error: function call inside of `expect`
-  --> tests/ui/expect_fun_call.rs:114:17
+  --> tests/ui/expect_fun_call.rs:120:17
    |
 LL |         opt_ref.expect(&format!("{:?}", opt_ref));
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{:?}", opt_ref))`
 
 error: function call inside of `expect`
-  --> tests/ui/expect_fun_call.rs:119:20
+  --> tests/ui/expect_fun_call.rs:125:20
    |
 LL |     format_capture.expect(&format!("{error_code}"));
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}"))`
 
 error: function call inside of `expect`
-  --> tests/ui/expect_fun_call.rs:123:30
+  --> tests/ui/expect_fun_call.rs:129:30
    |
 LL |     format_capture_and_value.expect(&format!("{error_code}, {}", 1));
    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| panic!("{error_code}, {}", 1))`