Skip to content

Keep generic types when translating trait alias in monomorphized mode#1087

Open
Sam-Ni wants to merge 8 commits intoAeneasVerif:mainfrom
Sam-Ni:mono_trait_alias
Open

Keep generic types when translating trait alias in monomorphized mode#1087
Sam-Ni wants to merge 8 commits intoAeneasVerif:mainfrom
Sam-Ni:mono_trait_alias

Conversation

@Sam-Ni
Copy link
Copy Markdown
Contributor

@Sam-Ni Sam-Ni commented Apr 6, 2026

This PR closes #1086 . We keep the generic types (such as Self) of trait aliases in their declarations and impl blocks to make it consistent with the "normal" trait declarations in mono mode.

@Nadrieril
Copy link
Copy Markdown
Member

Hm that feels wrong, the way trait aliases are translated is that they're translated twice: once as TraitDecl and once as a TraitImpl. The trait impl side should be translated as a normal RustcItem::Mono, can you justify why the special mono-trait exception is useful here?

@Sam-Ni
Copy link
Copy Markdown
Contributor Author

Sam-Ni commented Apr 7, 2026

Hm that feels wrong, the way trait aliases are translated is that they're translated twice: once as TraitDecl and once as a TraitImpl. The trait impl side should be translated as a normal RustcItem::Mono, can you justify why the special mono-trait exception is useful here?

I see. I misunderstood how impl blocks work for trait aliases. So we should keep a single trait declaration and provide separate impl blocks for different types, just like the normal traits. Is that correct?

@Nadrieril
Copy link
Copy Markdown
Member

Yep, that's what I had in mind so that trait aliases can be as close to normal traits as possible

Comment on lines +443 to +445
// Exclude trait impl of trait alias,
// For exmaple., we use the name `{impl B for i32}` rather than `{impl B for i32}::i32`,
// where `B` is a trait alias and `i32` is the generic argument for `Self`.
Copy link
Copy Markdown
Member

@Nadrieril Nadrieril Apr 23, 2026

Choose a reason for hiding this comment

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

I'm confused by that remark: I don't see how we can ever get {impl B for i32}::i32. We can get {impl B for i32} or we can get {impl<T> B for T}::i32. To me {impl B for i32}::i32 feels like something got messed up in the generics handling, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you’re right. The remark is misleading. What I meant to say is that, to avoid generating names like {impl B for i32}::i32 for the trait impl of a trait alias, we need to check src.kind in the if statement below the remark.

Is it better not to include such incorrect examples in the remark (since they can cause confusion)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is obviously better not to include incorrect examples, but what I'd really want is a correct example and explanation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it. I'll do that.

@Sam-Ni
Copy link
Copy Markdown
Contributor Author

Sam-Ni commented Apr 28, 2026

The remark is updated to include clearer explanations and examples on how trait implementations for aliases are translated in mono mode. If anything is still unclear or confusing, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: mismatched type generics appears when translating trait alias in monomorphized mode

2 participants