granite-rust/compiler
Matthias Krüger 1d9fe9cd06
Rollup merge of #90627 - camelid:suggest-box-deref, r=davidtwco
Suggest dereference of `Box` when inner type is expected

For example:

    enum Ty {
        Unit,
        List(Box<Ty>),
    }

    fn foo(x: Ty) -> Ty {
        match x {
            Ty::Unit => Ty::Unit,
            Ty::List(elem) => foo(elem),
        }
    }

Before, the only suggestion was to rewrap `inner` with `Ty::Wrapper`,
which is unhelpful and confusing:

    error[E0308]: mismatched types
     --> src/test/ui/suggestions/boxed-variant-field.rs:9:31
      |
    9 |         Ty::List(elem) => foo(elem),
      |                               ^^^^
      |                               |
      |                               expected enum `Ty`, found struct `Box`
      |                               help: try using a variant of the expected enum: `Ty::List(elem)`
      |
      = note: expected enum `Ty`
               found struct `Box<Ty>`

Now, rustc will first suggest dereferencing the `Box`, which is most
likely what the user intended:

    error[E0308]: mismatched types
     --> src/test/ui/suggestions/boxed-variant-field.rs:9:31
      |
    9 |         Ty::List(elem) => foo(elem),
      |                               ^^^^ expected enum `Ty`, found struct `Box`
      |
      = note: expected enum `Ty`
               found struct `Box<Ty>`
    help: try dereferencing the `Box`
      |
    9 |         Ty::List(elem) => foo(*elem),
      |                               +
    help: try using a variant of the expected enum
      |
    9 |         Ty::List(elem) => foo(Ty::List(elem)),
      |                               ~~~~~~~~~~~~~~

r? ``@davidtwco``
2021-11-06 23:12:04 +01:00
..
rustc Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_apfloat Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov" 2021-10-15 11:28:23 +02:00
rustc_arena Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_ast Auto merge of #90559 - rusticstuff:optimize-bidi-detection, r=davidtwco 2021-11-06 16:25:00 +00:00
rustc_ast_lowering Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr 2021-10-29 04:55:51 +00:00
rustc_ast_passes Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_ast_pretty Some "parenthesis" and "parentheses" fixes 2021-10-17 12:04:01 +02:00
rustc_attr Correct typo 2021-10-16 13:36:05 -07:00
rustc_borrowck Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr 2021-10-29 04:55:51 +00:00
rustc_builtin_macros Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_codegen_cranelift Make hash_result an Option. 2021-10-20 18:29:18 +02:00
rustc_codegen_gcc Auto merge of #89652 - rcvalle:rust-cfi, r=nagisa 2021-10-27 09:19:42 +00:00
rustc_codegen_llvm Auto merge of #90617 - tmiasko:time-trace-threads, r=wesleywiser 2021-11-06 09:55:50 +00:00
rustc_codegen_ssa Auto merge of #90641 - matthiaskrgr:mut, r=cjgillot 2021-11-06 13:19:22 +00:00
rustc_const_eval addr_of! grants mutable access, maybe? 2021-11-03 16:43:12 +01:00
rustc_data_structures Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr 2021-10-29 04:55:51 +00:00
rustc_driver Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_error_codes error_codes: uniformly comment error codes 2021-11-05 11:57:17 -04:00
rustc_errors Lint against RTL unicode codepoints in literals and comments 2021-10-31 13:14:04 +01:00
rustc_expand Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_feature Rollup merge of #90502 - GuillaumeGomez:split-doc-cfg-feature, r=jyn514 2021-11-02 23:48:50 +01:00
rustc_fs_util Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_graphviz Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov" 2021-10-15 11:28:23 +02:00
rustc_hir Auto merge of #90406 - nbdd0121:panic, r=cjgillot 2021-11-01 17:18:57 +00:00
rustc_hir_pretty Auto merge of #89124 - cjgillot:owner-info, r=michaelwoerister 2021-10-18 19:53:05 +00:00
rustc_incremental Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_index update cfg(bootstrap) 2021-10-23 21:55:57 -04:00
rustc_infer Auto merge of #89970 - jackh726:gats_diagnostics, r=nikomatsakis 2021-11-06 04:15:22 +00:00
rustc_interface Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_lexer Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov" 2021-10-15 11:28:23 +02:00
rustc_lint Optimize literal, doc comment lint as well, extract function. 2021-11-04 23:31:42 +01:00
rustc_lint_defs Properly register text_direction_codepoint_in_comment lint. 2021-11-05 20:12:40 +01:00
rustc_llvm Initialize LLVM time trace profiler on each code generation thread 2021-11-05 17:47:11 +01:00
rustc_macros Avoid a branch on key being local for queries that use the same local and extern providers 2021-10-25 13:36:23 +02:00
rustc_metadata Demote metadata load warning to "info". 2021-11-03 13:39:37 -07:00
rustc_middle Auto merge of #88441 - jackh726:closure_norm, r=nikomatsakis 2021-11-06 01:12:39 +00:00
rustc_mir_build Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_mir_dataflow Remove MaybeMutBorrowedLocals 2021-11-03 16:43:12 +01:00
rustc_mir_transform Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_monomorphize clippy::perf fixes 2021-11-04 21:07:56 +01:00
rustc_parse Remove now unused feature from rustc_parse 2021-11-04 23:40:59 +01:00
rustc_parse_format Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_passes Rollup merge of #90374 - GuillaumeGomez:unify-rustdoc-book-titles, r=camelid 2021-10-30 14:37:00 +02:00
rustc_plugin_impl Move rustc_middle::middle::cstore to rustc_session. 2021-10-03 16:08:51 +02:00
rustc_privacy Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_query_impl Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_query_system Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnr 2021-10-29 04:55:51 +00:00
rustc_resolve fix message 2021-11-03 13:53:57 +09:00
rustc_save_analysis clippy::perf fixes 2021-11-04 21:07:56 +01:00
rustc_serialize Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, r=petrochenkov" 2021-10-15 11:28:23 +02:00
rustc_session Update the documented default of -Zmutable-noalias 2021-11-05 12:01:59 -07:00
rustc_span Remove MaybeMutBorrowedLocals 2021-11-03 16:43:12 +01:00
rustc_symbol_mangling Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
rustc_target Update LLVM comments around NoAliasMutRef 2021-11-05 12:22:51 -07:00
rustc_trait_selection Auto merge of #88441 - jackh726:closure_norm, r=nikomatsakis 2021-11-06 01:12:39 +00:00
rustc_traits Move some outlives bounds things from rustc_trait_selection to rustc_typeck 2021-10-15 12:14:19 -04:00
rustc_ty_utils Auto merge of #90218 - JakobDegen:adt_significant_drop_fix, r=nikomatsakis 2021-10-28 16:03:13 +00:00
rustc_type_ir Add two inline annotations for hot functions 2021-10-03 12:43:43 -04:00
rustc_typeck Rollup merge of #90627 - camelid:suggest-box-deref, r=davidtwco 2021-11-06 23:12:04 +01:00