Skip to content

Commit 9dd2c89

Browse files
author
Alex Burka
committed
enforce unused-must-use lint in macros
1 parent 1cf82fd commit 9dd2c89

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/librustc_lint/unused.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use rustc::hir;
2929
declare_lint! {
3030
pub UNUSED_MUST_USE,
3131
Warn,
32-
"unused result of a type flagged as #[must_use]"
32+
"unused result of a type flagged as #[must_use]",
33+
report_in_external_macro: true
3334
}
3435

3536
declare_lint! {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-pass
12+
// compile-flags: -Wunused
13+
14+
// make sure write!() can't hide its unused Result
15+
16+
fn main() {
17+
use std::fmt::Write;
18+
let mut example = String::new();
19+
write!(&mut example, "{}", 42); //~WARN must be used
20+
}
21+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: unused `std::result::Result` that must be used
2+
--> $DIR/must-use-in-macro-55516.rs:19:5
3+
|
4+
LL | write!(&mut example, "{}", 42); //~WARN must be used
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-W unused-must-use` implied by `-W unused`
8+
= note: this `Result` may be an `Err` variant, which should be handled
9+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
10+

0 commit comments

Comments
 (0)