`format!` in a `proptest!` test: "macro `format!` is not supported yet" when a local module `alloc` is in scope

Open
#239 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
devtools, testing

Research direction

Start by running the linked minimal reproducer from the issue and reading the proptest! macro expansion path in the Relax Rust JIT repository. Compare how format! is resolved inside and outside the generated test, with a local alloc module in scope. Done means the reproducer passes under relax test while preserving the shadowing module.

Written by the indexing model from the issue text.

Description

format! inside a proptest! test fails to expand when a local module named alloc is in scope:

mod gpu {
    pub mod alloc {
        pub fn bytes(n: usize) -> Vec<u8> { vec![0; n] }
    }
}
use gpu::alloc;

#[cfg(test)]
mod tests {
    use super::*;
    use proptest::prelude::*;
    proptest! {
        #[test]
        fn formats(n in 0usize..100) {
            let s = format!("{n}");
            prop_assert!(!s.is_empty());
        }
    }
}
cargo test:  test result: ok. 1 passed
relax test:  src/lib.rs:19:5: internal: macro `format!` is not supported yet

It looks like the local alloc shadows the alloc crate that format! comes from. Each of these makes it pass:

  • deleting use gpu::alloc;
  • calling format! from an ordinary function in a child module with the same use super::*;, with no proptest!.

Minimal reproducer (proptest only), checked on 193e0b6c.

Dominant language
Rust
Stars
601
Forks
34
Avg merge
1h 58m
Merged PRs (30d)
45

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from makepad/relax

All issues in makepad/relax

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.