about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorQuinn Sinclair <me@partiallytyped.dev>2024-01-03 04:03:00 +0200
committerQuinn Sinclair <me@partiallytyped.dev>2024-01-07 17:11:34 +0200
commitbbadce9ec0a8855ab72852af1a6ed1f68c9ce0c2 (patch)
tree985cd70d506b22c8f04a379778172a96034b0c87 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parent9eb2b225f8fe7c8066adb261635fbece9f356ea3 (diff)
downloadrust-bbadce9ec0a8855ab72852af1a6ed1f68c9ce0c2.tar.gz
rust-bbadce9ec0a8855ab72852af1a6ed1f68c9ce0c2.zip
Fixed ICE introduced in #12004
Issue: in #12004, we emit a lint for `filter(Option::is_some)`. If the
parent expression is a `.map` we don't emit that lint as there exists a
more specialized lint for that.

The ICE introduced in #12004 is a consequence of the assumption that a
parent expression after a filter would be a method call with the filter
call being the receiver. However, it is entirely possible to have a
closure of the form

```
|| { vec![Some(1), None].into_iter().filter(Option::is_some) }
```
The previous implementation looked at the parent expression; namely the
closure, and tried to check the parameters by indexing [0] on an empty
list.

This commit is an overhaul of the lint with significantly more FP tests
and checks.

Impl details:

1. We verify that the filter method we are in is a proper trait method
   to avoid FPs.
2. We check that the parent expression is not a map by checking whether
   it exists; if is a trait method; and then a method call.
3. We check that we don't have comments in the span.
4. We verify that we are in an Iterator of Option and Result.
5. We check the contents of the filter.
  1. For closures we peel it. If it is not a single expression, we don't
     lint.
  2. For paths, we do a typecheck to avoid FPs for types that impl
     functions with the same names.
  3. For calls, we verify the type, via the path, and that the param of
     the closure is the single argument to the call.
  4. For method calls we verify that the receiver is the parameter of
     the closure. Since we handle single, non-block exprs, the
     parameter can't be shadowed, so no FP.

This commit also adds additional FP tests.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions