Skip to content

Macro ambiguity with #![no_implicit_prelude] #151487

Description

@Slickis

Code

I tried this code:

#![no_std]
#![no_implicit_prelude]

mod foo {
    use crate::*;
    fn bar() {
        unreachable!();
    }
}

#[macro_export]
macro_rules! unreachable {
    () => {
        loop {}
    };
}

I expected to see this happen: The code should compile (no name-resolution ambiguity).

Instead, this happened: The compiler reports an ambiguity error for unreachable!() claiming a conflict between a name from a glob import and an outer scope (the prelude).

error[E0659]: `unreachable` is ambiguous
  --> src/lib.rs:7:9
   |
 7 |         unreachable!();
   |         ^^^^^^^^^^^ ambiguous name
   |
   = note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
note: `unreachable` could refer to the macro imported here
  --> src/lib.rs:5:9
   |
 5 |     use crate::*;
   |         ^^^^^^^^
   = help: consider adding an explicit import of `unreachable` to disambiguate
   = help: or use `self::unreachable` to refer to this macro unambiguously
note: `unreachable` could also refer to the macro defined here
  --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/prelude/mod.rs:59:13
   |
59 |     pub use super::v1::*;
   |             ^^^^^^^^^

Version it worked on

It most recently worked on: 1.93.0-beta.8

Version with regression

rustc --version --verbose:

rustc 1.94.0-beta.1 (9b1f8ff42 2026-01-19)
binary: rustc
commit-hash: 9b1f8ff42d110b0ca138116745be921df5dc97e7
commit-date: 2026-01-19
host: x86_64-unknown-linux-gnu
release: 1.94.0-beta.1
LLVM version: 21.1.8

Notes / additional observations:

Rust Playground:
https://play.rust-lang.org/?version=nightly&edition=2024&gist=23b9e8aa365dc3f6b4bffb840ac0c700

Removing #![no_implicit_prelude] yields the same error.
Swapping order (define macro before mod foo) makes the code compile successfully.

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, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.S-has-bisectionStatus: A bisection has been found for this issueT-langRelevant to the language teamregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions