Skip to content

Deduplication: Pulled common logic out from lower_const_arg_struct#154460

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
LaneAsade:lower-path-for-struct-expr
Apr 8, 2026
Merged

Deduplication: Pulled common logic out from lower_const_arg_struct#154460
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
LaneAsade:lower-path-for-struct-expr

Conversation

@LaneAsade
Copy link
Copy Markdown
Contributor

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: #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.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 27, 2026

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 27, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 27, 2026

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, types
  • compiler, types expanded to 69 candidates
  • Random selection from 12 candidates

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 27, 2026

⚠️ Warning ⚠️

@Human9000-bit
Copy link
Copy Markdown
Contributor

cc @BoxyUwU

@BoxyUwU
Copy link
Copy Markdown
Member

BoxyUwU commented Mar 27, 2026

r? BoxyUwU

@BoxyUwU
Copy link
Copy Markdown
Member

BoxyUwU commented Apr 7, 2026

thx, sorry for taking so long to review this.

@bors r+ rollup=iffy

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 7, 2026

📌 Commit fc157f6 has been approved by BoxyUwU

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 7, 2026
rust-bors bot pushed a commit that referenced this pull request Apr 8, 2026
Rollup of 4 pull requests

Successful merges:

 - #154460 (Deduplication: Pulled common logic out from lower_const_arg_struct)
 - #154609 (Enable `#[diagnostic::on_const]` for local impls)
 - #154678 (Introduce #[diagnostic::on_move] on `Rc`)
 - #154902 (rustdoc: Inherit inline attributes for declarative macros)
@rust-bors rust-bors bot merged commit 288406a into rust-lang:main Apr 8, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Apr 8, 2026
rust-timer added a commit that referenced this pull request Apr 8, 2026
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: #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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants