about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-03-17 14:04:14 +0100
committerGitHub <noreply@github.com>2024-03-17 14:04:14 +0100
commit3ec2b7bd1d08687e83ea8a1e0aa01d3c85bdc720 (patch)
tree734a9ebb89a638247c182ca54c260dca321a79bb /compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
parentecdea9e9438cdb8cf707e7f60e066eda02344d05 (diff)
parent78e94cba7733d52f0601d853be15622361d94e44 (diff)
downloadrust-3ec2b7bd1d08687e83ea8a1e0aa01d3c85bdc720.tar.gz
rust-3ec2b7bd1d08687e83ea8a1e0aa01d3c85bdc720.zip
Rollup merge of #121236 - long-long-float:rust-fix-consider-slicing, r=Nadrieril
Don't show suggestion if slice pattern is not top-level

Close #120605

Don't show suggestion to add slicing (`[..]`) if the slice pattern is enclosed by struct like `Struct { a: [] }`.

For example, current rustc makes a suggestion as a comment. However, the pattern `a: []` is wrong, not scrutinee `&self.a`.
In this case, the structure type `a: Vec<Struct>` and the pattern `a: []` are different so I think the pattern should be fixed, not the scrutinee.
If the parent of the pattern that was the target of the error is a structure, I made the compiler not show a suggestion.

```rs
pub struct Struct {
    a: Vec<Struct>,
}

impl Struct {
    pub fn test(&self) {
        if let [Struct { a: [] }] = &self.a {
//             ^^^^^^^^^^^^^^^^^^   ------- help: consider slicing here: `&self.a[..]`
            println!("matches!")
        }
    }
}
```

Note:

* ~~I created `PatInfo.history` to store parent-child relationships for patterns, but this may be inefficient.~~
  * I use two fields `parent_kind` and `current_kind` instead of vec. It may not performance issue.
* Currently only looking at direct parents, but may need to look at deeper ancestry.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp')
0 files changed, 0 insertions, 0 deletions