about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-07-19 11:37:30 +0000
committerbors <bors@rust-lang.org>2023-07-19 11:37:30 +0000
commit7a34143fa394ccba3cbe7bd1d068420b1bfb84ea (patch)
treeaa8dcf7ea320872faee2b7babe808e0806578946 /compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
parent0fa1fd396e7d57bbe1380ef9c8738c88cfb30965 (diff)
parentf583fd18e4d1ecb7a0c2c838a5ac0a10188f24db (diff)
downloadrust-7a34143fa394ccba3cbe7bd1d068420b1bfb84ea.tar.gz
rust-7a34143fa394ccba3cbe7bd1d068420b1bfb84ea.zip
Auto merge of #11135 - smoelius:unwrap_or_else_default-fp, r=Centri3
Fix `unwrap_or_else_default` false positive

This PR fixes a false positive in the handling of `unwrap_or_else` with a default value when the value is needed for type inference.

An easy example to exhibit the false positive is the following:
```rust
    let option = None;
    option.unwrap_or_else(Vec::new).push(1);
```
The following code would not compile, because the fact that the value is a `Vec` has been lost:
```rust
    let option = None;
    option.unwrap_or_default().push(1);
```
The fix is to:
- implement a heuristic to tell whether an expression's type can be determined purely from its subexpressions, and the arguments and locals they use;
- apply the heuristic to `unwrap_or_else`'s receiver.

The heuristic returns false when applied to `option` in the above example, but it returns true when applied to `option` in either of the following examples:
```rust
    let option: Option<Vec<u64>> = None;
    option.unwrap_or_else(Vec::new).push(1);
```
```rust
    let option = None::<Vec<u64>>;
    option.unwrap_or_else(Vec::new).push(1);
```

(Aside: https://github.com/rust-lang/rust-clippy/pull/10120 unfairly contained multiple changes in one PR. I am trying to break that PR up into smaller pieces.)

---

changelog: FP: [`unwrap_or_else_default`]: No longer lints if the default value is needed for type inference
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions