Skip to content

Fix ICE in result_large_err with uninhabited enums #10007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions clippy_lints/src/functions/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,21 @@ 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,
hir_ty_span,
"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(
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/result_large_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}