Include async functions in the len_without_is_empty#10359
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. Please see the contribution instructions for more information. |
|
r? @llogiq |
6f96437 to
b83b963
Compare
b83b963 to
9d69b0b
Compare
|
fmt and dogfood are still failing; those should be easy to fix. @rustbot author |
9d69b0b to
31b3bd1
Compare
|
The tests are fixed now, hope everything looks fine @rustbot llogiq |
|
@rustbot label: +S-waiting-on-review, -S-waiting-on-author |
| fn parse_len_output<'tcx>(cx: &LateContext<'_>, sig: FnSig<'tcx>) -> Option<LenOutput<'tcx>> { | ||
|
|
||
| fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> { | ||
| if let ty::Alias(_, alias_ty) = ty.kind() { |
There was a problem hiding this comment.
You chould use the if_chain! macro here for shorter and clearer code.
There was a problem hiding this comment.
Nowadays we can even use let chains.
| return Some(LenOutput::Option(def_id)); | ||
| } | ||
|
|
||
| return Some(LenOutput::Option(def_id)); |
There was a problem hiding this comment.
What is the use of the if is_first_generic_integral(segment) above if it returns the same thing anyway?
There was a problem hiding this comment.
Sorry, this is a bug. is_first_generic_integral checks that len() returns Option<T> where T is an integral type. This should ignore things like pub fn len() -> Option<String> because that's what happens for the sync version.
I've added a test for this.
| let item = hir_map.get_if_local(def_id); | ||
| let item = item.unwrap(); | ||
|
|
||
| if let Node::Item(item) = item { |
There was a problem hiding this comment.
or could use a unique if let … here since you are really matching deeper and deeper with one possible pattern.
There was a problem hiding this comment.
I rewrote this with an if let without nesting. However, it can't be a unique if let since at times I want to check some bounds before indexing into an array.
I have collapsed the chains as much as possible though. I personally don't like that much (e.g. I'd rather split
let Some(Node::Item(Item { kind: ItemKind::OpaqueTy(opaque), .. })) = cx.tcx.hir().get_if_local(alias_ty.def_id) &&
...
into
let Some(Node::Item(item)) = cx.tcx.hir().get_if_local(alias_ty.def_id) &&
let Item { kind: ItemKind::OpaqueTy(opaque), .. } = item &&
...
but if you prefer it like this I have no issue with that.
edit, I had to split the example I provided to shorten the line under 120 characters anyway, but I would probably still cut some of the remaining ones.
31b3bd1 to
c68b745
Compare
|
Hi, do you think you will have some time for this PR? I'd like to finish this soI don't forget about it. |
|
☔ The latest upstream changes (presumably #10438) made this pull request unmergeable. Please resolve the merge conflicts. |
| (Self::Option(_), Res::Def(_, def_id)) if cx.tcx.is_diagnostic_item(sym::Option, def_id) => true, | ||
| (Self::Result(_), Res::Def(_, def_id)) if cx.tcx.is_diagnostic_item(sym::Result, def_id) => true, |
There was a problem hiding this comment.
| (Self::Option(_), Res::Def(_, def_id)) if cx.tcx.is_diagnostic_item(sym::Option, def_id) => true, | |
| (Self::Result(_), Res::Def(_, def_id)) if cx.tcx.is_diagnostic_item(sym::Result, def_id) => true, | |
| (Self::Option(_), Res::Def(_, def_id)) => cx.tcx.is_diagnostic_item(sym::Option, def_id), | |
| (Self::Result(_), Res::Def(_, def_id)) => cx.tcx.is_diagnostic_item(sym::Result, def_id), |
I think we don't need guards here.
c68b745 to
1335978
Compare
Co-authored-by: Akshay <nerdy@peppe.rs>
1335978 to
5369052
Compare
|
r? @llogiq |
|
Could not assign reviewer from: |
|
Thank you! @bors r+ |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
fixes #7232
Changes done to the functionality:
Allowing different error types for the functions was disallowed. So the following was linted before but is not after this change
changelog: Enhancement: [
len_without_is_empty]: Now also detectsasyncfunctions#10359