Description
I want to write a macro wrapping something marked #![must_use]
which doesn't spam the build output with "unused_must_use", but also doesn't destroy the result. I don't want to unwrap these values either, nor mark every single invocation with #![allow(unused_must_use)]
, nor allow unused_must_see
for the entire program (because with this macro's one exception, it is useful): I simply want to strip this return value's compiler-spamming must_use
.
This:
macro_rules! println_out(
($($arg:tt)*) => ( {let _ = writeln!(&mut ::std::io::stdout(), $($arg)* )} )
);
doesn't work because the result is unavailable if I need to check it, which I do on occasion.
Even this: fails to work:
macro_rules! println_err(
($($arg:tt)*) => ( {
let _x = writeln!(&mut ::std::io::stderr(), $($arg)* );
_x.is_ok();
_x
} )
);
because the final line can be unused in the calling context
stdout
/stderr
/write_ln!
are used as examples here, but I need to do this generically with certain things that spam must_use
.
This isn't an unsafety issue. I simply shouldn't have to be bound ubiquitously by the particular compiler-warning policy preached by a module's author. I may (and do) have valid cases where must_use
is semantically wrong.
It should not be impossible to do this.