Skip to content

Commit 74947e7

Browse files
committed
Rename try_ to try_fn
1 parent 063249a commit 74947e7

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

macros/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn throws(args: TokenStream, input: TokenStream) -> TokenStream {
1515
}
1616

1717
#[proc_macro_attribute]
18-
pub fn try_(args: TokenStream, input: TokenStream) -> TokenStream {
19-
assert!(args.to_string() == "", "try does not take arguments");
18+
pub fn try_fn(args: TokenStream, input: TokenStream) -> TokenStream {
19+
assert!(args.to_string() == "", "try_fn does not take arguments");
2020
Throws::new(None).fold(input)
2121
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub use culpa_macros::throws;
9898
/// Annotates a function that implicitly wraps a try block.
9999
///
100100
/// See the main crate docs for more details.
101-
pub use culpa_macros::try_;
101+
pub use culpa_macros::try_fn;
102102

103103
/// Throw an error.
104104
///

tests/try.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
use culpa::{throw, try_};
1+
use culpa::{throw, try_fn};
22

33
type Error = isize;
44

5-
#[try_]
5+
#[try_fn]
66
pub fn unit_fn() -> Result<(), Error> {}
77

8-
#[try_]
8+
#[try_fn]
99
pub fn returns_fn() -> Result<i32, Error> {
1010
return 0;
1111
}
1212

13-
#[try_]
13+
#[try_fn]
1414
pub fn returns_unit_fn() -> Result<(), Error> {
1515
if true {
1616
return;
1717
}
1818
}
1919

20-
#[try_]
20+
#[try_fn]
2121
pub fn tail_returns_value() -> Result<i32, Error> {
2222
0
2323
}
2424

25-
#[try_]
25+
#[try_fn]
2626
pub async fn async_fn() -> Result<(), Error> {}
2727

28-
#[try_]
28+
#[try_fn]
2929
pub async fn async_fn_with_ret() -> Result<i32, Error> {
3030
0
3131
}
3232

33-
#[try_]
33+
#[try_fn]
3434
pub fn throws_error() -> Result<(), i32> {
3535
if true {
3636
throw!(0);
3737
}
3838
}
3939

40-
#[try_]
40+
#[try_fn]
4141
pub fn throws_and_has_return_type() -> Result<&'static str, i32> {
4242
if true {
4343
return "success";
@@ -47,16 +47,16 @@ pub fn throws_and_has_return_type() -> Result<&'static str, i32> {
4747
"okay"
4848
}
4949

50-
#[try_]
50+
#[try_fn]
5151
pub fn throws_generics<E>() -> Result<(), E> {}
5252

5353
pub struct Foo;
5454

5555
impl Foo {
56-
#[try_]
56+
#[try_fn]
5757
pub fn static_method() -> Result<(), Error> {}
5858

59-
#[try_]
59+
#[try_fn]
6060
pub fn bar(&self) -> Result<i32, Error> {
6161
if true {
6262
return 1;
@@ -65,88 +65,88 @@ impl Foo {
6565
}
6666
}
6767

68-
#[try_]
68+
#[try_fn]
6969
pub fn has_inner_fn() -> Result<(), Error> {
7070
fn inner_fn() -> i32 {
7171
0
7272
}
7373
let _: i32 = inner_fn();
7474
}
7575

76-
#[try_]
76+
#[try_fn]
7777
pub fn has_inner_closure() -> Result<(), Error> {
7878
let f = || 0;
7979
let _: i32 = f();
8080
}
8181

82-
#[try_]
82+
#[try_fn]
8383
pub async fn has_inner_async_block() -> Result<(), Error> {
8484
let f = async { 0 };
8585
let _: i32 = f.await;
8686
}
8787

88-
#[try_]
88+
#[try_fn]
8989
pub fn throws_as_result() -> Result<i32, Error> {
9090
0
9191
}
9292

93-
#[try_]
93+
#[try_fn]
9494
pub fn throws_as_result_alias() -> std::io::Result<i32> {
9595
0
9696
}
9797

98-
#[try_]
98+
#[try_fn]
9999
pub fn ommitted_error() -> Result<(), Error> {}
100100

101101
pub mod foo {
102-
use culpa::{throw, try_};
102+
use culpa::{throw, try_fn};
103103

104104
pub type Error = i32;
105105

106-
#[try_]
106+
#[try_fn]
107107
pub fn throws_integer() -> Result<(), i32> {
108108
throw!(0);
109109
}
110110
}
111111

112112
pub mod foo_trait_obj {
113-
use culpa::try_;
113+
use culpa::try_fn;
114114
pub trait FooTrait {}
115115

116116
struct FooStruct;
117117

118118
pub struct FooError;
119119
impl FooTrait for FooStruct {}
120120

121-
#[try_]
121+
#[try_fn]
122122
pub fn foo() -> Result<Box<dyn FooTrait>, FooError> {
123123
Box::new(FooStruct)
124124
}
125125
}
126126

127-
#[try_]
127+
#[try_fn]
128128
pub fn let_else(a: Option<u8>) -> Result<u8, Error> {
129129
let Some(a) = a else {
130130
return 0;
131131
};
132132
a
133133
}
134134

135-
#[try_]
135+
#[try_fn]
136136
pub fn impl_trait() -> Result<impl std::fmt::Debug, Error> {}
137137

138-
#[try_]
138+
#[try_fn]
139139
#[deny(unreachable_code)]
140140
pub fn unreachable() -> Result<(), i32> {
141141
todo!()
142142
}
143143

144144
trait Example {
145-
#[try_]
145+
#[try_fn]
146146
fn foo() -> Result<i32, Error>;
147147
}
148148

149-
#[try_]
149+
#[try_fn]
150150
fn as_option(x: bool) -> Option<i32> {
151151
if x {
152152
throw!();

0 commit comments

Comments
 (0)