Stream: t-compiler/wg-rls-2.0

Topic: Help casting


Manmeet Mann (Aug 07 2020 at 13:00, on Zulip):

How to convert a hir::Type to ast::Type?

Laurențiu Nicola (Aug 07 2020 at 13:06, on Zulip):

I don't think it's possible? One is a type as in "42i32 is of type i32" while the other one is a piece of syntax, as in x: &[i32]

Manmeet Mann (Aug 07 2020 at 13:11, on Zulip):

I am working on assist generate function. Trying to make it infer the return type. I don't know how to quote the function because make::fn_ doesn't accept a return type

Laurențiu Nicola (Aug 07 2020 at 13:14, on Zulip):

Ah, I'm not sure, but you might need to go through the textual representation

Laurențiu Nicola (Aug 07 2020 at 13:14, on Zulip):

There's make::ty which gives you an ast::Type

Manmeet Mann (Aug 07 2020 at 13:15, on Zulip):

Thanks

Manmeet Mann (Aug 07 2020 at 13:16, on Zulip):

Also should I modify make::fn_ to take a return type

Manmeet Mann (Aug 07 2020 at 13:16, on Zulip):

Ie. Option<Type>

Laurențiu Nicola (Aug 07 2020 at 13:16, on Zulip):

And you can pretty-print a hir::Ty using ty.display(db)

Laurențiu Nicola (Aug 07 2020 at 13:17, on Zulip):

That sounds reasonable

Florian Diebold (Aug 07 2020 at 13:32, on Zulip):

you should use display_source_code though, not display. The former is specifically for printing a valid source code representation

Last update: Sep 27 2020 at 13:30UTC