Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(exporter): disable impl expr resolution under type aliases #709

Merged
merged 3 commits into from
Jun 25, 2024
Merged

Conversation

W95Psp
Copy link
Collaborator

@W95Psp W95Psp commented Jun 10, 2024

This commit disables trait resolution in the context of a type alias definition.

Rust doesn't enforce bounds on generic parameters in type aliases, so it is legal to write:

struct Foo<T: Clone>(T);
type Synonym<T> = Foo<T>;

Thus, if we compute the impl expression for the bound T: Clone that appears on the type expression Foo<T>, Rustc's trait selection fails: in the context of Synonym, T indeed doesn't implement Clone, a priori.

This is raising an issue about backends: translating such type synonyms with "missing" bounds will fail. See
#708. Thus, this PR also introduces an option so that type synonyms are not extracted by default.

Fixes #707 and fixes #708

@Nadrieril
Copy link
Collaborator

Could you add the required bounds to the type synonym instead? This is the only correct solution I can imagine.

@W95Psp
Copy link
Collaborator Author

W95Psp commented Jun 10, 2024

That's something we could do, indeed, but that's not trivial. I'm afraid this will cause bugs in the frontend :/

A quite "brutal" way of doing that would be: each time select_trait_candidate fails on a trait reference, we add this trait reference to the where clause of the type synonym. But that sounds quite hacky :(

@Nadrieril
Copy link
Collaborator

Yeah :(

@W95Psp W95Psp added this pull request to the merge queue Jun 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 12, 2024
@W95Psp W95Psp added the waiting-on-author Status: This is awaiting some action from the author. label Jun 13, 2024
@W95Psp W95Psp added this pull request to the merge queue Jun 24, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 24, 2024
@W95Psp W95Psp enabled auto-merge June 24, 2024 08:43
W95Psp and others added 3 commits June 25, 2024 07:48
This commits disables trait resolution in the context of a type alias
definition.

Rust doesn't enforce bounds on generic parameters in type aliases, so
it is legal to write:

```rust
struct Foo<T: Clone>(T);
type Synonym<T> = Foo<T>;
```

Thus, if we compute the impl expression for the bound `T: Clone` that
appears on the type expression `Foo<T>`, Rustc's trait selection
fails: in the context of `Synonym`, `T` indeed doesn't implement
`Clone`, _a priori_.

This is raising an issue about backends: translating such type synonym
with "missing" bounds will fail. See
#708.

Fixes #707
@W95Psp W95Psp added this pull request to the merge queue Jun 25, 2024
Merged via the queue into main with commit 18e21e2 Jun 25, 2024
13 checks passed
@W95Psp W95Psp deleted the fix-707 branch June 25, 2024 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-on-author Status: This is awaiting some action from the author.
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Type aliases missing bounds in backends Trait selection returns Unimplemented on type aliases
3 participants