Skip to content

Delegation: eliminate usage of AST from generics creation#154142

Open
aerooneqq wants to merge 1 commit intorust-lang:mainfrom
aerooneqq:dont-create-ast-generics-2
Open

Delegation: eliminate usage of AST from generics creation#154142
aerooneqq wants to merge 1 commit intorust-lang:mainfrom
aerooneqq:dont-create-ast-generics-2

Conversation

@aerooneqq
Copy link
Contributor

@aerooneqq aerooneqq commented Mar 20, 2026

This PR eliminates all interaction with AST during creation of generics, then it supports proper const param types propagation. Fixes #153433. Fixes #153499. Part of #118212.

r? @petrochenkov

@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 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 20, 2026
@petrochenkov petrochenkov added the F-fn_delegation `#![feature(fn_delegation)]` label Mar 20, 2026
pub enum InferDelegation<'hir> {
DefId(DefId),
Sig(DefId, InferDelegationSig<'hir>),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need comments explaining what the variants mean / when they are used.

/// through `tcx`. Next, at some point of generics processing we need to lower those
/// generics to HIR, for this purpose we use `into_hir_generics` that lowers AST generics
/// and replaces Ast variant with Hir. Such approach is useful as we can call this method
/// Used for storing either ty generics or their lowered HIR version. Firstly we obtain
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Used for storing either ty generics or their lowered HIR version. Firstly we obtain
/// Used for storing either ty generics or their uplifted HIR version. First we obtain

(In other places too.)

}
} else {
DelegationGenerics::Default(parent_generics_factory(self, false))
let skip_self = !generate_self as usize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let skip_self = !generate_self as usize;
let skip_self = usize::from(!generate_self);

generics
fn generic_params(&mut self, id: DefId) -> Option<impl Iterator<Item = ty::GenericParamDef>> {
let params = &self.tcx.generics_of(id).own_params;
(!params.is_empty()).then(|| params.iter().cloned())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to clone and collect the parameters?
You could probably keep the &'tcx [GenericParam] or its sub-slices directly.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-fn_delegation `#![feature(fn_delegation)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

[ICE]: adding a def'n for node-id NodeId(35) and def kind LifetimeParam but a previous def'n exists [ICE]: duplicate copy of DefId in lctx.children

3 participants