Files
rust/compiler/rustc_hir_analysis
Jacob Pratt 288406ae93 Rollup merge of #154460 - LaneAsade:lower-path-for-struct-expr, r=BoxyUwU
Deduplication: Pulled common logic out from lower_const_arg_struct

This PR aims to deduplicate the logic in the function `lower_const_arg_struct` by creating a helper function `lower_path_for_struct_expr` which is shared between `rustc_hir_ty_lowering `and `rustc_hir_typeck`.

Related: https://github.com/rust-lang/rust/issues/150621

Helper function code:

```
pub struct ResolvedStructPath<'tcx> {
    pub res: Result<Res, ErrorGuaranteed>,
    pub ty: Ty<'tcx>,
}

pub fn lower_path_for_struct_expr(
        &self,
        qpath: hir::QPath<'tcx>,
        path_span: Span,
        hir_id: HirId,
    ) -> ResolvedStructPath<'tcx> {
        match qpath {
            hir::QPath::Resolved(ref maybe_qself, path) => {
                let self_ty = maybe_qself.as_ref().map(|qself| self.lower_ty(qself));
                let ty = self.lower_resolved_ty_path(self_ty, path, hir_id, PermitVariants::Yes);
                ResolvedStructPath { res: Ok(path.res), ty }
            }
            hir::QPath::TypeRelative(hir_self_ty, segment) => {
                let self_ty = self.lower_ty(hir_self_ty);

                let result = self.lower_type_relative_ty_path(
                    self_ty,
                    hir_self_ty,
                    segment,
                    hir_id,
                    path_span,
                    PermitVariants::Yes,
                );
                let ty = result
                    .map(|(ty, _, _)| ty)
                    .unwrap_or_else(|guar| Ty::new_error(self.tcx(), guar));

                ResolvedStructPath {
                    res: result.map(|(_, kind, def_id)| Res::Def(kind, def_id)),
                    ty,
                }
            }
        }
    }
```

Thanks to @BoxyUwU for the guidance on this issue.
2026-04-07 23:05:30 -04:00
..

For high-level intro to how type checking works in rustc, see the hir typeck chapter of the rustc dev guide.