Repository: rust-lang/rust
File: compiler/rustc_ast_lowering/src/item.rs (Rust)

Code before:
                            this.lower_param_bounds(
                                bounds,
                                RelaxedBoundPolicy::Allowed,
                                ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
                            ),
                            ty,
                        )
                    },
                );
                (*ident, generics, kind, ty.is_some())
            }
            AssocItemKind::Delegation(box delegation) => {
                let delegation_results = self.lower_delegation(delegation, i.id);
                let item_kind = hir::TraitItemKind::Fn(
                    delegation_results.sig,
                    hir::TraitFn::Provided(delegation_results.body_id),
                );
                (delegation.ident, delegation_results.generics, item_kind, true)
            }
            AssocItemKind::MacCall(..) | AssocItemKind::DelegationMac(..) => {
                panic!("macros should have been expanded by now")
            }
        };

        let (defaultness, _) =
            self.lower_defaultness_for_assoc_item(&i.kind, i.kind.defaultness(), has_value);

        let item = hir::TraitItem {
            owner_id: trait_item_def_id,
            ident: self.lower_ident(ident),
            generics,
            kind,
            span: self.lower_span(i.span),
            defaultness,
            has_delayed_lints: !self.delayed_lints.is_empty(),
        };
        self.arena.alloc(item)
    }

    fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemId {
        hir::TraitItemId { owner_id: self.owner_id(i.id) }
    }

    /// Construct `ExprKind::Err` for the given `span`.
    pub(crate) fn expr_err(&mut self, span: Span, guar: ErrorGuaranteed) -> hir::Expr<'hir> {
        self.expr(span, hir::ExprKind::Err(guar))
    }

    fn lower_trait_impl_header(
        &mut self,
        trait_impl_header: &TraitImplHeader,

Review comment (suggestion):
Why not just:

```suggestion
        let defaultness = match i.kind.defaultness() {
            // We don't (yet) support final trait assoc items other than assoc fns. While we do
			// reject `final` on non-fns during AST validation we also have to stop propagating
			// it here since later compiler passes don't expect & can't handle such assoc items.
            Defaultness:Final(_) if !matches!(i.kind, AssocItemKind::Fn(..)) => ast::Defaultness::Implicit,
            defaultness => defaultness,
        };
        let (defaultness, _) = self.lower_defaultness(defaultness, has_value, || {
            hir::Defaultness::Default { has_value }
        });
```

This way, we don't need to explicitly call `lower_span` and so on.

Code after:
                            this.lower_param_bounds(
                                bounds,
                                RelaxedBoundPolicy::Allowed,
                                ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
                            ),
                            ty,
                        )
                    },
                );
                (*ident, generics, kind, ty.is_some())
            }
            AssocItemKind::Delegation(box delegation) => {
                let delegation_results = self.lower_delegation(delegation, i.id);
                let item_kind = hir::TraitItemKind::Fn(
                    delegation_results.sig,
                    hir::TraitFn::Provided(delegation_results.body_id),
                );
                (delegation.ident, delegation_results.generics, item_kind, true)
            }
            AssocItemKind::MacCall(..) | AssocItemKind::DelegationMac(..) => {
                panic!("macros should have been expanded by now")
            }
        };

        let defaultness = match i.kind.defaultness() {
            // We do not yet support `final` on trait associated items other than functions.
            // Even though we reject `final` on non-functions during AST validation, we still
            // need to stop propagating it here because later compiler passes do not expect
            // and cannot handle such items.
            Defaultness::Final(..) if !matches!(i.kind, AssocItemKind::Fn(..)) => {
                Defaultness::Implicit
            }
            defaultness => defaultness,
        };
        let (defaultness, _) = self
            .lower_defaultness(defaultness, has_value, || hir::Defaultness::Default { has_value });

        let item = hir::TraitItem {
            owner_id: trait_item_def_id,
            ident: self.lower_ident(ident),
            generics,
            kind,
            span: self.lower_span(i.span),
            defaultness,
            has_delayed_lints: !self.delayed_lints.is_empty(),
        };
        self.arena.alloc(item)
    }

    fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemId {
        hir::TraitItemId { owner_id: self.owner_id(i.id) }