diff options
| author | bors <bors@rust-lang.org> | 2022-12-01 07:20:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-01 07:20:06 +0000 |
| commit | 641ced4eb96d07fba2284fa258ccb987f7afc8a1 (patch) | |
| tree | d23dec24499ffb6faf0b8632964183f14c16535f | |
| parent | ee12b12be538900d9b21cde6643ee78144a14445 (diff) | |
| parent | 7ae5c81e9f9046a547757a1521e83c23da0bb67e (diff) | |
| download | rust-641ced4eb96d07fba2284fa258ccb987f7afc8a1.tar.gz rust-641ced4eb96d07fba2284fa258ccb987f7afc8a1.zip | |
Auto merge of #10007 - Jarcho:issue_10005, r=giraffate
Fix ICE in `result_large_err` with uninhabited enums fixes #10005 changelog: `result_large_err`: Fix ICE with uninhabited enums
| -rw-r--r-- | clippy_lints/src/functions/result.rs | 8 | ||||
| -rw-r--r-- | tests/ui/result_large_err.rs | 6 |
2 files changed, 11 insertions, 3 deletions
diff --git a/clippy_lints/src/functions/result.rs b/clippy_lints/src/functions/result.rs index f7e30b051a6..23da145d038 100644 --- a/clippy_lints/src/functions/result.rs +++ b/clippy_lints/src/functions/result.rs @@ -94,7 +94,9 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty if let hir::ItemKind::Enum(ref def, _) = item.kind; then { let variants_size = AdtVariantInfo::new(cx, *adt, subst); - if variants_size[0].size >= large_err_threshold { + if let Some((first_variant, variants)) = variants_size.split_first() + && first_variant.size >= large_err_threshold + { span_lint_and_then( cx, RESULT_LARGE_ERR, @@ -102,11 +104,11 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty "the `Err`-variant returned from this function is very large", |diag| { diag.span_label( - def.variants[variants_size[0].ind].span, + def.variants[first_variant.ind].span, format!("the largest variant contains at least {} bytes", variants_size[0].size), ); - for variant in &variants_size[1..] { + for variant in variants { if variant.size >= large_err_threshold { let variant_def = &def.variants[variant.ind]; diag.span_label( diff --git a/tests/ui/result_large_err.rs b/tests/ui/result_large_err.rs index 9dd27d6dc01..1c12cebfd97 100644 --- a/tests/ui/result_large_err.rs +++ b/tests/ui/result_large_err.rs @@ -108,4 +108,10 @@ pub fn array_error<T, U>() -> Result<(), ArrayError<(i32, T), U>> { Ok(()) } +// Issue #10005 +enum Empty {} +fn _empty_error() -> Result<(), Empty> { + Ok(()) +} + fn main() {} |
