New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing unused_must_use warning for macro calls #55240

snoyberg opened this Issue Oct 21, 2018 · 0 comments


None yet
2 participants

snoyberg commented Oct 21, 2018

This code is pretty close to my original code:

use std::fmt::{Formatter, Display, self};

struct Foo;

impl Display for Foo {
    fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
        write!(fmt, "ignored result\n");

        let mut closure = || {
            write!(fmt, "not ignoring result\n")

        closure(); // also ignoring here


fn main() {
    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")) as Result<(), String>)

fn err_function() -> Result<(), String> {
    Err(String::from("error from function"))

fn main() {

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
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.


$ rustc --version --verbose
rustc 1.31.0-nightly (96cafc53c 2018-10-09)
binary: rustc
commit-hash: 96cafc53cfc6667a03c8e77d8e0a2fc96555ff6b
commit-date: 2018-10-09
host: x86_64-apple-darwin
release: 1.31.0-nightly
LLVM version: 8.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment