Skip to content
Permalink
Browse files

Use precise span for must_use tuple components

  • Loading branch information...
varkor committed May 27, 2019
1 parent fd36b5f commit e121d9671afe4eae1f418db14a6fdae07652c51c
Showing with 38 additions and 7 deletions.
  1. +15 −4 src/librustc_lint/unused.rs
  2. +4 −0 src/test/ui/lint/must_use-tuple.rs
  3. +19 −3 src/test/ui/lint/must_use-tuple.stderr
@@ -54,7 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
{
true
} else {
check_must_use_ty(cx, ty, s.span)
check_must_use_ty(cx, ty, &expr, s.span)
};

let mut fn_warned = false;
@@ -138,6 +138,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
fn check_must_use_ty(
cx: &LateContext<'_, '_>,
ty: Ty<'_>,
expr: &hir::Expr,
span: Span,
) -> bool {
match ty.sty {
@@ -170,9 +171,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
has_emitted
}
ty::Tuple(ref tys) => {
tys.iter().map(|k| k.expect_ty()).any(|ty| {
check_must_use_ty(cx, ty, span)
})
let mut has_emitted = false;
let spans = if let hir::ExprKind::Tup(comps) = &expr.node {
debug_assert_eq!(comps.len(), tys.len());
comps.iter().map(|e| e.span).collect()
} else {
vec![]
};
for (i, ty) in tys.iter().map(|k| k.expect_ty()).enumerate() {
if check_must_use_ty(cx, ty, expr, *spans.get(i).unwrap_or(&span)) {
has_emitted = true;
}
}
has_emitted
}
_ => false,
}
@@ -2,4 +2,8 @@

fn main() {
(Ok::<(), ()>(()),); //~ ERROR unused `std::result::Result` that must be used

(Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5);
//~^ ERROR unused `std::result::Result` that must be used
//~^^ ERROR unused `std::result::Result` that must be used
}
@@ -1,8 +1,8 @@
error: unused `std::result::Result` that must be used
--> $DIR/must_use-tuple.rs:4:5
--> $DIR/must_use-tuple.rs:4:6
|
LL | (Ok::<(), ()>(()),);
| ^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/must_use-tuple.rs:1:9
@@ -11,5 +11,21 @@ LL | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^
= note: this `Result` may be an `Err` variant, which should be handled

error: aborting due to previous error
error: unused `std::result::Result` that must be used
--> $DIR/must_use-tuple.rs:6:6
|
LL | (Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5);
| ^^^^^^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled

error: unused `std::result::Result` that must be used
--> $DIR/must_use-tuple.rs:6:27
|
LL | (Ok::<(), ()>(()), 0, Ok::<(), ()>(()), 5);
| ^^^^^^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled

error: aborting due to 3 previous errors

0 comments on commit e121d96

Please sign in to comment.
You can’t perform that action at this time.