Skip to content

Commit 9b97705

Browse files
committed
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
2 parents 760274f + 5a5a25c commit 9b97705

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/librustc_lint/unused.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
135135
if attr.check_name("must_use") {
136136
let mut msg = format!("unused {}`{}` which must be used",
137137
describe_path, cx.tcx.item_path_str(def_id));
138-
// check for #[must_use="..."]
139-
if let Some(s) = attr.value_str() {
140-
msg.push_str(": ");
141-
msg.push_str(&s.as_str());
138+
let mut err = cx.struct_span_lint(UNUSED_MUST_USE, sp, &msg);
139+
// check for #[must_use = "..."]
140+
if let Some(note) = attr.value_str() {
141+
err.note(&note.as_str());
142142
}
143-
cx.span_lint(UNUSED_MUST_USE, sp, &msg);
143+
err.emit();
144144
return true;
145145
}
146146
}

src/test/compile-fail/unused-result.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![deny(unused_results, unused_must_use)]
1211
#![allow(dead_code)]
12+
#![deny(unused_results, unused_must_use)]
13+
//~^ NOTE: lint level defined here
14+
//~| NOTE: lint level defined here
1315

1416
#[must_use]
1517
enum MustUse { Test }
@@ -27,7 +29,8 @@ fn qux() -> MustUseMsg { return foo::<MustUseMsg>(); }
2729
fn test() {
2830
foo::<isize>();
2931
foo::<MustUse>(); //~ ERROR: unused `MustUse` which must be used
30-
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used: some message
32+
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used
33+
//~^ NOTE: some message
3134
}
3235

3336
#[allow(unused_results, unused_must_use)]
@@ -40,7 +43,8 @@ fn test2() {
4043
fn main() {
4144
foo::<isize>(); //~ ERROR: unused result
4245
foo::<MustUse>(); //~ ERROR: unused `MustUse` which must be used
43-
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used: some message
46+
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` which must be used
47+
//~^ NOTE: some message
4448

4549
let _ = foo::<isize>();
4650
let _ = foo::<MustUse>();

src/test/ui/fn_must_use.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: unused return value of `need_to_use_this_value` which must be used: it's important
1+
warning: unused return value of `need_to_use_this_value` which must be used
22
--> $DIR/fn_must_use.rs:60:5
33
|
44
LL | need_to_use_this_value(); //~ WARN unused return value
@@ -9,18 +9,21 @@ note: lint level defined here
99
|
1010
LL | #![warn(unused_must_use)]
1111
| ^^^^^^^^^^^^^^^
12+
= note: it's important
1213

1314
warning: unused return value of `MyStruct::need_to_use_this_method_value` which must be used
1415
--> $DIR/fn_must_use.rs:65:5
1516
|
1617
LL | m.need_to_use_this_method_value(); //~ WARN unused return value
1718
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1819

19-
warning: unused return value of `EvenNature::is_even` which must be used: no side effects
20+
warning: unused return value of `EvenNature::is_even` which must be used
2021
--> $DIR/fn_must_use.rs:66:5
2122
|
2223
LL | m.is_even(); // trait method!
2324
| ^^^^^^^^^^^^
25+
|
26+
= note: no side effects
2427

2528
warning: unused return value of `std::cmp::PartialEq::eq` which must be used
2629
--> $DIR/fn_must_use.rs:72:5

0 commit comments

Comments
 (0)