-
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
Fix false positive for needless_character_iteration
lint
#12886
Fix false positive for needless_character_iteration
lint
#12886
Conversation
cc46063
to
312c7f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some optimization, and this should be ready!
ExprKind::Call(fn_path, [arg]) => { | ||
if let ExprKind::Path(path) = fn_path.kind | ||
&& let Some(fn_def_id) = cx.qpath_res(&path, fn_path.hir_id).opt_def_id() | ||
&& match_def_path(cx, fn_def_id, &["core", "char", "methods", "<impl char>", "is_ascii"]) | ||
&& path_to_local_id(peels_expr_ref(arg), first_param) | ||
&& let Some(snippet) = snippet_opt(cx, before_chars) | ||
// If we have `!is_ascii`, then only `.any()` should warn. And if the condition is | ||
// `is_ascii`, then only `.all()` should warn. | ||
&& revert != is_all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you lift this to avoid running the expensive conditions unnecessarily? (Same with the other condition)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
312c7f3
to
158b658
Compare
Moved the condition sooner for better performance as suggested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! ❤️
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #12879.
changelog: Fix false positive for
needless_character_iteration
lint