You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::fmt::{Formatter,Display,self};structFoo;implDisplayforFoo{fnfmt(&self,fmt:&mutFormatter) -> fmt::Result{write!(fmt, "ignored result\n");letmut closure = || {write!(fmt, "not ignoring result\n")};closure();// also ignoring hereOk(())}}fnmain(){println!("{}", Foo);}
Expected: a warning on the first write! call and the call to closure about an ignored Result value.
Actual: I get the warning on the closure call, but not on the first write! call.
My best guess is that for some reason Results returned from a macro do not trigger this warning, so I came up with a smaller attempted repro. However, this shows a slightly different result:
macro_rules! err_macro {() => (Err(String::from("error from macro"))asResult<(), String>)}fnerr_function() -> Result<(),String>{Err(String::from("error from function"))}fnmain(){err_function();err_macro!();}
As expected, I get a warning on the call to err_function(). I also get a warning for the macro call, in both the definition and use locations:
warning: unused `std::result::Result` which must be used
--> where-da-warning-2.rs:2:12
|
2 | () => (Err(String::from("error from macro")) as Result<(), String>)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
11 | err_macro!();
| ------------- in this macro invocation
|
= note: this `Result` may be an `Err` variant, which should be handled
Perhaps the reason the write! macro doesn't generate a warning is because the its a macro being pulled in from a different library, not being defined locally.
This issue seems to have been fixed as I'm getting proper warning on your above code:
warning: unused `std::result::Result` that must be used
--> /home/sibi/foo.rs:7:9
|
7 | write!(fmt, "ignored result\n");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_must_use)]` on by default
= note: this `Result` may be an `Err` variant, which should be handled
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
warning: unused `std::result::Result` that must be used
--> /home/sibi/foo.rs:11:9
|
11 | closure(); // also ignoring here
| ^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled
This code is pretty close to my original code:
Expected: a warning on the first
write!
call and the call toclosure
about an ignoredResult
value.Actual: I get the warning on the
closure
call, but not on the firstwrite!
call.My best guess is that for some reason
Result
s returned from a macro do not trigger this warning, so I came up with a smaller attempted repro. However, this shows a slightly different result:As expected, I get a warning on the call to
err_function()
. I also get a warning for the macro call, in both the definition and use locations:Perhaps the reason the
write!
macro doesn't generate a warning is because the its a macro being pulled in from a different library, not being defined locally.Meta
The text was updated successfully, but these errors were encountered: