mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
288406ae93
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.
For high-level intro to how type checking works in rustc, see the hir typeck chapter of the rustc dev guide.