-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Warn on indexing in general? #2536
Comments
Well.. indexing is fine if you know the value cannot be out of bounds. We should write such a lint as a MIR processing lint that triggers on all reachable panics. This is nontrivial to do, but we can start with a simple one and keep improving it. Note that this has a lot of overlap with the const propagator in rustc, so we should probably keep improving that one instead and create an RFC for a no-panic lint |
@oli-obk thanks for the feedback, I love the idea of a more general no-panic lint (especially if it won't warn on a value that cannot be out of bounds). I'm unclear on what would be a productive next step for me though. I'm certainly interested in the idea of working toward some familiarity with MIR, whether that means starting simple like you mentioned or digging into the rustc const propagator. |
I think for now the lint as you originally suggested sounds like a good medium term solution. The full analysis version is still far on the horizon. Feel free to open a PR to add it to the It would be great if indexing with compile-time indices into arrays would not report the lint as long as the index is in bounds. |
@oli-obk I believe that I can avoid reporting in-bounds array indexes by using some of the functionality that already exists in the I'd like to avoid as much code duplication as possible though and am interested in any thoughts around it. One strategy would be incorporate the out-of-bounds check from |
You need to create different lints for different groups, you can't have parts of a lint in different groups. But that's absolutely no problem. Create as many fine grained lints as you think makes sense. |
👋
I'm interested in contributing a lint I've put together but would love some feedback before starting the PR process. The general idea is that I'd like to dissuade behavior that could cause a runtime panic in my project, in this case, indexing.
Some preliminary work behaves something like the following:
I guess to start, I'm interested in whether this lint seems like could fit in here. If it does we can go from there, thanks!
The text was updated successfully, but these errors were encountered: