Skip to content

Commit 070d7c2

Browse files
authored
Rollup merge of rust-lang#94353 - flip1995:fix_debug_assert_unused, r=Dylan-DPC
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. found in rust-lang#94329 A reproducer for this would be ```rust fn main() { (1, (3,)); } ``` Not sure, if I should add a regression test for a `debug_assert`.
2 parents ed202b8 + bbe3447 commit 070d7c2

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

compiler/rustc_lint/src/unused.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,17 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
240240
}
241241
ty::Tuple(ref tys) => {
242242
let mut has_emitted = false;
243-
let spans = if let hir::ExprKind::Tup(comps) = &expr.kind {
243+
let comps = if let hir::ExprKind::Tup(comps) = expr.kind {
244244
debug_assert_eq!(comps.len(), tys.len());
245-
comps.iter().map(|e| e.span).collect()
245+
comps
246246
} else {
247-
vec![]
247+
&[]
248248
};
249249
for (i, ty) in tys.iter().enumerate() {
250250
let descr_post = &format!(" in tuple element {}", i);
251-
let span = *spans.get(i).unwrap_or(&span);
252-
if check_must_use_ty(cx, ty, expr, span, descr_pre, descr_post, plural_len)
253-
{
251+
let e = comps.get(i).unwrap_or(expr);
252+
let span = e.span;
253+
if check_must_use_ty(cx, ty, e, span, descr_pre, descr_post, plural_len) {
254254
has_emitted = true;
255255
}
256256
}

src/test/ui/lint/unused/must_use-array.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ error: unused array of boxed `T` trait objects in tuple element 1 that must be u
3232
--> $DIR/must_use-array.rs:43:5
3333
|
3434
LL | impl_array();
35-
| ^^^^^^^^^^^^^
35+
| ^^^^^^^^^^^^
3636

3737
error: unused array of arrays of arrays of `S` that must be used
3838
--> $DIR/must_use-array.rs:45:5

src/test/ui/lint/unused/must_use-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ error: unused boxed `Critical` trait object in tuple element 1 that must be used
2626
--> $DIR/must_use-trait.rs:37:5
2727
|
2828
LL | get_critical_tuple();
29-
| ^^^^^^^^^^^^^^^^^^^^^
29+
| ^^^^^^^^^^^^^^^^^^^^
3030

3131
error: unused implementer of `Critical` in tuple element 2 that must be used
3232
--> $DIR/must_use-trait.rs:37:5
3333
|
3434
LL | get_critical_tuple();
35-
| ^^^^^^^^^^^^^^^^^^^^^
35+
| ^^^^^^^^^^^^^^^^^^^^
3636

3737
error: aborting due to 5 previous errors
3838

src/test/ui/lint/unused/must_use-tuple.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ error: unused `Result` in tuple element 0 that must be used
3131
--> $DIR/must_use-tuple.rs:14:5
3232
|
3333
LL | foo();
34-
| ^^^^^^
34+
| ^^^^^
3535
|
3636
= note: this `Result` may be an `Err` variant, which should be handled
3737

3838
error: unused `Result` in tuple element 0 that must be used
39-
--> $DIR/must_use-tuple.rs:16:6
39+
--> $DIR/must_use-tuple.rs:16:7
4040
|
4141
LL | ((Err::<(), ()>(()), ()), ());
42-
| ^^^^^^^^^^^^^^^^^^^^^^^
42+
| ^^^^^^^^^^^^^^^^^
4343
|
4444
= note: this `Result` may be an `Err` variant, which should be handled
4545

0 commit comments

Comments
 (0)