Auto merge of #50437 - zackmdavis:must_note, r=estebank

in which the must-use additional messaging is tucked into a note

_I_ think it looks better this way! What do _you_ think??

![must_use_note](https://user-images.githubusercontent.com/1076988/39612597-b6dd2dae-4f15-11e8-87ec-ab9da21ef062.png)

r? @estebank
This commit is contained in:
bors 2018-05-07 06:27:01 +00:00
commit 9b97705f9e
3 changed files with 17 additions and 10 deletions

View File

@ -135,12 +135,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
if attr.check_name("must_use") {
let mut msg = format!("unused {}`{}` which must be used",
describe_path, cx.tcx.item_path_str(def_id));
// check for #[must_use="..."]
if let Some(s) = attr.value_str() {
msg.push_str(": ");
msg.push_str(&s.as_str());
let mut err = cx.struct_span_lint(UNUSED_MUST_USE, sp, &msg);
// check for #[must_use = "..."]
if let Some(note) = attr.value_str() {
err.note(&note.as_str());
}
cx.span_lint(UNUSED_MUST_USE, sp, &msg);
err.emit();
return true;
}
}

View File

@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![deny(unused_results, unused_must_use)]
#![allow(dead_code)]
#![deny(unused_results, unused_must_use)]
//~^ NOTE: lint level defined here
//~| NOTE: lint level defined here
#[must_use]
enum MustUse { Test }
@ -27,7 +29,8 @@ fn qux() -> MustUseMsg { return foo::<MustUseMsg>(); }
fn test() {
foo::<isize>();
foo::<MustUse>(); //~ ERROR: unused `MustUse` which must be used
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used: some message
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used
//~^ NOTE: some message
}
#[allow(unused_results, unused_must_use)]
@ -40,7 +43,8 @@ fn test2() {
fn main() {
foo::<isize>(); //~ ERROR: unused result
foo::<MustUse>(); //~ ERROR: unused `MustUse` which must be used
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used: some message
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used
//~^ NOTE: some message
let _ = foo::<isize>();
let _ = foo::<MustUse>();

View File

@ -1,4 +1,4 @@
warning: unused return value of `need_to_use_this_value` which must be used: it's important
warning: unused return value of `need_to_use_this_value` which must be used
--> $DIR/fn_must_use.rs:60:5
|
LL | need_to_use_this_value(); //~ WARN unused return value
@ -9,6 +9,7 @@ note: lint level defined here
|
LL | #![warn(unused_must_use)]
| ^^^^^^^^^^^^^^^
= note: it's important
warning: unused return value of `MyStruct::need_to_use_this_method_value` which must be used
--> $DIR/fn_must_use.rs:65:5
@ -16,11 +17,13 @@ warning: unused return value of `MyStruct::need_to_use_this_method_value` which
LL | m.need_to_use_this_method_value(); //~ WARN unused return value
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: unused return value of `EvenNature::is_even` which must be used: no side effects
warning: unused return value of `EvenNature::is_even` which must be used
--> $DIR/fn_must_use.rs:66:5
|
LL | m.is_even(); // trait method!
| ^^^^^^^^^^^^
|
= note: no side effects
warning: unused return value of `std::cmp::PartialEq::eq` which must be used
--> $DIR/fn_must_use.rs:72:5