nonempty
nonempty copied to clipboard
Use vec![] for instantiate an empty vector in nonempty! macro
It fixes https://github.com/cloudhead/nonempty/issues/68
I hope using vec![] should not be a big problem, cause vec![] is already used in another branch of the macro.
Thank you again for you work!
Thanks for the contribution! @nuttycom would vec! work here, or would that mean that std is required? It seems like the no-std builds successfully, so perhaps it's fine!
@FintanH
vec![] is already used in another branch of the macro, so I would assume it does not make it worse :D
Hmmm, I am not sure here. I think the existing use of vec may actually
be a bug, I just didn’t notice it because there there are no uses of the
nonempty macro in a context where no-std is enforced and not
automatically enabled.
vec! itself is part of std:
https://doc.rust-lang.org/std/macro.vec.html
So it could be that you can’t use the macro in a no-std context, but because it’s a macro if it’s never used there is no problem.
What is probably needed to demonstrate the issue is a CI task like the one
I added here:
https://github.com/zcash/orchard/pull/450 but with the generated lib.rs file containing some code that invokes the nonempty macro.
I'm not sure what the best way to make sure that extern crate alloc is added to the generated code is, though.
On Mon, Jan 6, 2025 at 8:18 PM Serhii Potapov @.***> wrote:
@FintanH https://github.com/FintanH
vec![] is already used in another branch of the macro, so I would assume it does not make it worse :D
image.png (view on web) https://github.com/user-attachments/assets/1acb9b23-78dd-4daf-8b89-b61ccadac33d
— Reply to this email directly, view it on GitHub https://github.com/cloudhead/nonempty/pull/69#issuecomment-2573659181, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAGXR3Q6OZKCU7KUAWHZC32JLCHVAVCNFSM6AAAAABUB3IE6GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNZTGY2TSMJYGE . You are receiving this because you were mentioned.Message ID: @.***>
vec!itself is part ofstd
It is actually part of alloc: https://doc.rust-lang.org/alloc/macro.vec.html
It looks like it requires a #[macro_use] on alloc to compile, take a look at this example:
#![no_std]
#[macro_use]
extern crate alloc;
fn main() {
vec![0];
}
Ok, so afaiu this change is fine because the no-std actions check uses --no-default-features which means that std is not enabled, and all other dependencies are optional – so also not enabled – and it passes just fine :) I'll merge and push a hotfix version
@FintanH Thanks!
Resolved in https://github.com/cloudhead/nonempty/pull/70