Closed
Description
Hi,
When I run my cargo test
command, the compiler doesn't have found my variable - she's initialized in a macro.
I tried this code:
No worries for #[macro_export]
attribute, the macro is in a module.
//We're in lib.rs file
#[macro_export]
macro_rules! log {
($log_type:expr, $message_content:expr) => {
let mut content : String = String::new();
content.push_str($log_type);
content.push_str($message_content);
println!("{}", &content);
};
($log_type:expr, $message_content:expr, $variable:expr) => {
let mut content : String = String::new();
content.push_str($log_type);
content.push_str($message_content);
content.push_str($variable);
println!("{}", &content);
};
}
// This test is in the same file which the macro's declaration..
#[test]
fn pack_logger_proce_custom()
{
log!("[CUSTOM]:", "CUSTOM log is OK. (run with two args)"); //Will fail... Why ?
}
I expected to see this happen:
[CUSTOM]: CUSTOM log is OK. (run with two args)
Instead, this happened: Nothing, an error.
Meta
rustc --version --verbose
:
rustc 1.9.0 (e4e8b6668 2016-05-18)
binary: rustc
commit-hash: e4e8b666850a763fdf1c3c2c142856ab51e32779
commit-date: 2016-05-18
host: x86_64-unknown-linux-gnu
release: 1.9.0
Backtrace (in verbose mode):
Compiling verbose_bird v0.0.1 (file:///home/songbird/Documents/RustDev/Verbose_Bird)
Running `rustc src/lib.rs --crate-name verbose_bird --crate-type lib -g --test -C metadata=08d4ada3bc6a277f -C extra-filename=-08d4ada3bc6a277f --out-dir /home/songbird/Documents/RustDev/Verbose_Bird/target/debug --emit=dep-info,link -L dependency=/home/songbird/Documents/RustDev/Verbose_Bird/target/debug -L dependency=/home/songbird/Documents/RustDev/Verbose_Bird/target/debug/deps`
src/lib.rs:21:5: 21:12 error: unresolved name `content` [E0425]
src/lib.rs:21 content.push_str($log_type);
^~~~~~~
src/lib.rs:70:2: 70:61 note: in this expansion of log! (defined in src/lib.rs)
src/lib.rs:21:5: 21:12 help: run `rustc --explain E0425` to see a detailed explanation
src/lib.rs:22:5: 22:12 error: unresolved name `content` [E0425]
src/lib.rs:22 content.push_str($message_content);
^~~~~~~
src/lib.rs:70:2: 70:61 note: in this expansion of log! (defined in src/lib.rs)
src/lib.rs:22:5: 22:12 help: run `rustc --explain E0425` to see a detailed explanation
src/lib.rs:23:21: 23:28 error: unresolved name `content` [E0425]
src/lib.rs:23 println!("{}", &content);
^~~~~~~
<std macros>:2:25: 2:56 note: in this expansion of format_args!
<std macros>:3:1: 3:54 note: in this expansion of print! (defined in <std macros>)
src/lib.rs:23:5: 23:29 note: in this expansion of println! (defined in <std macros>)
src/lib.rs:70:2: 70:61 note: in this expansion of log! (defined in src/lib.rs)
src/lib.rs:23:21: 23:28 help: run `rustc --explain E0425` to see a detailed explanation
error: aborting due to 3 previous errors
error: Could not compile `verbose_bird`.
Caused by:
Process didn't exit successfully: `rustc src/lib.rs --crate-name verbose_bird --crate-type lib -g --test -C metadata=08d4ada3bc6a277f -C extra-filename=-08d4ada3bc6a277f --out-dir /home/songbird/Documents/RustDev/Verbose_Bird/target/debug --emit=dep-info,link -L dependency=/home/songbird/Documents/RustDev/Verbose_Bird/target/debug -L dependency=/home/songbird/Documents/RustDev/Verbose_Bird/target/debug/deps` (exit code: 101)
I hope this can help you, thanks for your help.
Metadata
Metadata
Assignees
Labels
No labels