diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-08 22:51:04 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-08 22:51:04 +0000 |
commit | 3fdf26a6fcaa557e9c3652cca5c0e0802956ee3f (patch) | |
tree | 95068634046c5c57a7689ab7034797224e542dca /docs/dev/debugging.md | |
parent | c48478621fe9b50cb19bfd0ea4a5c2ff0de5d6ac (diff) | |
parent | b275e609051f217f330509da26cf74bf941cf972 (diff) |
Merge #7898
7898: generate_function assist: infer return type r=JoshMcguigan a=JoshMcguigan
This PR makes two changes to the generate function assist:
1. Attempt to infer an appropriate return type for the generated function
2. If a return type is inferred, and that return type is not unit, don't render the snippet
```rust
fn main() {
let x: u32 = foo$0();
// ^^^ trigger the assist to generate this function
}
// BEFORE
fn foo() ${0:-> ()} {
todo!()
}
// AFTER (only change 1)
fn foo() ${0:-> u32} {
todo!()
}
// AFTER (change 1 and 2, note the lack of snippet around the return type)
fn foo() -> u32 {
todo!()
}
```
These changes are made as two commits, in case we want to omit change 2. I personally feel like it is a nice change, but I could understand there being some opposition.
#### Pros of change 2
If we are able to infer a return type, and especially if that return type is not the unit type, the return type is almost as likely to be correct as the argument names/types. I think this becomes even more true as people learn how this feature works.
#### Cons of change 2
We could never be as confident about the return type as we are about the function argument types, so it is more likely a user will want to change that. Plus it is a confusing UX to sometimes have the cursor highlight the return type after triggering this assist and sometimes not have that happen.
#### Why omit unit type?
The assumption is that if we infer the return type as unit, it is likely just because of the current structure of the code rather than that actually being the desired return type. However, this is obviously just a heuristic and will sometimes be wrong. But being wrong here just means falling back to the exact behavior that existed before this PR.
Co-authored-by: Josh Mcguigan <[email protected]>
Diffstat (limited to 'docs/dev/debugging.md')
0 files changed, 0 insertions, 0 deletions