rust/tests/ui/return
Michael Goulet ca9f615525
Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillot
Remove `MaybeForgetReturn` suggestion

#115196 implemented a suggestion to add a missing `return` when there is an ambiguity error, when that ambiguity error could be constrained by the return type of the function.

I initially reviewed it and thought it could be useful; however, looking back at that code now, I feel like it's a bit too much of a hack to be worth keeping around in typeck, especially given how rare it's expected to fire in practice. This is especially true because it depends on `StashKey::MaybeForgetReturn`, which is only stashed when we have *Sized* obligation ambiguity errors. Let's remove it for now.

I'd like to note that it's basically impossible to get this suggestion to apply in its current state except for what I'd consider somewhat artificial examples, involving no generic trait bounds. For example, it's not triggered for:

```rust
struct W<T>(T);

fn bar<T: Default>() -> W<T> { todo!() }

fn foo() -> W<i32> {
    if true {
        bar();
    }
    W(0)
}
```

Nor is it triggered for:

```
fn foo() -> i32 {
    if true {
        Default::default();
    }
    0
}
```

It's basically only triggered iff there's only one ambiguity error on the type, which is `Sized`.

Generally, suggesting something that affects control flow is a pretty dramatic suggestion; therefore, both the accuracy and precision of this diagnostic should be pretty high.

One other, somewhat unrelated observation is that this might be using stashed diagnostics incorrectly (or at least unnecessarily). Stashed diagnostics are used when error detection is fragmented over several major stages of the compiler, like a parse or resolver error which later can be recovered in typeck. However, this one is a bit different since it is fully handled within typeck -- perhaps that suggests that if this were to be reimplemented, it wouldn't need to be so complicated of an implementation.
2025-03-06 12:22:10 -05:00
..
dont-suggest-through-inner-const.rs Don't skip inner const when looking for body for suggestion 2024-05-23 19:49:48 -04:00
dont-suggest-through-inner-const.stderr Don't skip inner const when looking for body for suggestion 2024-05-23 19:49:48 -04:00
infer-return-ty-for-fn-sig-issue-125488.fixed Fix a error suggestion for E0121 when using placeholder _ as return types on function signature. 2024-06-29 14:23:33 +08:00
infer-return-ty-for-fn-sig-issue-125488.rs Fix a error suggestion for E0121 when using placeholder _ as return types on function signature. 2024-06-29 14:23:33 +08:00
infer-return-ty-for-fn-sig-issue-125488.stderr Fix a error suggestion for E0121 when using placeholder _ as return types on function signature. 2024-06-29 14:23:33 +08:00
issue-64620.rs
issue-64620.stderr
issue-82612-return-mutable-reference.rs
issue-82612-return-mutable-reference.stderr
issue-86188-return-not-in-fn-body.rs
issue-86188-return-not-in-fn-body.stderr Tweak multispan rendering 2024-12-12 23:36:27 +00:00
ret-bang.rs Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
ret-non-nil.rs Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
ret-non-nil.stderr Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
return-disjoint-regions.rs Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
return-disjoint-regions.stderr Move 100 entries from tests/ui into subdirs 2024-05-20 19:55:59 -07:00
return-from-diverging.rs
return-from-diverging.stderr
return-from-residual-sugg-issue-125997.fixed Fixing span manipulation and indentation of the suggestion introduced by #126187 2024-08-25 20:30:06 +08:00
return-from-residual-sugg-issue-125997.rs Suggest adding Result return type for associated method in E0277. 2024-07-23 10:24:45 +08:00
return-from-residual-sugg-issue-125997.stderr Tweak E0277 when predicate comes indirectly from ? 2025-02-20 18:15:39 +00:00
return-impl-trait-bad.rs
return-impl-trait-bad.stderr
return-impl-trait.fixed
return-impl-trait.rs
return-impl-trait.stderr
return-match-array-const.rs
return-match-array-const.stderr Filter empty lines, comments and delimiters from previous to last multiline span rendering 2024-12-12 23:36:27 +00:00
return-nil.rs tests: remove //@ pretty-expanded usages 2024-11-26 02:50:48 +08:00
return-struct.rs
return-struct.stderr
return-ty-mismatch-note.rs tests: update tests for more conservative return ty mismatch note 2024-06-18 21:06:53 +00:00
return-ty-mismatch-note.stderr tests: update tests for more conservative return ty mismatch note 2024-06-18 21:06:53 +00:00
return-type.rs
return-type.stderr
return-unit-from-diverging.rs
return-unit-from-diverging.stderr
suggest-a-value.rs Suggest value on bare return 2024-04-14 09:42:53 -04:00
suggest-a-value.stderr Fix 1-tuple value suggestion 2024-04-14 09:42:53 -04:00
tail-expr-as-potential-return.rs Remove MaybeForgetReturn suggestion 2025-02-22 00:04:26 +00:00
tail-expr-as-potential-return.stderr Remove MaybeForgetReturn suggestion 2025-02-22 00:04:26 +00:00
tail-expr-if-as-return.rs feat: add unit test 2024-05-16 21:10:07 +08:00
tail-expr-if-as-return.stderr feat: add unit test 2024-05-16 21:10:07 +08:00