Skip to content

Cannot find assert in $crate::core using [no_std] #55482

Description

@Robbepop
#![no_std]
macro_rules! foo {
    ($e:expr) => {
        $crate::core::assert!($e);
        $crate::core::assert_eq!($e, true);
    };
}
pub fn foo() { foo!(true); }

Compiling the above code generates this error message:

error[E0433]: failed to resolve. Could not find `assert` in `core`
  --> src/lib.rs:5:23
   |
5  |         $crate::core::assert!($e);
   |                       ^^^^^^ Could not find `assert` in `core`
...
13 |     foo!(true);
   |     ----------- in this macro invocation

However, this compiles:

#![no_std]
macro_rules! foo {
    ($e:expr) => {
        assert!($e); // no more `$crate::core::` path prefix!
        $crate::core::assert_eq!($e, true);
    };
}
pub fn foo() { foo!(true); }

Note that for the assert_eq invokation both versions $crate::core::assert_eq! and just assert_eq! works.

Is this intended behaviour or a bug?

Try it yourself at the playground.

Activity

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

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-langRelevant to the language teamT-libs-api[DEPRECATED; DO NOT USE]T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions