fix: vec! macro resolution via alloc::vec self-import - #227
Conversation
c5cbc3d to
03a1781
Compare
developer0hye
left a comment
There was a problem hiding this comment.
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.
8202ad5 to
f852188
Compare
`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>
f852188 to
356869d
Compare
|
@Lokathor @developer0hye - I rebased to the latest |
|
@Lokathor would it possible to cut a release tag for me to use for our project. Thank you. |
|
Ah! Sorry I missed this behavior on these other toolchains. Thanks for fixing this up! |
|
@ravi-ciroos i use |
Problem
use alloc::vec::{self, Vec};at the top ofsrc/tinyvec.rsrelies on theselfimport also bringing thevec!macro into scope alongside thevecmodule. On some toolchains that import only resolves the module (type
namespace), not the macro, so the unqualified
vec![...]calls in this filefail to compile with:
Toolchains where this reproduces
Reproduced building
tinyvec1.13.0 (--features alloc) on all three rustcversions available to me, so it isn't specific to one release:
e408947bf59807616e48a229cea(
rustc --version --verboseoutput for each attached below.)This surfaced downstream via
unicode-normalization(pulled in transitivelythrough
lancedb→lance→lance-tokenizer), which depends ontinyvec'sallocfeature and hits this exact code path.Fix
Drainby name instead of importing thevecmodule viaself.vec!call sites (alloc::vec!and$crate::alloc::vec!inside the exportedtiny_vec!macro) so macroresolution no longer depends on the
self-import behavior.Verified
cargo build --features allocsucceeds with this change on allthree toolchains listed above.