Stream: t-compiler/rust-analyzer

Topic: Type inference failing on BoxFutures?


Zoey (Mar 20 2021 at 15:54, on Zulip):

Hello- I'm working with complex futures and have been seeing a lot of inference issues around futures; BoxFuture usage is hit pretty hard by it, so anything using async functions on traits is pretty much "just annotate everything" if you want to see any useful types at all.

What I'm seeing is that BoxFuture and similar are typed successfully, but once you await them, the type inference fails to deduce the inner type anymore, and shows <<{unknown} as Deref>::Target as Future>::Output or similar depending on the affected types.

I've made a repro at https://gist.github.com/Dessix/2d06becd23ff9291d8fab4015d17975b with several scenarios, showing what infers and what doesn't.

Also, I've seen this occur on Instrument streams and futures from the tokio tracing library; Instrumenting a future makes it go from resolving the type to producing {unknown} in a nested set of typecasts and associated types.

Additionally, while troubleshooting I've determined that this seems to occur independently of the Chalk environment variables for maximum iterations and tree depth (I set them 10x their defaults and saw no change in the inference result). I haven't been able to find a GitHub issue that fits this scenario.

Jonas Schievink [he/him] (Mar 20 2021 at 17:17, on Zulip):

hmm, it seems to work fine if the .await is removed, odd

Zoey (Mar 20 2021 at 17:27, on Zulip):

Yeah, I noted that in my repro on line 44, where it infers correctly until the .await. Not sure why.

Florian Diebold (Mar 20 2021 at 17:35, on Zulip):

can you file a bug for this?

Zoey (Mar 20 2021 at 17:35, on Zulip):

Working on it right now- any additional info you'd like beyond a copy-paste of my opening post to this thread?

Florian Diebold (Mar 20 2021 at 17:36, on Zulip):

that's already plenty :)

Zoey (Mar 20 2021 at 17:36, on Zulip):

Cool- I also went through the entire issue backlog for anything involving infer, inference, associated type, and chalk; nothing seemed to fit, as noted above, so here's hoping it's not just a duplicate ^^

Laurențiu (Mar 20 2021 at 17:41, on Zulip):

See also https://github.com/rust-analyzer/rust-analyzer/issues/5886

Florian Diebold (Mar 20 2021 at 17:42, on Zulip):

hm that does seem to be the same issue

Laurențiu (Mar 20 2021 at 17:51, on Zulip):

Yup

Zoey (Mar 20 2021 at 17:56, on Zulip):

Interesting- the difference I see is that Output is String in that one, where in mine it was {unknown}. Are you sure this is the same? Later comments show similar, but... under impl? If they're the same I'll avoid posting a dupe.

Florian Diebold (Mar 20 2021 at 17:58, on Zulip):

I think the screenshots in the last message show the same thing as yours

Zoey (Mar 20 2021 at 18:00, on Zulip):

I'll post my repros there and note that it also occurs for BoxStream and tracing::Instrumented

Edit: Added a comment on the issue with my repros posted.

Zoey (Mar 20 2021 at 18:52, on Zulip):

Interesting note to add- it appears that futures::executor::block_on also has this issue, based on the screenshots provided in the comment by user woody77.
Scratch that part- it's just extrapolating the type from the async block above it.

I'm also not clear on what's actually going on here, but Florian marked it as actionable, so I presume there's some context I'm missing?

Florian Diebold (Mar 20 2021 at 19:05, on Zulip):

the actionable part is debugging it and finding out what's going on

Zoey (Mar 31 2021 at 08:41, on Zulip):

Looks like someone figured it out and made a patch: https://github.com/rust-analyzer/rust-analyzer/pull/8266
Just waiting for code review and merge now :)

Lukas Wirth (Mar 31 2021 at 10:55, on Zulip):

Only thanks to what Jonas figured out though, from there on finding a minimal repro wasn't that much work anymore

Last update: Jul 24 2021 at 21:30UTC