mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Use precise span for must_use tuple components
This commit is contained in:
parent
fd36b5fd52
commit
e121d9671a
@ -54,7 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
|
|||||||
{
|
{
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
check_must_use_ty(cx, ty, s.span)
|
check_must_use_ty(cx, ty, &expr, s.span)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut fn_warned = false;
|
let mut fn_warned = false;
|
||||||
@ -138,6 +138,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
|
|||||||
fn check_must_use_ty(
|
fn check_must_use_ty(
|
||||||
cx: &LateContext<'_, '_>,
|
cx: &LateContext<'_, '_>,
|
||||||
ty: Ty<'_>,
|
ty: Ty<'_>,
|
||||||
|
expr: &hir::Expr,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
match ty.sty {
|
match ty.sty {
|
||||||
@ -170,9 +171,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
|
|||||||
has_emitted
|
has_emitted
|
||||||
}
|
}
|
||||||
ty::Tuple(ref tys) => {
|
ty::Tuple(ref tys) => {
|
||||||
tys.iter().map(|k| k.expect_ty()).any(|ty| {
|
let mut has_emitted = false;
|
||||||
check_must_use_ty(cx, ty, span)
|
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,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,8 @@
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
(Ok::<(), ()>(()),); //~ ERROR unused `std::result::Result` that must be used
|
(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
|
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::<(), ()>(()),);
|
LL | (Ok::<(), ()>(()),);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
note: lint level defined here
|
note: lint level defined here
|
||||||
--> $DIR/must_use-tuple.rs:1:9
|
--> $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
|
= 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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user