Skip to content

semicolon-if-nothing-returned: macro: type cannot be inferred #11277

Closed

Description

@matthiaskrgr
#![feature(custom_mir, core_intrinsics)]

extern crate core;
use core::intrinsics::mir::*;


#[repr(u8)]
enum Bool {
    False = 0,
    True = 1,
}


// EMIT_MIR enums.set_discr_repr.built.after.mir
#[custom_mir(dialect = "runtime", phase = "initial")]
fn set_discr_repr(b: &mut Bool) {
    mir!({
        SetDiscriminant(*b, 0);
        Return()
    })
}

fn main() {

}

clippy::semicolon-if-nothing-returned warns here:

warning: consider adding a `;` to the last statement for consistent formatting
  --> ./tests/mir-opt/building/custom/enums.rs:17:5
   |
17 | /     mir!({
18 | |         SetDiscriminant(*b, 0);
19 | |         Return()
20 | |     })
   | |______^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
   = note: requested on the command line with `-W clippy::semicolon-if-nothing-returned`
help: add a `;` here
   |
17 ~     mir!({
18 +         SetDiscriminant(*b, 0);
19 +         Return()
20 +     });

but if I add a semicolon, rustc find it cannot infer the type which it needs to make sure the macro does in fact return ()

error[E0282]: type annotations needed
  --> ./tests/mir-opt/building/custom/enums.rs:17:5
   |
17 | /     mir!({
18 | |         SetDiscriminant(*b, 0);
19 | |         Return()
20 | |     });
   | |______^ cannot infer type
   |
   = note: this error originates in the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)

Activity

  1. added
    T-macrosType: Issues with macros and macro expansion
    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
    on Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedT-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions