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
This commit is contained in:
bors 2022-12-01 07:20:06 +00:00
commit 641ced4eb9
2 changed files with 11 additions and 3 deletions

View File

@ -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(

View File

@ -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() {}