Skip to content

panic! macro should be an expression returning ! (Never type) #268

@Dirbaio

Description

@Dirbaio

Code like this fails to compile, while it compiles with std panic!().

    let foo: u32 = match version {
        4 => 123,
        5 => 456,
        _ => defmt::panic!("unknown version {:?}", version),
    };
error: macro expansion ignores token `;` and any following
  --> firmware/qemu/src/bin/panic.rs:14:14
   |
14 |         _ => defmt::panic!("unknown version {:?}", version),
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: you might be missing a semicolon here: `;`
   |              |
   |              caused by the macro expansion here
   |
   = note: the usage of `defmt::panic!` is likely invalid in expression context

error[E0308]: mismatched types
  --> firmware/qemu/src/bin/panic.rs:14:14
   |
14 |         _ => defmt::panic!("unknown version {:?}", version),
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `()`
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions