-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Uplift clippy::invalid_null_ptr_usage
lint as invalid_null_arguments
#119220
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
b25c44c
to
7308419
Compare
This comment has been minimized.
This comment has been minimized.
7308419
to
05aabc1
Compare
I think @saethlin has also found plenty of code that hits this in the wild, so this seems like a good lint. |
You're probably referring to PyO3/pyo3#2687 and servo/font-kit#197 I don't think either of these would be detected by the lint, but I agree that this is a reasonable lint target. |
I'll flag this as |
☔ The latest upstream changes (presumably #120991) made this pull request unmergeable. Please resolve the merge conflicts. |
(Just me, with my lang hat on but not talking for the team.) I wish there was an easier way for these to get added without waiting on us. Would you be interested in making a proposal of some sort for making maybe a It'd be great if, rather than lang needing to approve stuff, it'd just be |
That feels similar to what flux and verus are doing but at a smaller scale. Unsure about allowing downstream users to access it but it'd be great to make these kinds of checks more prevalent (and not just for null ptr cases) |
I do like refinement types. We should discuss this further, I love the idea of rust expanding its sights of correctness to this, rather than a devtool (what flux does atm) |
I would if there was an easier way to add those kind of lints. Using the
That would be awesome, I would love if it were this "simple". I can write something akin to an MCP (for t-lang) but I don't have the time for a full RFC :-) |
This comment was marked as outdated.
This comment was marked as outdated.
@traviscross It's been more than a year since I nominated this PR for T-lang, I know it's not high priority/high in the list, and I don't mind waiting, but it's becoming annoying to maintain these kind of PR. This one in particular has nearly all modified files in conflict. Is this something T-lang would accept? Is there a way to gather consensus outside of a nomination? If not I rather close this PR than continue to waste my time maintaining this PR. |
Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
Anyone have a better suggestion for the lint name than |
This comment has been minimized.
This comment has been minimized.
b36fb5a
to
334634c
Compare
…ywiser Fix false-positive in `expr_or_init` and in the `invalid_from_utf8` lint This PR fixes the logic for finding initializer in the `expr_or_init` and `expr_or_init_with_outside_body` functions. If the binding were to be mutable (`let mut`), the logic wouldn't consider that the initializer expression could have been modified and would return the init expression even-trough multiple subsequent assignments could have been done. Example: ```rust let mut a = [99, 108, 130, 105, 112, 112]; // invalid, not UTF-8 loop { a = *b"clippy"; // valid break; } std::str::from_utf8_mut(&mut a); // currently warns, with this PR it doesn't ``` This PR modifies the logic to excludes mutable let bindings. Found when using `expr_or_init` in rust-lang#119220. r? compiler
…ywiser Fix false-positive in `expr_or_init` and in the `invalid_from_utf8` lint This PR fixes the logic for finding initializer in the `expr_or_init` and `expr_or_init_with_outside_body` functions. If the binding were to be mutable (`let mut`), the logic wouldn't consider that the initializer expression could have been modified and would return the init expression even-trough multiple subsequent assignments could have been done. Example: ```rust let mut a = [99, 108, 130, 105, 112, 112]; // invalid, not UTF-8 loop { a = *b"clippy"; // valid break; } std::str::from_utf8_mut(&mut a); // currently warns, with this PR it doesn't ``` This PR modifies the logic to excludes mutable let bindings. Found when using `expr_or_init` in rust-lang#119220. r? compiler
…ywiser Fix false-positive in `expr_or_init` and in the `invalid_from_utf8` lint This PR fixes the logic for finding initializer in the `expr_or_init` and `expr_or_init_with_outside_body` functions. If the binding were to be mutable (`let mut`), the logic wouldn't consider that the initializer expression could have been modified and would return the init expression even-trough multiple subsequent assignments could have been done. Example: ```rust let mut a = [99, 108, 130, 105, 112, 112]; // invalid, not UTF-8 loop { a = *b"clippy"; // valid break; } std::str::from_utf8_mut(&mut a); // currently warns, with this PR it doesn't ``` This PR modifies the logic to excludes mutable let bindings. Found when using `expr_or_init` in rust-lang#119220. r? compiler
Rollup merge of rust-lang#138360 - Urgau:fix-fp-expr_or_init, r=wesleywiser Fix false-positive in `expr_or_init` and in the `invalid_from_utf8` lint This PR fixes the logic for finding initializer in the `expr_or_init` and `expr_or_init_with_outside_body` functions. If the binding were to be mutable (`let mut`), the logic wouldn't consider that the initializer expression could have been modified and would return the init expression even-trough multiple subsequent assignments could have been done. Example: ```rust let mut a = [99, 108, 130, 105, 112, 112]; // invalid, not UTF-8 loop { a = *b"clippy"; // valid break; } std::str::from_utf8_mut(&mut a); // currently warns, with this PR it doesn't ``` This PR modifies the logic to excludes mutable let bindings. Found when using `expr_or_init` in rust-lang#119220. r? compiler
This comment was marked as resolved.
This comment was marked as resolved.
334634c
to
1ceebfe
Compare
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
clippy::invalid_null_ptr_usage
lintclippy::invalid_null_arguments
lint
clippy::invalid_null_arguments
lintclippy::invalid_null_ptr_usage
lint as invalid_null_arguments
1ceebfe
to
7739280
Compare
This comment was marked as outdated.
This comment was marked as outdated.
7739280
to
441fb02
Compare
This PR aims at uplifting the
clippy::invalid_null_ptr_usage
lint into rustc, this is similar to theclippy::invalid_utf8_in_unchecked
uplift a few months ago, in the sense that those two lints lint on invalid parameter(s), here a null pointer where it is unexpected and UB to pass one.For context: GitHub Search reveals that just for
slice::from_raw_parts{_mut}
~20 invalid usages withptr::null
and an additional 4 invalid usages with0 as *const ...
-ish casts.invalid_null_arguments
(deny-by-default)
The
invalid_null_arguments
lint checks for invalid usage of null pointers.Example
Produces:
Explanation
Calling methods whose safety invariants requires non-null pointer with a null pointer is undefined behavior.
The lint use a list of functions to know which functions and arguments to checks, this could be improved in the future with a rustc attribute, or maybe even with a
#[diagnostic]
attribute.This PR also includes some small refactoring to avoid some ambiguities in naming, those can be done in another PR is desired.
@rustbot label: +I-lang-nominated
r? compiler