Skip to content

Commit 50bb7a4

Browse files
committed
Tweak span for #[must_use]
Do not point at whole statement, only at the expression (skip pointing at `;`)
1 parent c1a859b commit 50bb7a4

24 files changed

+58
-61
lines changed

compiler/rustc_lint/src/unused.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,14 @@ declare_lint_pass!(UnusedResults => [UNUSED_MUST_USE, UNUSED_RESULTS]);
8787

8888
impl<'tcx> LateLintPass<'tcx> for UnusedResults {
8989
fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
90-
let expr = match s.kind {
91-
hir::StmtKind::Semi(ref expr) => &**expr,
92-
_ => return,
93-
};
90+
let hir::StmtKind::Semi(expr) = s.kind else { return; };
9491

9592
if let hir::ExprKind::Ret(..) = expr.kind {
9693
return;
9794
}
9895

9996
let ty = cx.typeck_results().expr_ty(&expr);
100-
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span, "", "", 1);
97+
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, expr.span, "", "", 1);
10198

10299
let mut fn_warned = false;
103100
let mut op_warned = false;
@@ -119,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
119116
_ => None,
120117
};
121118
if let Some(def_id) = maybe_def_id {
122-
fn_warned = check_must_use_def(cx, def_id, s.span, "return value of ", "");
119+
fn_warned = check_must_use_def(cx, def_id, expr.span, "return value of ", "");
123120
} else if type_permits_lack_of_use {
124121
// We don't warn about unused unit or uninhabited types.
125122
// (See https://github.com/rust-lang/rust/issues/43806 for details.)

src/test/ui/closures/2229_closure_analysis/match/issue-87097.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | / || match out_ref {
1616
LL | | Variant::A => (),
1717
LL | | Variant::B => (),
1818
LL | | };
19-
| |______^
19+
| |_____^
2020
|
2121
= note: closures are lazy and do nothing unless called
2222
= note: `#[warn(unused_must_use)]` on by default
@@ -28,7 +28,7 @@ LL | / || match here.field {
2828
LL | | Variant::A => (),
2929
LL | | Variant::B => (),
3030
LL | | };
31-
| |______^
31+
| |_____^
3232
|
3333
= note: closures are lazy and do nothing unless called
3434

src/test/ui/conditional-compilation/cfg-attr-multi-true.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ warning: unused `MustUseDeprecated` that must be used
2828
--> $DIR/cfg-attr-multi-true.rs:19:5
2929
|
3030
LL | MustUseDeprecated::new();
31-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^
3232
|
3333
note: the lint level is defined here
3434
--> $DIR/cfg-attr-multi-true.rs:7:9

src/test/ui/generator/issue-52398.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ warning: unused generator that must be used
44
LL | / move || {
55
LL | | A.test(yield);
66
LL | | };
7-
| |______^
7+
| |_____^
88
|
99
= note: generators are lazy and do nothing unless resumed
1010
= note: `#[warn(unused_must_use)]` on by default
@@ -16,7 +16,7 @@ LL | / static move || {
1616
LL | | yield *y.borrow();
1717
LL | | return "Done";
1818
LL | | };
19-
| |______^
19+
| |_____^
2020
|
2121
= note: generators are lazy and do nothing unless resumed
2222

src/test/ui/generator/issue-57084.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | | loop {
77
LL | | yield
88
LL | | }
99
LL | | };
10-
| |______^
10+
| |_____^
1111
|
1212
= note: generators are lazy and do nothing unless resumed
1313
= note: `#[warn(unused_must_use)]` on by default

src/test/ui/generator/match-bindings.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | | match Enum::A(String::new()) {
88
... |
99
LL | | }
1010
LL | | };
11-
| |______^
11+
| |_____^
1212
|
1313
= note: generators are lazy and do nothing unless resumed
1414
= note: `#[warn(unused_must_use)]` on by default

src/test/ui/generator/reborrow-mut-upvar.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | | yield;
88
... |
99
LL | | *bar = 2;
1010
LL | | };
11-
| |______^
11+
| |_____^
1212
|
1313
= note: generators are lazy and do nothing unless resumed
1414
= note: `#[warn(unused_must_use)]` on by default

src/test/ui/generator/too-live-local-in-immovable-gen.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | | // and it should also find out that `a` is not live.
88
... |
99
LL | | let _ = &a;
1010
LL | | };
11-
| |__________^
11+
| |_________^
1212
|
1313
= note: generators are lazy and do nothing unless resumed
1414
= note: `#[warn(unused_must_use)]` on by default

src/test/ui/generator/yield-in-args-rev.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | / || {
55
LL | | let b = true;
66
LL | | foo(yield, &b);
77
LL | | };
8-
| |______^
8+
| |_____^
99
|
1010
= note: generators are lazy and do nothing unless resumed
1111
= note: `#[warn(unused_must_use)]` on by default

src/test/ui/generator/yield-in-box.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | | let _t = box (&x, yield 0, &y);
88
... |
99
LL | | }
1010
LL | | };
11-
| |______^
11+
| |_____^
1212
|
1313
= note: generators are lazy and do nothing unless resumed
1414
= note: `#[warn(unused_must_use)]` on by default

0 commit comments

Comments
 (0)