Skip to content

OR patterns in let chains are formatted without indentation #194

@BoxyUwU

Description

@BoxyUwU
        let hir = tcx.hir();
        if let Some(body_id) = tcx.hir_node_by_def_id(def_id).body_id() {
            tcx.arena.alloc_from_iter(hir.body_param_names(body_id))
        } else if let Node::TraitItem(&TraitItem {
            kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),
            ..
        })
        | Node::ForeignItem(&ForeignItem {
            kind: ForeignItemKind::Fn(_, idents, _),
            ..
        }) = tcx.hir_node(tcx.local_def_id_to_hir_id(def_id))
        {
            idents
        } else {
            span_bug!(
                hir.span(tcx.local_def_id_to_hir_id(def_id)),
                "fn_arg_names: unexpected item {:?}",
                def_id
            );
        }

The indentation on this else if let is very confusing as it looks like the if else ends because we are at "normal" indentation for statements in the body, which makes it look like someone has written an assignment with a pattern with a leading | which is then somehow followed up by a block with an else on the end of it (?)

Something like the following would be significantly clearer as the indentation signifies that this is inside of the else condition:

        let hir = tcx.hir();
        if let Some(body_id) = tcx.hir_node_by_def_id(def_id).body_id() {
            tcx.arena.alloc_from_iter(hir.body_param_names(body_id))
        } else if let Node::TraitItem(&TraitItem {
                kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),
                ..
            })
            | Node::ForeignItem(&ForeignItem {
                kind: ForeignItemKind::Fn(_, idents, _),
                ..
            }) = tcx.hir_node(tcx.local_def_id_to_hir_id(def_id))
        {
            idents
        } else {
            span_bug!(
                hir.span(tcx.local_def_id_to_hir_id(def_id)),
                "fn_arg_names: unexpected item {:?}",
                def_id
            );
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions