about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src/coverage/counters.rs
diff options
context:
space:
mode:
authorNoah Lev <camelidcamel@gmail.com>2021-11-04 23:25:16 -0700
committerNoah Lev <camelidcamel@gmail.com>2021-11-06 11:06:17 -0700
commitd93f7f93c44a7106071411224c0615c7cfcb2468 (patch)
treeb4f74ab00b6bd87f54d0bdf07d15f3bff717add1 /compiler/rustc_mir_transform/src/coverage/counters.rs
parent2cff30b17a5409e15134f8634444069fc6f21cb6 (diff)
downloadrust-d93f7f93c44a7106071411224c0615c7cfcb2468.tar.gz
rust-d93f7f93c44a7106071411224c0615c7cfcb2468.zip
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 `elem` with `Ty::List`,
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)),
      |                               ~~~~~~~~~~~~~~
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/counters.rs')
0 files changed, 0 insertions, 0 deletions