Change std macro calls to be fully qualified #469
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes calls like
format!
andvec!
within insta's macros to bestd::format!
andstd::vec!
. I ran into this issue in a crate wherestd's prelude isn't enabled, even in tests. While perhaps a bit of a
niche case, I don't think this fix has any downsides.
The specific kind of error that happens is if you use
insta::assert_snapshot!
(or similar) and the (for example)format!
macro isn't in scope. Here's a small example. First a
Cargo.toml
:And now
lib.rs
:(EDIT: I forgot to include the
#![no_std]
attribute when I originally wrote this. I've included it now.)And now here's what happens when you try to build it:
This can be pretty easily worked around by adding
use std::format;
sothat the macro can call it. But I figure it's better to just have the
macros do the right thing by default. Moreover, I suspect this is also
important in other (perhaps strange) contexts where there is a custom
format!
macro defined and in scope.insta
would use the custom macroinstead of the one from
std
. But with this change, it will always usethe one from
std
.