1
Fork 0

Fix debug_assert in unused lint pass

This fixes a debug assertion in the unused lint pass. As a side effect,
this also improves the span generated for tuples in the
`unused_must_use` lint.
This commit is contained in:
flip1995 2022-02-25 11:30:16 +00:00
parent ece55d416e
commit bbe3447313
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
4 changed files with 12 additions and 12 deletions

View file

@ -240,17 +240,17 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
} }
ty::Tuple(ref tys) => { ty::Tuple(ref tys) => {
let mut has_emitted = false; let mut has_emitted = false;
let spans = if let hir::ExprKind::Tup(comps) = &expr.kind { let comps = if let hir::ExprKind::Tup(comps) = expr.kind {
debug_assert_eq!(comps.len(), tys.len()); debug_assert_eq!(comps.len(), tys.len());
comps.iter().map(|e| e.span).collect() comps
} else { } else {
vec![] &[]
}; };
for (i, ty) in tys.iter().enumerate() { for (i, ty) in tys.iter().enumerate() {
let descr_post = &format!(" in tuple element {}", i); let descr_post = &format!(" in tuple element {}", i);
let span = *spans.get(i).unwrap_or(&span); let e = comps.get(i).unwrap_or(expr);
if check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, plural_len) let span = e.span;
{ if check_must_use_ty(cx, ty, e, span, descr_pre, descr_post, plural_len) {
has_emitted = true; has_emitted = true;
} }
} }

View file

@ -32,7 +32,7 @@ error: unused array of boxed `T` trait objects in tuple element 1 that must be u
--> $DIR/must_use-array.rs:43:5 --> $DIR/must_use-array.rs:43:5
| |
LL | impl_array(); LL | impl_array();
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^
error: unused array of arrays of arrays of `S` that must be used error: unused array of arrays of arrays of `S` that must be used
--> $DIR/must_use-array.rs:45:5 --> $DIR/must_use-array.rs:45:5

View file

@ -26,13 +26,13 @@ error: unused boxed `Critical` trait object in tuple element 1 that must be used
--> $DIR/must_use-trait.rs:37:5 --> $DIR/must_use-trait.rs:37:5
| |
LL | get_critical_tuple(); LL | get_critical_tuple();
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
error: unused implementer of `Critical` in tuple element 2 that must be used error: unused implementer of `Critical` in tuple element 2 that must be used
--> $DIR/must_use-trait.rs:37:5 --> $DIR/must_use-trait.rs:37:5
| |
LL | get_critical_tuple(); LL | get_critical_tuple();
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 5 previous errors error: aborting due to 5 previous errors

View file

@ -31,15 +31,15 @@ error: unused `Result` in tuple element 0 that must be used
--> $DIR/must_use-tuple.rs:14:5 --> $DIR/must_use-tuple.rs:14:5
| |
LL | foo(); LL | foo();
| ^^^^^^ | ^^^^^
| |
= 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: unused `Result` in tuple element 0 that must be used error: unused `Result` in tuple element 0 that must be used
--> $DIR/must_use-tuple.rs:16:6 --> $DIR/must_use-tuple.rs:16:7
| |
LL | ((Err::<(), ()>(()), ()), ()); LL | ((Err::<(), ()>(()), ()), ());
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
| |
= note: this `Result` may be an `Err` variant, which should be handled = note: this `Result` may be an `Err` variant, which should be handled