Skip to content

Commit 378180a

Browse files
committed
glib: Allow variable expansion in format strings passed to bool_error
1 parent d1fdc2e commit 378180a

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

glib/src/error.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,26 @@ pub trait ErrorDomain: Copy {
152152
/// Generic error used for functions that fail without any further information
153153
#[macro_export]
154154
macro_rules! bool_error(
155-
// Plain strings
156-
($msg:expr) => {{
157-
$crate::BoolError::new(
158-
$msg,
159-
file!(),
160-
$crate::function_name!(),
161-
line!(),
162-
)
163-
}};
164-
165-
// Format strings
166155
($($msg:tt)*) => {{
167-
$crate::BoolError::new(
168-
format!($($msg)*),
169-
file!(),
170-
$crate::function_name!(),
171-
line!(),
172-
)
156+
match ::std::format_args!($($msg)*) {
157+
formatted => {
158+
if let Some(s) = formatted.as_str() {
159+
$crate::BoolError::new(
160+
s,
161+
file!(),
162+
$crate::function_name!(),
163+
line!()
164+
)
165+
} else {
166+
$crate::BoolError::new(
167+
formatted.to_string(),
168+
file!(),
169+
$crate::function_name!(),
170+
line!(),
171+
)
172+
}
173+
}
174+
}
173175
}};
174176
);
175177

0 commit comments

Comments
 (0)