Skip to content

error: cannot determine resolution for the macro itself is not stably triggering on 1.97.1 #160195

Description

@shirok1

src/lib.rs

#[cfg(feature = "env-first")]
pub mod env;

// This declaration-before-`env` order is part of the rustc regression.
pub mod interface {
    mod wasm {
        #[allow(unused_imports)]
        use crate::env::{self};

        #[cfg(not(feature = "qualified-env"))]
        include!(concat!(env!("OUT_DIR"), "/wit/dom_export.rs"));

        #[cfg(feature = "qualified-env")]
        include!(concat!(core::env!("OUT_DIR"), "/wit/dom_export.rs"));

        // This child scope survives and drives rustc's `dom_import` suggestion.
        pub mod dom_import {
            include!(concat!(env!("OUT_DIR"), "/wit/dom_import.rs"));
        }

        #[allow(dead_code)]
        struct DomExport;
        impl dom_export::DomExport for DomExport {}
    }

    pub use wasm::*;
}

#[cfg(not(feature = "env-first"))]
pub mod env;

src/env.rs

#[derive(Default)]
#[allow(dead_code)]
pub struct BusinessData;

build.rs

use std::{env, fs, path::PathBuf};

fn main() {
    let output = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("wit");
    fs::create_dir_all(&output).unwrap();

    fs::write(
        output.join("dom_export.rs"),
        "pub mod dom_export { pub trait DomExport {} }\n",
    )
    .unwrap();
    fs::write(
        output.join("dom_import.rs"),
        "pub mod dom_import { pub trait DomImport {} }\n",
    )
    .unwrap();
}

Building:

$ cargo +1.96.1 build
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s

$ cargo +1.97.1 build
error: cannot determine resolution for the macro `env`
  --> src/lib.rs:11:26
   |
11 |         include!(concat!(env!("OUT_DIR"), "/wit/dom_export.rs"));
   |                          ^^^
   |
   = note: import resolution is stuck, try simplifying macro imports

error[E0433]: cannot find module or crate `dom_export` in this scope
  --> src/lib.rs:23:14
   |
23 |         impl dom_export::DomExport for DomExport {}
   |              ^^^^^^^^^^ use of unresolved module or unlinked crate `dom_export`
   |
help: there is a crate or module with a similar name
   |
23 -         impl dom_export::DomExport for DomExport {}
23 +         impl dom_import::DomExport for DomExport {}
   |

For more information about this error, try `rustc --explain E0433`.
error: could not compile `xxx` (lib) due to 2 previous errors

$ cargo +1.97.1 build --features env-first
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s

$ cargo +1.97.1 build  --features qualified-env
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s

If error: cannot determine resolution for the macro is an intended feature of 1.97, it should not be affected by the mod declaring order

Workaround: fully qualify to core::env! or just don't name the mod env and import it

Detail version:

$ rustc +1.97.1 -vV
rustc 1.97.1 (8bab26f4f 2026-07-14)
binary: rustc
commit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452
commit-date: 2026-07-14
host: aarch64-apple-darwin
release: 1.97.1
LLVM version: 22.1.6

$ rustc +1.96.1 -vV
rustc 1.96.1 (31fca3adb 2026-06-26)
binary: rustc
commit-hash: 31fca3adb283cc9dfd56b49cdee9a96eb9c96ffd
commit-date: 2026-06-26
host: aarch64-apple-darwin
release: 1.96.1
LLVM version: 22.1.2

Disclosure: this minimal reproduce is generated with GPT-5.6 Sol from diagnose log

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions