You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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) => {letmut content :String = String::new();
content.push_str($log_type);
content.push_str($message_content);
println!("{}",&content);};($log_type:expr, $message_content:expr, $variable:expr) => {letmut 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]fnpack_logger_proce_custom(){log!("[CUSTOM]:","CUSTOM log is OK. (run with two args)");//Will fail... Why ?}
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.
The text was updated successfully, but these errors were encountered:
as far as I can tell this was a problem in previous versions of rust: Starting with rust 1.10 your code works as expected. (Looking at the release notes, the fix was probably #32923).
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.I expected to see this happen:
Instead, this happened: Nothing, an error.
Meta
rustc --version --verbose
:Backtrace (in verbose mode):
I hope this can help you, thanks for your help.
The text was updated successfully, but these errors were encountered: