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

Output type of aliased Fn trait object is not inferred correctly. #13169

Open
lucidfrontier45 opened this issue Sep 2, 2022 · 2 comments
Open
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@lucidfrontier45
Copy link

lucidfrontier45 commented Sep 2, 2022

  • rustc 1.63.0 (4b91a6ea7 2022-08-08)
  • rust-analyzer v0.3.1186

image

As is shown in the picture, the return type of dyn Fn trait objects is not correctly inferred. v in test_myfn_dyn and test_myfn2_dyn are also expected to be inferred as usize.

This may be related to #5057 but that was about directly writing dyn trait object, which works fine as the example of test_dyn_fn_trait_direct.

@flodiebold flodiebold added A-ty type system / type inference / traits / method resolution C-bug Category: bug labels Sep 2, 2022
@lowr
Copy link
Contributor

lowr commented Sep 5, 2022

Interesting. Essentially, this is because chalk cannot prove Implemented(dyn Trait: Trait) given the following setup:

trait Base { type T; }
trait Trait: Base<T = usize> {}

Because of the rules described in rust-lang/chalk#203, chalk needs to prove AliasEq(<dyn Trait as Base>::T = usize) only to fail as there's no clause for it.

@flodiebold Do you have any insights on this? I don't know chalk enough to tell if this is something chalk should be able to deduce by itself or if we need to give chalk more information, e.g. dyn for<Self> [Implemented(Self: Trait), AliasEq(<Self as Base>::T = usize)] for dyn Trait with the setup above whereas we currently only give dyn for<Self> [Implemented(Self: Trait)].

@flodiebold
Copy link
Member

Well, that seems wrong. It seems to me that associated type bindings should be implied, not required. It certainly wouldn't make any sense for us to add that clause, since that's what implied bounds / elaboration are for. I'd suggest opening a Chalk issue for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants