fix compiler warning

Fix issue [link](https://github.com/rust-lang/rust/issues/79813) which
will eventually deny trailing semicolons in expression macro in rust compiler.
This commit is contained in:
Dean Li 2021-08-07 16:31:54 +08:00
parent 10cbba02d9
commit 1086fdb965
No known key found for this signature in database
GPG Key ID: 4F55BB69D480672A
5 changed files with 8 additions and 8 deletions

View File

@ -2,8 +2,8 @@
#[macro_export] #[macro_export]
#[doc(hidden)] #[doc(hidden)]
macro_rules! bail { macro_rules! bail {
($msg: expr) => { return Err($msg.into()); }; ($msg: expr) => { return Err($msg.into()) };
($fmt: literal $($args: tt)+) => { return Err(format!($fmt $($args)+).into()); }; ($fmt: literal $($args: tt)+) => { return Err(format!($fmt $($args)+).into()) };
} }
/// A simple macro for checking a condition. Resembles anyhow::ensure. /// A simple macro for checking a condition. Resembles anyhow::ensure.
@ -18,7 +18,7 @@ macro_rules! ensure {
#[doc(hidden)] #[doc(hidden)]
macro_rules! warn { macro_rules! warn {
($msg: literal) => { ($msg: literal) => {
println!(concat!("cargo:warning=", $msg)); println!(concat!("cargo:warning=", $msg))
}; };
} }

View File

@ -75,7 +75,7 @@ impl InterpreterConfig {
warn!( warn!(
"PyPy does not yet support abi3 so the build artifacts will be version-specific. \ "PyPy does not yet support abi3 so the build artifacts will be version-specific. \
See https://foss.heptapod.net/pypy/pypy/-/issues/3397 for more information." See https://foss.heptapod.net/pypy/pypy/-/issues/3397 for more information."
) );
} }
}; };

View File

@ -84,7 +84,7 @@ impl PyClassArgs {
expected!($expected, right.span()) expected!($expected, right.span())
}; };
($expected: literal, $span: expr) => { ($expected: literal, $span: expr) => {
bail_spanned!($span => concat!("expected ", $expected)); bail_spanned!($span => concat!("expected ", $expected))
}; };
} }

View File

@ -81,7 +81,7 @@ pub fn check_generic(sig: &syn::Signature) -> syn::Result<()> {
fn ensure_function_options_valid(options: &PyFunctionOptions) -> syn::Result<()> { fn ensure_function_options_valid(options: &PyFunctionOptions) -> syn::Result<()> {
if let Some(pass_module) = &options.pass_module { if let Some(pass_module) = &options.pass_module {
bail_spanned!(pass_module.span() => "`pass_module` cannot be used on Python methods") bail_spanned!(pass_module.span() => "`pass_module` cannot be used on Python methods");
} }
Ok(()) Ok(())
} }
@ -334,7 +334,7 @@ impl PropertyType<'_> {
(Some(name), _) => name.0.to_string(), (Some(name), _) => name.0.to_string(),
(None, Some(field_name)) => format!("{}\0", field_name.unraw()), (None, Some(field_name)) => format!("{}\0", field_name.unraw()),
(None, None) => { (None, None) => {
bail_spanned!(field.span() => "`get` and `set` with tuple struct fields require `name`") bail_spanned!(field.span() => "`get` and `set` with tuple struct fields require `name`");
} }
}; };
Ok(syn::LitStr::new(&name, field.span())) Ok(syn::LitStr::new(&name, field.span()))

View File

@ -14,7 +14,7 @@ macro_rules! err_spanned {
/// Macro inspired by `anyhow::bail!` to return a compiler error with the given span. /// Macro inspired by `anyhow::bail!` to return a compiler error with the given span.
macro_rules! bail_spanned { macro_rules! bail_spanned {
($span:expr => $msg:expr) => { ($span:expr => $msg:expr) => {
return Err(err_spanned!($span => $msg)); return Err(err_spanned!($span => $msg))
}; };
} }