about summary refs log tree commit diff
path: root/tests/codegen/patchable-function-entry
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-26 14:18:33 +0000
committerbors <bors@rust-lang.org>2023-09-26 14:18:33 +0000
commit3b1b58c225d35414d90078dc7e06ca74a49cad0c (patch)
tree0fe15ae669e6c4d1302f45e47e4e86375ba56df2 /tests/codegen/patchable-function-entry
parentc945f90cb9623973700aae72a2807b6b54e0b549 (diff)
parent7306504b82cfc1d39f44c3bd59aceca483e37eac (diff)
downloadrust-3b1b58c225d35414d90078dc7e06ca74a49cad0c.tar.gz
rust-3b1b58c225d35414d90078dc7e06ca74a49cad0c.zip
Auto merge of #15662 - rmehri01:fix_panic_with_return_in_match, r=Veykril
fix: panic with wrapping/unwrapping result return type assists

With the `wrap_return_type_in_result` assist, the following code results in a panic (note the lack of a semicolon):

```rust
fn foo(num: i32) -> $0i32 {
    return num
}

=>

thread 'handlers::wrap_return_type_in_result::tests::wrap_return_in_tail_position' panicked at crates/syntax/src/ted.rs:137:41:
called `Option::unwrap()` on a `None` value
```

I think this is because it first walks the body expression to change any `return` expressions and then walks all tail expressions, resulting in the `return num` being changed twice since it is both a `return` and in tail position. This can also happen when a `match` is in tail position and `return` is used in a branch for example. Not really sure how big of an issue this is in practice though since this seems to be the only case that is impacted and can be reduced to just `num` instead of `return num`.

This also occurs with the `unwrap_result_return_type` assist but panics with the following instead:

```
thread 'handlers::unwrap_result_return_type::tests::wrap_return_in_tail_position' panicked at /rustc/3223b0b5e8dadda3f76c3fd1a8d6c5addc09599e/library/alloc/src/string.rs:1766:29:
assertion failed: self.is_char_boundary(n)
```
Diffstat (limited to 'tests/codegen/patchable-function-entry')
0 files changed, 0 insertions, 0 deletions