Skip to content

fix: vec! macro resolution via alloc::vec self-import - #227

Merged
Lokathor merged 1 commit into
Lokathor:mainfrom
ravi-ciroos:fix/vec-macro-scope
Sep 4, 2026
Merged

fix: vec! macro resolution via alloc::vec self-import#227
Lokathor merged 1 commit into
Lokathor:mainfrom
ravi-ciroos:fix/vec-macro-scope

Conversation

@ravi-ciroos

Copy link
Copy Markdown
Contributor

Problem

use alloc::vec::{self, Vec}; at the top of src/tinyvec.rs relies on the
self import also bringing the vec! macro into scope alongside the vec
module. On some toolchains that import only resolves the module (type
namespace), not the macro, so the unqualified vec![...] calls in this file
fail to compile with:

error: cannot find macro `vec` in this scope
   --> src/tinyvec.rs:710:21
    |
710 |       TinyVec::Heap(vec![A::Item::default(); len])
    |                     ^^^
    |
note: `vec` is imported here, but it is a module, not a macro
   --> src/tinyvec.rs:3:18
    |
  3 | use alloc::vec::{self, Vec};
    |                  ^^^^

Toolchains where this reproduces

Reproduced building tinyvec 1.13.0 (--features alloc) on all three rustc
versions available to me, so it isn't specific to one release:

rustc commit date
1.94.1 e408947bf 2026-03-25
1.95.0 59807616e 2026-04-14
1.98.1 (latest stable) 48a229cea 2026-09-01

(rustc --version --verbose output for each attached below.)

rustc 1.94.1 (e408947bf 2026-03-25)
host: aarch64-apple-darwin
LLVM version: 21.1.8

rustc 1.95.0 (59807616e 2026-04-14)
host: aarch64-apple-darwin
LLVM version: 22.1.2

rustc 1.98.1 (48a229cea 2026-09-01)
host: aarch64-apple-darwin
LLVM version: 22.1.8

This surfaced downstream via unicode-normalization (pulled in transitively
through lancedblancelance-tokenizer), which depends on
tinyvec's alloc feature and hits this exact code path.

Fix

  • Import Drain by name instead of importing the vec module via self.
  • Fully qualify the two vec! call sites (alloc::vec! and
    $crate::alloc::vec! inside the exported tiny_vec! macro) so macro
    resolution no longer depends on the self-import behavior.

Verified cargo build --features alloc succeeds with this change on all
three toolchains listed above.

@ravi-ciroos ravi-ciroos changed the title Fix vec! macro resolution via alloc::vec self-import fix: vec! macro resolution via alloc::vec self-import Sep 4, 2026

@developer0hye developer0hye left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro-specific hunk is still needed after #226. I reproduced a remaining failure on current main from a downstream #![no_std] crate:

#![no_std]
use tinyvec::{tiny_vec, TinyVec};

fn expands_to_heap() -> TinyVec<[u8; 1]> {
  tiny_vec!([u8; 1] => 1, 2)
}

The library-only check added by #226 passes, but this downstream expansion fails with cannot find macro vec in this scope. Your $crate::alloc::vec! change fixes it.

To make that fix durable, please add a #![no_std] integration target that expands the heap arm and run:

cargo check --test no_std_macro --no-default-features --features=alloc

I verified that command fails before the macro hunk and passes at 03a1781. It also coexists with the normal std test configuration. Since #226 has now merged, rebasing this PR would also make the remaining macro-only change clearer.

@ravi-ciroos
ravi-ciroos force-pushed the fix/vec-macro-scope branch 3 times, most recently from 8202ad5 to f852188 Compare September 4, 2026 01:51
`use alloc::vec::{self, Vec};` relies on the `self` import also
bringing the `vec!` macro into scope alongside the `vec` module.
On some rustc versions this only resolves the module (type
namespace), so unqualified `vec![...]` calls in this file fail
with "cannot find macro `vec` in this scope".

Import `Drain` by name instead of the `vec` module, and fully
qualify the two `vec!` invocations (`alloc::vec!` / `$crate::alloc::vec!`)
so macro resolution no longer depends on the `self`-import quirk.

Signed-off-by: Ravi Chamarthy <ravi@ciroos.ai>
@Lokathor

Lokathor commented Sep 4, 2026

Copy link
Copy Markdown
Owner

I think this came in almost exactly as I was merging and releasing #226 .

I understand that #226 wasn't a complete fix in all cases, so I'm happy to take further submissions if you rebase and adjust.

Adding a CI pass that checks this extra edge case situation would also be greatly appreciated.

@rchamarthy

Copy link
Copy Markdown

@Lokathor @developer0hye - I rebased to the latest main and updated the PR. Please review.

@Lokathor
Lokathor merged commit 77dae04 into Lokathor:main Sep 4, 2026
5 checks passed
@ravi-ciroos

Copy link
Copy Markdown
Contributor Author

@Lokathor would it possible to cut a release tag for me to use for our project. Thank you.

@andrew-signal

andrew-signal commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Ah! Sorry I missed this behavior on these other toolchains. Thanks for fixing this up!

@Lokathor

Lokathor commented Sep 4, 2026

Copy link
Copy Markdown
Owner

@ravi-ciroos i use cargo release these days so all releases get a github tag. this is in 1.13.2, if you didn't already notice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants