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

Add clippy lints to catch more panics #1363

Closed
2 of 3 tasks
sffc opened this issue Dec 7, 2021 · 11 comments · Fixed by #1650
Closed
2 of 3 tasks

Add clippy lints to catch more panics #1363

sffc opened this issue Dec 7, 2021 · 11 comments · Fixed by #1650
Assignees
Labels
C-meta Component: Relating to ICU4X as a whole good first issue Good for newcomers S-small Size: One afternoon (small bug fix or enhancement) T-techdebt Type: ICU4X code health and tech debt

Comments

@sffc
Copy link
Member

sffc commented Dec 7, 2021

We should enable the following clippy lints:

Ideally we can limit this to library code only. We don't want these in test code or offline tooling code.

As usual, in cases where the usage of these operators is valid, an #[allow(clippy::indexing_slicing)] can be used, with a comment explaining why it is OK.

The goal here is to better enforce this section of the style guide: https://github.com/unicode-org/icu4x/blob/main/docs/process/style_guide.md#best-practice

I can't talk about panics without also referencing #1183

@sffc sffc added good first issue Good for newcomers C-meta Component: Relating to ICU4X as a whole T-techdebt Type: ICU4X code health and tech debt S-small Size: One afternoon (small bug fix or enhancement) needs-approval One or more stakeholders need to approve proposal labels Dec 7, 2021
@robertbastian
Copy link
Member

I don't agree with expect over unwrap. If either are justified because it's obvious that the value is Ok/Some, using expect puts a pointless string in the binary.

@Manishearth
Copy link
Member

Manishearth commented Dec 10, 2021

It's not really pointless because it tells you more about where in the code the problem happened. Fortunately, unwrap/expect now use #[track_caller] so they're not


I'm over all positive about adding these lints; I think they'll work out well! I feel like the main situation where we'll want to keep them in is near unsafe code: it's better to panic than trigger UB (which is essentially, allowing for a broader set of undesirable behavior including a panic elsewhere).

We can also improve the lints upstream to handle more cases if there are panics that are clearly safe at compile time.

@sffc
Copy link
Member Author

sffc commented Dec 10, 2021

I don't agree with expect over unwrap. If either are justified because it's obvious that the value is Ok/Some, using expect puts a pointless string in the binary.

I want to forbid both.

@dminor
Copy link
Contributor

dminor commented Dec 10, 2021

This makes sense to me.

@sffc sffc added backlog help wanted Issue needs an assignee and removed needs-approval One or more stakeholders need to approve proposal labels Dec 23, 2021
@ozghimire
Copy link
Contributor

I can add these clippy lints. Is anyone else working on this at the moment?

@gregtatum
Copy link
Member

@sffc is that list above up to date?

@sffc
Copy link
Member Author

sffc commented Feb 25, 2022

Yes it is. Nothing has changed since I filed the issue.

@sffc
Copy link
Member Author

sffc commented Mar 5, 2022

Looking at @ozghimire's PR, I'm wondering if we should restrict unwrap and [], but allow expect, since the point is to have an affirmative comment that the panic is safe, and expect already gives that to us.

@robertbastian
Copy link
Member

since the point is to have an affirmative comment that the panic is safe

We're not saying the panic is "safe" (which has a special meaning in Rust), we're saying it's impossible. We shouldn't include a message in the binary that will never be used.

I also think we should be consistent and either always expect or always unwrap.

@gregtatum
Copy link
Member

We shouldn't include a message in the binary that will never be used.

But logic errors do come up, and the assumption that it'll never be shown can be wrong.

sffc pushed a commit that referenced this issue Mar 24, 2022
@sffc sffc added this to the 2022 Q1 0.6 Sprint E milestone Mar 24, 2022
@sffc sffc removed help wanted Issue needs an assignee backlog labels Mar 24, 2022
@sffc
Copy link
Member Author

sffc commented Mar 24, 2022

Fixed in #1650

@sffc sffc closed this as completed Mar 24, 2022
@sffc sffc mentioned this issue Aug 17, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-meta Component: Relating to ICU4X as a whole good first issue Good for newcomers S-small Size: One afternoon (small bug fix or enhancement) T-techdebt Type: ICU4X code health and tech debt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants