rust/compiler
Matthias Krüger 1a96f31f76
Rollup merge of #100130 - compiler-errors:erroneous-return-span, r=lcnr
Avoid pointing out `return` span if it has nothing to do with type error

This code:

```rust
fn f(_: String) {}

fn main() {
    let x = || {
        if true {
            return ();
        }
        f("");
    };
}
```

Emits this:
```
   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/main.rs:8:11
  |
8 |         f("");
  |           ^^- help: try using a conversion method: `.to_string()`
  |           |
  |           expected struct `String`, found `&str`
  |
note: return type inferred to be `String` here
 --> src/main.rs:6:20
  |
6 |             return ();
  |                    ^^
```

Specifically, that note has nothing to do with the type error in question. This is because the change implemented in #84244 tries to point out the `return` span on _any_ type coercion error within a closure that happens after a `return` statement, regardless of if the error has anything to do with it.

This is really easy to trigger -- just needs a closure (or an `async`) and an early return (or any other form, e.g. `?` operator suffices) -- and super distracting in production codebases. I'm letting #84128 regress because that issue is much harder to fix correctly, and I can re-open that issue after this lands.

As a drive-by, I added a `resolve_vars_if_possible` to the coercion error logic, which leads to some error improvements. Unrelated to the issue above, though.
2022-08-07 01:19:33 +02:00
..
rustc
rustc_apfloat
rustc_arena
rustc_ast Move LifetimeCollectVisitor to rustc_ast_lowering 2022-08-04 11:26:54 -03:00
rustc_ast_lowering Fix typo 2022-08-04 15:13:47 -03:00
rustc_ast_passes
rustc_ast_pretty Enable unused_parens for match arms 2022-08-04 07:16:39 -04:00
rustc_attr
rustc_borrowck Rollup merge of #100095 - jackh726:early-binder, r=lcnr 2022-08-04 22:25:04 +02:00
rustc_builtin_macros Rollup merge of #100058 - TaKO8Ki:suggest-positional-formatting-argument-instead-of-format-args-capture, r=estebank 2022-08-04 22:25:01 +02:00
rustc_codegen_cranelift
rustc_codegen_gcc
rustc_codegen_llvm
rustc_codegen_ssa Auto merge of #100035 - workingjubilee:merge-functions, r=nikic 2022-08-05 23:11:49 +00:00
rustc_const_eval Auto merge of #99743 - compiler-errors:fulfillment-context-cleanups, r=jackh726 2022-08-06 06:48:15 +00:00
rustc_data_structures
rustc_driver
rustc_error_codes
rustc_error_messages
rustc_errors Rollup merge of #100071 - klensy:annotate-snippets-bump, r=Mark-Simulacrum 2022-08-07 01:19:32 +02:00
rustc_expand
rustc_feature
rustc_fs_util
rustc_graphviz
rustc_hir Do not collect lifetimes with Infer resolution 2022-08-04 12:40:00 -03:00
rustc_hir_pretty
rustc_incremental
rustc_index
rustc_infer
rustc_interface
rustc_lexer
rustc_lint Rollup merge of #100093 - wcampbell0x2a:unused-parens-for-match-arms, r=petrochenkov 2022-08-04 22:25:02 +02:00
rustc_lint_defs
rustc_llvm RustWrapper: update for TypedPointerType in LLVM 2022-08-04 11:31:57 -04:00
rustc_log
rustc_macros
rustc_metadata
rustc_middle Auto merge of #99867 - spastorino:refactor-remap-lifetimes, r=nikomatsakis 2022-08-05 06:35:12 +00:00
rustc_mir_build Rollup merge of #100132 - compiler-errors:issue-100103, r=tmiasko 2022-08-06 16:15:56 +02:00
rustc_mir_dataflow
rustc_mir_transform Rollup merge of #100095 - jackh726:early-binder, r=lcnr 2022-08-04 22:25:04 +02:00
rustc_monomorphize
rustc_parse Rollup merge of #100167 - chenyukang:require-suggestion, r=estebank 2022-08-06 16:15:59 +02:00
rustc_parse_format add a comment about what we can parse now 2022-08-04 20:43:35 +09:00
rustc_passes Auto merge of #100073 - dpaoliello:externvar, r=michaelwoerister 2022-08-05 13:05:34 +00:00
rustc_plugin_impl
rustc_privacy move DiagnosticArgFromDisplay into rustc_errors 2022-08-05 16:44:01 +00:00
rustc_query_impl
rustc_query_system
rustc_resolve Add docs to generics_def_id_map 2022-08-04 11:27:03 -03:00
rustc_save_analysis
rustc_serialize
rustc_session
rustc_smir
rustc_span recover require,include instead of use in item 2022-08-05 19:20:03 +08:00
rustc_symbol_mangling
rustc_target
rustc_trait_selection Auto merge of #99743 - compiler-errors:fulfillment-context-cleanups, r=jackh726 2022-08-06 06:48:15 +00:00
rustc_traits Rollup merge of #100095 - jackh726:early-binder, r=lcnr 2022-08-04 22:25:04 +02:00
rustc_transmute
rustc_ty_utils
rustc_type_ir
rustc_typeck Rollup merge of #100130 - compiler-errors:erroneous-return-span, r=lcnr 2022-08-07 01:19:33 +02:00