Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

De-unwrap all assists #15398

Closed
15 tasks done
lnicola opened this issue Aug 5, 2023 · 12 comments · Fixed by #15665
Closed
15 tasks done

De-unwrap all assists #15398

lnicola opened this issue Aug 5, 2023 · 12 comments · Fixed by #15665
Labels
A-assists C-bug Category: bug

Comments

@lnicola
Copy link
Member

lnicola commented Aug 5, 2023

Historically, the assists have been one of our major source of crashes, usually because they didn't handle invalid or incomplete code. Let's try to clean these up a bit.

Here are the ones I've found, though some of the usages there might actually be correct.

@lnicola lnicola added A-assists C-bug Category: bug labels Aug 5, 2023
@lowr
Copy link
Contributor

lowr commented Aug 6, 2023

The unwrap() in remove_dbg is fine because replacements is checked to be non-empty right before it.

@lnicola
Copy link
Member Author

lnicola commented Aug 6, 2023

That's right, but we could still extract that into a local variable and check it properly. It's not worse, and we won't spend time figuring it out again the next 10 times we go through the assists.

EDIT: even a single ? might do the job.

@lowr
Copy link
Contributor

lowr commented Aug 6, 2023

A comment would suffice I'd say. It's definitely bad to unwrap() without any explanation but for those as simple as this one I'd rather not write unnecessary control flow. I'll file a PR that adds a comment if that sounds reasonable.

Meanwhile, I've found that unwrap() in generate_default_from_new is problematic, sigh.

@lnicola
Copy link
Member Author

lnicola commented Aug 6, 2023

I mean, a ? (or even my original suggestion, but not I'm not at the computer) will let us remove the check above, so it's not more control flow. It's much easier to grep and not have the unwrap there than to read the comment and think 😅.

@lnicola
Copy link
Member Author

lnicola commented Aug 6, 2023

By the way, my idea here is to clean up as much of these as we can, then add a "ratchet"-style test to make sure we're not adding more by mistake.

bors added a commit that referenced this issue Aug 6, 2023
Don't provide `generate_default_from_new` when impl self ty is missing

Also don't provide the assist when the `Default` trait can't be found.

Part of #15398
bors added a commit that referenced this issue Aug 11, 2023
minor: Remove `unwrap` from `Remove dbg!`

Part of #15398.
bors added a commit that referenced this issue Aug 11, 2023
…icola

minor : Deunwrap remove_unused_imports

#15398 Subtask 3
bors added a commit that referenced this issue Aug 15, 2023
…r=Veykril

minor : Deunwrap convert_to_guarded_return

Closes subtask 12 of #15398
bors added a commit that referenced this issue Aug 15, 2023
…r=Veykril

minor : Deunwrap generate_delegate_methods

#15398 subtask 8
bors added a commit that referenced this issue Aug 18, 2023
minor : Deunwrap generate_derive

#15398 subtask 1. Since the editing closure has arms, I did something *experimental* ( in this case just a clever term for bad code ) to bypass creating an `Option` but I am ready to change this.
bors added a commit that referenced this issue Sep 8, 2023
… r=Veykril

minor : Deunwrap wrap_return_type_in_result

#15398 subtask 7
bors added a commit that referenced this issue Sep 11, 2023
minor : Deunwrap extract_function

#15398 subtask 5.
bors added a commit that referenced this issue Sep 22, 2023
minor : Deunwrap inline call

#15398 subtask 4. There is still one instance of unwrap, which I found pretty hard to change.
bors added a commit that referenced this issue Sep 22, 2023
minor : Deunwrap inline call

#15398 subtask 4. There is still one instance of unwrap, which I found pretty hard to change.
bors added a commit that referenced this issue Sep 22, 2023
…eykril

Deunwrap add_missing_match_arms

Last subtask of #15398
bors added a commit that referenced this issue Sep 22, 2023
…ykril

minor : Deunwrap convert_comment_block and desugar_doc_comment

Closes subtask 13 of #15398 . I still don't know a more idiomatic way for the for loops I added, any suggestion would make me happy.
@Milo123459
Copy link
Contributor

can this be closed because all the tasks have been completed?

@lnicola
Copy link
Member Author

lnicola commented Sep 25, 2023

Almost. I think there are a couple more in generate_function which we can turn into expect.

@Milo123459
Copy link
Contributor

can i potentially look into doing those?

@lnicola
Copy link
Member Author

lnicola commented Sep 25, 2023

Sure. Check out lines 407 and 686 in generate_function.rs.

The other thing I wanted to have is a tidy test to count how many unwraps there are in this directory.

@Milo123459
Copy link
Contributor

is there a place i can ask for guidance? some of these aren't that clear - for example line 406 suggests that the unwrap is fine? or am i misinterpreting it.

@lnicola
Copy link
Member Author

lnicola commented Sep 25, 2023

Yeah, I meant replacing .unwrap() with .expect("generated function should have a body") and so on.

@Milo123459
Copy link
Contributor

should be all good, not sure about the tail_expr expect.

@bors bors closed this as completed in d3cc3bc Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants