Stream: t-compiler/help

Topic: How do I get the type of an `ast::ItemKind::Fn`?


Joshua Nelson (Jun 20 2020 at 00:48, on Zulip):

Is this happening too early in the process to infer the type or is there a way to get it from tcx?

Joshua Nelson (Jun 20 2020 at 00:49, on Zulip):

(deleted)

Joshua Nelson (Jun 20 2020 at 00:49, on Zulip):

actually I think I see the issue already, I don't have a tcx available :(

Joshua Nelson (Jun 20 2020 at 00:50, on Zulip):

for context (hah!) this is in https://github.com/rust-lang/rust/blob/2bfdecad6b1e89c4becfd4c115f643384eb39d6a/src/librustc_interface/util.rs#L594 which is implementing MutVisitor for the AST

mark-i-m (Jun 20 2020 at 01:43, on Zulip):

Yeah, so the AST happens before any typing has happened

mark-i-m (Jun 20 2020 at 01:44, on Zulip):

However, depending on where in rustc_interface this is, you might be able to get access to a tcx somehow...

mark-i-m (Jun 20 2020 at 01:47, on Zulip):

hmmm... yeah, looking through the code, it looks like this is before the tcx is even constructed

mark-i-m (Jun 20 2020 at 01:48, on Zulip):

(though, I'm not an expert, so I may be wrong)

Joshua Nelson (Jun 20 2020 at 01:57, on Zulip):

ok, well it's not necessary to fix my bug, it would just be nice (allow replacing bodies of functions returning impl trait). thanks for looking though!

mark-i-m (Jun 20 2020 at 03:25, on Zulip):

I might be misunderstanding, but why not use a proc macro?

Joshua Nelson (Jun 20 2020 at 03:35, on Zulip):

I'm not sure how proc macros are related. In this context I'm replacing the function body with loop {} so that rustdoc doesn't have to do item-bodies checking, but that breaks type inference if the function returns impl trait.

mark-i-m (Jun 20 2020 at 18:26, on Zulip):

Ah, I see. Yeah, ignore my suggestion :P

Joshua Nelson (Jun 20 2020 at 23:36, on Zulip):

In case you're curious, this ended up as https://github.com/rust-lang/rust/pull/73566/

Last update: Sep 28 2020 at 14:45UTC