Skip to content
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

write! is somehow masking the #[must_use] on its result #55516

Closed
pnkfelix opened this issue Oct 30, 2018 · 6 comments
Closed

write! is somehow masking the #[must_use] on its result #55516

pnkfelix opened this issue Oct 30, 2018 · 6 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another.

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Oct 30, 2018

Hat tip to @shepmaster for finding this

play

fn main() {
    use std::fmt::Write;
    let mut example = String::new();
    write!(&mut example, "{}", 42);
}

is not triggering the #[must_use] lint on Result.

@pnkfelix pnkfelix added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Oct 30, 2018
@shepmaster
Copy link
Member

This code compiles with warnings in Rust 1.28.0, but no warnings in Rust 1.29.0

fn main() {
    use std::fmt::Write;
    let mut example = String::new();
    write!(&mut example, "{}", 42);
}
$ cargo +1.28.0 build
   Compiling xz v0.1.0 (file:///private/tmp/xz)
warning: unused `std::result::Result` which must be used
 --> src/main.rs:4:5
  |
4 |     write!(&mut example, "{}", 42);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_must_use)] on by default
  = note: this `Result` may be an `Err` variant, which should be handled
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

    Finished dev [unoptimized + debuginfo] target(s) in 1.02s

$ cargo clean
$ cargo +1.29.0 build
   Compiling xz v0.1.0 (file:///private/tmp/xz)
    Finished dev [unoptimized + debuginfo] target(s) in 1.09s

Potentially related to #54288.

@kennytm kennytm added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. labels Oct 30, 2018
@shepmaster
Copy link
Member

Expanding the macro and compiling does have the warning:

fn main() {
    use std::fmt::Write;
    let mut example = String::new();
    (&mut example).write_fmt(format_args!("{}", 42));
}
$ cargo clean
$ cargo +1.29.0 build
   Compiling xz v0.1.0 (file:///private/tmp/xz)
warning: unused `std::result::Result` which must be used
 --> src/main.rs:4:5
  |
4 |     (&mut example).write_fmt(format_args!("{}", 42));
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_must_use)] on by default
  = note: this `Result` may be an `Err` variant, which should be handled

    Finished dev [unoptimized + debuginfo] target(s) in 0.56s

@ehuss
Copy link
Contributor

ehuss commented Oct 30, 2018

Seems related to #52467.

@shepmaster
Copy link
Member

related to #52467.

/cc @alexcrichton

@alexcrichton
Copy link
Member

Ah oops, definitely a mistake! I believe a fix for this would be to set report_in_external_macro (like in this macro) for the definition of the unused must use lint as well

@varkor
Copy link
Member

varkor commented Nov 3, 2018

Will #55240 also be fixed by this?

bors added a commit that referenced this issue Nov 4, 2018
enforce unused-must-use lint in macros

Fixes #55516 by turning on the UNUSED_MUST_USE lint within macros.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another.
Projects
None yet
Development

No branches or pull requests

6 participants