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 https://github.com/rust-analyzer/rust-analyzer/issues/6739 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? https://github.com/ivan770/rust-analyzer/commit/cb66bb8ff9609d4fc3702ac1ed6197802b54e473
demo2.mp4

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

neat!

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? https://github.com/rust-analyzer/rust-analyzer/pull/6769#discussion_r540146705
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