about summary refs log tree commit diff
path: root/tests/ui/try-trait
diff options
context:
space:
mode:
authorKivooeo <Kivooeo123@gmail.com>2025-07-01 21:46:28 +0500
committerKivooeo <Kivooeo123@gmail.com>2025-07-10 18:47:20 +0500
commit3ad95cccf9b3af7e527869a1eb130217971b7a57 (patch)
tree9cbd3351ca4945ebab10f7eea36eac6224473dcc /tests/ui/try-trait
parente9191ec57ee5bdd0961a22fd9852f361a5c97ea0 (diff)
downloadrust-3ad95cccf9b3af7e527869a1eb130217971b7a57.tar.gz
rust-3ad95cccf9b3af7e527869a1eb130217971b7a57.zip
cleaned up some tests
Diffstat (limited to 'tests/ui/try-trait')
-rw-r--r--tests/ui/try-trait/try-operator-expansion-hygiene.rs16
-rw-r--r--tests/ui/try-trait/try-operator-various-contexts.rs35
2 files changed, 26 insertions, 25 deletions
diff --git a/tests/ui/try-trait/try-operator-expansion-hygiene.rs b/tests/ui/try-trait/try-operator-expansion-hygiene.rs
index 20538e094c6..b6f4e533d8d 100644
--- a/tests/ui/try-trait/try-operator-expansion-hygiene.rs
+++ b/tests/ui/try-trait/try-operator-expansion-hygiene.rs
@@ -1,16 +1,14 @@
+//! This test verifies that the `?` operator expansion is hygienic,
+//! i.e., it's not affected by other `val` and `err` bindings that may be in scope.
+//!
+//! Note: Prior to the Try trait stabilization, `expr?` expanded to a match
+//! with `val` and `err` bindings. The current implementation uses Try::branch()
+//! but this test remains relevant for hygiene verification.
+
 //@ run-pass
 
 #![allow(non_upper_case_globals)]
 #![allow(dead_code)]
-// `expr?` expands to:
-//
-// match expr {
-//     Ok(val) => val,
-//     Err(err) => return Err(From::from(err)),
-// }
-//
-// This test verifies that the expansion is hygienic, i.e., it's not affected by other `val` and
-// `err` bindings that may be in scope.
 
 use std::num::ParseIntError;
 
diff --git a/tests/ui/try-trait/try-operator-various-contexts.rs b/tests/ui/try-trait/try-operator-various-contexts.rs
index b9978204557..41c3679c96f 100644
--- a/tests/ui/try-trait/try-operator-various-contexts.rs
+++ b/tests/ui/try-trait/try-operator-various-contexts.rs
@@ -1,9 +1,11 @@
+//! Checks the functionality of the `?` operator in various syntactic contexts.
+
 //@ run-pass
 
 #![allow(dead_code)]
 
 use std::fs::File;
-use std::io::{Read, self};
+use std::io::{self, Read};
 use std::num::ParseIntError;
 use std::str::FromStr;
 
@@ -35,7 +37,9 @@ fn on_path() -> Result<i32, ParseIntError> {
 
 fn on_macro() -> Result<i32, ParseIntError> {
     macro_rules! id {
-        ($e:expr) => { $e }
+        ($e:expr) => {
+            $e
+        };
     }
 
     Ok(id!("7".parse::<i32>())?)
@@ -50,11 +54,14 @@ fn on_parens() -> Result<i32, ParseIntError> {
 fn on_block() -> Result<i32, ParseIntError> {
     let x = "9".parse::<i32>();
 
-    Ok({x}?)
+    Ok({ x }?)
 }
 
 fn on_field() -> Result<i32, ParseIntError> {
-    struct Pair<A, B> { a: A, b: B }
+    struct Pair<A, B> {
+        a: A,
+        b: B,
+    }
 
     let x = Pair { a: "10".parse::<i32>(), b: 0 };
 
@@ -89,7 +96,9 @@ fn on_index() -> Result<i32, ParseIntError> {
 }
 
 fn on_args() -> Result<i32, ParseIntError> {
-    fn sub(x: i32, y: i32) -> i32 { x - y }
+    fn sub(x: i32, y: i32) -> i32 {
+        x - y
+    }
 
     let x = "20".parse();
     let y = "21".parse();
@@ -98,19 +107,11 @@ fn on_args() -> Result<i32, ParseIntError> {
 }
 
 fn on_if() -> Result<i32, ParseIntError> {
-    Ok(if true {
-        "22".parse::<i32>()
-    } else {
-        "23".parse::<i32>()
-    }?)
+    Ok(if true { "22".parse::<i32>() } else { "23".parse::<i32>() }?)
 }
 
 fn on_if_let() -> Result<i32, ParseIntError> {
-    Ok(if let Ok(..) = "24".parse::<i32>() {
-        "25".parse::<i32>()
-    } else {
-        "26".parse::<i32>()
-    }?)
+    Ok(if let Ok(..) = "24".parse::<i32>() { "25".parse::<i32>() } else { "26".parse::<i32>() }?)
 }
 
 fn on_match() -> Result<i32, ParseIntError> {
@@ -121,7 +122,9 @@ fn on_match() -> Result<i32, ParseIntError> {
 }
 
 fn tight_binding() -> Result<bool, ()> {
-    fn ok<T>(x: T) -> Result<T, ()> { Ok(x) }
+    fn ok<T>(x: T) -> Result<T, ()> {
+        Ok(x)
+    }
 
     let x = ok(true);
     Ok(!x?)