54
54
#[ macro_export]
55
55
macro_rules! bail {
56
56
( $msg: literal $( , ) ?) => {
57
- return $crate:: private:: Err ( $crate:: anyhow !( $msg) )
57
+ return $crate:: private:: Err ( $crate:: __anyhow !( $msg) )
58
58
} ;
59
59
( $err: expr $( , ) ?) => {
60
- return $crate:: private:: Err ( $crate:: anyhow !( $err) )
60
+ return $crate:: private:: Err ( $crate:: __anyhow !( $err) )
61
61
} ;
62
62
( $fmt: expr, $( $arg: tt) * ) => {
63
- return $crate:: private:: Err ( $crate:: anyhow !( $fmt, $( $arg) * ) )
63
+ return $crate:: private:: Err ( $crate:: __anyhow !( $fmt, $( $arg) * ) )
64
64
} ;
65
65
}
66
66
@@ -75,13 +75,13 @@ macro_rules! bail {
75
75
return $crate:: private:: Err ( $crate:: Error :: msg( "pattern does not contain `{}`" ) )
76
76
} ;
77
77
( $msg: literal $( , ) ?) => {
78
- return $crate:: private:: Err ( $crate:: anyhow !( $msg) )
78
+ return $crate:: private:: Err ( $crate:: __anyhow !( $msg) )
79
79
} ;
80
80
( $err: expr $( , ) ?) => {
81
- return $crate:: private:: Err ( $crate:: anyhow !( $err) )
81
+ return $crate:: private:: Err ( $crate:: __anyhow !( $err) )
82
82
} ;
83
83
( $fmt: expr, $( $arg: tt) * ) => {
84
- return $crate:: private:: Err ( $crate:: anyhow !( $fmt, $( $arg) * ) )
84
+ return $crate:: private:: Err ( $crate:: __anyhow !( $fmt, $( $arg) * ) )
85
85
} ;
86
86
}
87
87
@@ -145,17 +145,17 @@ macro_rules! ensure {
145
145
} ;
146
146
( $cond: expr, $msg: literal $( , ) ?) => {
147
147
if !$cond {
148
- return $crate:: private:: Err ( $crate:: anyhow !( $msg) ) ;
148
+ return $crate:: private:: Err ( $crate:: __anyhow !( $msg) ) ;
149
149
}
150
150
} ;
151
151
( $cond: expr, $err: expr $( , ) ?) => {
152
152
if !$cond {
153
- return $crate:: private:: Err ( $crate:: anyhow !( $err) ) ;
153
+ return $crate:: private:: Err ( $crate:: __anyhow !( $err) ) ;
154
154
}
155
155
} ;
156
156
( $cond: expr, $fmt: expr, $( $arg: tt) * ) => {
157
157
if !$cond {
158
- return $crate:: private:: Err ( $crate:: anyhow !( $fmt, $( $arg) * ) ) ;
158
+ return $crate:: private:: Err ( $crate:: __anyhow !( $fmt, $( $arg) * ) ) ;
159
159
}
160
160
} ;
161
161
}
@@ -225,3 +225,25 @@ macro_rules! anyhow {
225
225
$crate:: Error :: msg( $crate:: private:: format!( $fmt, $( $arg) * ) )
226
226
} ;
227
227
}
228
+
229
+ // Not public API. This is used in the implementation of some of the other
230
+ // macros, in which the must_use call is not needed because the value is known
231
+ // to be used.
232
+ #[ doc( hidden) ]
233
+ #[ macro_export]
234
+ macro_rules! __anyhow {
235
+ ( $msg: literal $( , ) ?) => ( {
236
+ let error = $crate:: private:: format_err( $crate:: private:: format_args!( $msg) ) ;
237
+ error
238
+ } ) ;
239
+ ( $err: expr $( , ) ?) => ( {
240
+ use $crate:: private:: kind:: * ;
241
+ let error = match $err {
242
+ error => ( & error) . anyhow_kind( ) . new( error) ,
243
+ } ;
244
+ error
245
+ } ) ;
246
+ ( $fmt: expr, $( $arg: tt) * ) => {
247
+ $crate:: Error :: msg( $crate:: private:: format!( $fmt, $( $arg) * ) )
248
+ } ;
249
+ }
0 commit comments