Skip to content

Conversation

@unrealhoang
Copy link
Contributor

attempt on #3669

@unrealhoang unrealhoang force-pushed the assist_unwrap_to_match branch from cd3ad5b to 51c2f15 Compare March 26, 2020 13:58
let ty = ctx.sema.type_of_expr(&caller)?;

let type_name = ty.as_adt()?.name(ctx.sema.db);
if type_name == name![Result] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather then using name!, let's do type_name.to_string() == "Result". name! should be mostly internal. In particular, we probably shouldn't add Option there just for the sake of a single assit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could actually make this completely agnostic of the particular enum by looking at the code of the unwrap function and using the branches from there, assuming it's a single match (which it is for Option and Result)... I'm not suggesting we do this right now though 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah, you know going further an assist to inline the function call should actually be a superset of this assist!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, except that at least the Result implementation calls a private function instead of directly panicing 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bruh

@unrealhoang unrealhoang force-pushed the assist_unwrap_to_match branch from 51c2f15 to d9df0f4 Compare March 26, 2020 15:11
@matklad
Copy link
Contributor

matklad commented Mar 26, 2020

bors r+

bors bot added a commit that referenced this pull request Mar 26, 2020
3732: Assist: replace unwrap with match r=matklad a=unrealhoang

attempt on #3669

Co-authored-by: Unreal Hoang <[email protected]>
@matklad
Copy link
Contributor

matklad commented Mar 26, 2020

CI failure is unrelated. Could you rebase on top of #3735?

bors d+

@bors
Copy link
Contributor

bors bot commented Mar 26, 2020

✌️ unrealhoang can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@bors
Copy link
Contributor

bors bot commented Mar 26, 2020

This PR was included in a batch that successfully built, but then failed to merge into master (it was a non-fast-forward update). It will be automatically retried.

@bors
Copy link
Contributor

bors bot commented Mar 26, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants