rust/compiler
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
..
rustc Fix overcapturing, unsafe extern blocks, and new unsafe ops 2025-02-22 00:01:48 +00:00
rustc_abi compiler: add ExternAbi::is_rustic_abi 2025-03-04 18:21:36 -08:00
rustc_arena Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_ast Implement &pin const self and &pin mut self sugars 2025-03-05 22:37:53 +08:00
rustc_ast_ir Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_ast_lowering Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
rustc_ast_passes Implment #[cfg] and #[cfg_attr] in where clauses 2025-03-01 22:02:46 +08:00
rustc_ast_pretty Implement &pin const self and &pin mut self sugars 2025-03-05 22:37:53 +08:00
rustc_attr_data_structures Spruce up AttributeKind docs 2025-02-26 22:21:36 +00:00
rustc_attr_parsing Remove NtPath. 2025-02-28 08:42:14 +11:00
rustc_baked_icu_data Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_borrowck Use mk_ty_from_kind a bit less, clean up lifetime handling in borrowck 2025-02-28 01:27:08 +00:00
rustc_builtin_macros mgca: Lower all const paths as ConstArgKind::Path 2025-03-04 10:11:13 -05:00
rustc_codegen_cranelift Rollup merge of #137634 - tgross35:update-builtins, r=tgross35 2025-03-04 14:50:40 -08:00
rustc_codegen_gcc Auto merge of #137959 - matthiaskrgr:rollup-62vjvwr, r=matthiaskrgr 2025-03-04 02:27:56 +00:00
rustc_codegen_llvm Auto merge of #137959 - matthiaskrgr:rollup-62vjvwr, r=matthiaskrgr 2025-03-04 02:27:56 +00:00
rustc_codegen_ssa Auto merge of #135695 - Noratrieb:elf-raw-dylib, r=bjorn3 2025-03-04 15:39:44 +00:00
rustc_const_eval Rollup merge of #137804 - RalfJung:backend-repr-simd-vector, r=workingjubilee 2025-03-01 16:03:10 +01:00
rustc_data_structures Auto merge of #138031 - workingjubilee:rollup-5bsotpz, r=workingjubilee 2025-03-05 06:59:11 +00:00
rustc_driver Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_driver_impl Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_error_codes Rollup merge of #136764 - traviscross:TC/make-ptr_cast_add_auto_to_object-hard-error, r=oli-obk 2025-03-05 21:46:34 +08:00
rustc_error_messages Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_errors Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillot 2025-03-06 12:22:10 -05:00
rustc_expand Auto merge of #137959 - matthiaskrgr:rollup-62vjvwr, r=matthiaskrgr 2025-03-04 02:27:56 +00:00
rustc_feature Rollup merge of #137728 - Darksonn:no-tuple-unsize, r=oli-obk 2025-03-05 21:46:44 +08:00
rustc_fluent_macro Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_fs_util Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_graphviz Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_hashes Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_hir Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
rustc_hir_analysis Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
rustc_hir_pretty Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
rustc_hir_typeck Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillot 2025-03-06 12:22:10 -05:00
rustc_incremental Change span field accesses to method calls 2025-02-24 14:22:31 +01:00
rustc_index Rollup merge of #136610 - Jarcho:range_idx, r=Noratrieb 2025-02-24 02:11:32 -05:00
rustc_index_macros Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_infer Use Binder<Vec<T>> instead of Vec<Binder<T>> in new solver 2025-02-26 17:32:26 +00:00
rustc_interface Remove some unnecessary aliases from rustc_data_structures::sync 2025-03-03 20:20:24 +11:00
rustc_lexer Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_lint Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
rustc_lint_defs Rollup merge of #136764 - traviscross:TC/make-ptr_cast_add_auto_to_object-hard-error, r=oli-obk 2025-03-05 21:46:34 +08:00
rustc_llvm Auto merge of #133250 - DianQK:embed-bitcode-pgo, r=nikic 2025-03-01 08:22:18 +00:00
rustc_log Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_macros pretty print hir attributes 2025-02-24 14:31:19 +01:00
rustc_metadata Auto merge of #135695 - Noratrieb:elf-raw-dylib, r=bjorn3 2025-03-04 15:39:44 +00:00
rustc_middle Hide the end of ranges in pretty printing if it's also the maximum of the type 2025-03-06 10:50:23 +00:00
rustc_mir_build Make MatchPairTree::place non-optional 2025-03-05 23:26:00 +11:00
rustc_mir_dataflow Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_mir_transform Auto merge of #137907 - compiler-errors:inline-fnonce, r=saethlin 2025-03-05 18:39:17 +00:00
rustc_monomorphize compiler: use is_rustic_abi in abi_check 2025-03-04 18:23:51 -08:00
rustc_next_trait_solver Rollup merge of #137728 - Darksonn:no-tuple-unsize, r=oli-obk 2025-03-05 21:46:44 +08:00
rustc_parse Simplify parse_self_param 2025-03-05 22:50:27 +08:00
rustc_parse_format Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
rustc_passes mgca: Lower all const paths as ConstArgKind::Path 2025-03-04 10:11:13 -05:00
rustc_pattern_analysis Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
rustc_privacy Introduce new-style attribute parsers for several attributes 2025-02-24 14:31:17 +01:00
rustc_query_impl Introduce new parsing infrastructure and types for parsed attributes 2025-02-24 14:26:06 +01:00
rustc_query_system Rollup merge of #137731 - SparrowLii:waiter, r=nnethercote 2025-03-05 21:46:45 +08:00
rustc_resolve Rollup merge of #137913 - compiler-errors:struct-field-default-generic, r=BoxyUwU 2025-03-04 19:37:01 -08:00
rustc_sanitizers Introduce new-style attribute parsers for several attributes 2025-02-24 14:31:17 +01:00
rustc_serialize rename sub_ptr 😅 2025-02-23 23:11:00 +07:00
rustc_session Rollup merge of #137975 - Zalathar:needs-hir, r=compiler-errors 2025-03-04 19:37:03 -08:00
rustc_smir Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
rustc_span Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
rustc_symbol_mangling Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
rustc_target Auto merge of #135695 - Noratrieb:elf-raw-dylib, r=bjorn3 2025-03-04 15:39:44 +00:00
rustc_trait_selection Rollup merge of #137303 - compiler-errors:maybe-forgor, r=cjgillot 2025-03-06 12:22:10 -05:00
rustc_traits Only use implied bounds hack if bevy, and use deeply normalize in implied bounds hack 2025-03-04 18:18:48 +00:00
rustc_transmute Remove allow(dead_code) attributes. 2025-02-28 17:31:31 +11:00
rustc_ty_utils Remove the Option part of range ends in the HIR 2025-03-06 10:47:40 +00:00
rustc_type_ir Rollup merge of #137728 - Darksonn:no-tuple-unsize, r=oli-obk 2025-03-05 21:46:44 +08:00
rustc_type_ir_macros Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
stable_mir Make CrateItem::body() function return an option 2025-03-04 17:46:40 -08:00