Stream: t-compiler/rust-analyzer

Topic: Comparing types by ExprIds

ivan770 (Dec 08 2020 at 15:39, on Zulip):

Hi. I'm new to RA development, so there is a question I can't find any answer to - how do I compare types by ExprIds? I'm currently trying to implement by checking for missing tail expression, and comparing last statement type with body type.

Jonas Schievink [he/him] (Dec 08 2020 at 15:40, on Zulip):

You need to look up its type in the InferenceResult

ivan770 (Dec 08 2020 at 16:27, on Zulip):

Thanks, it worked! Looks like I have some naive implementation, though it seems to be working demo.mp4

ivan770 (Dec 08 2020 at 18:49, on Zulip):

Can I get some code review please?

Jonas Schievink [he/him] (Dec 08 2020 at 18:50, on Zulip):


Jeremy Kolb (Dec 08 2020 at 19:10, on Zulip):

The code looks pretty good to me. If you submit a PR we can do a proper review.

ivan770 (Dec 10 2020 at 15:51, on Zulip):

@matklad Hi. Can you help me a bit with that part?
I can't find any way to obtain ExprStmt, as AstNode casts don't work here because of different kinds.

matklad (Dec 10 2020 at 15:53, on Zulip):

Hm, riiight, good question

matklad (Dec 10 2020 at 15:53, on Zulip):

We don't actually store info about statements in the source map yet

matklad (Dec 10 2020 at 15:54, on Zulip):

I guess that means that we should stick to an ast::Expr here

matklad (Dec 10 2020 at 15:55, on Zulip):

Then, in the fix, where you care getting the ;, you can write expr.syntax().parent().and_then(ast::ExprStmt::cast).and_then(|it| it.semicolon_token()).

ivan770 (Dec 10 2020 at 16:11, on Zulip):

Thanks, it worked!

Last update: Jul 27 2021 at 20:30UTC