summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-07-01 11:37:48 +0200
committermo8it <mo8it@proton.me>2024-07-01 11:37:48 +0200
commit4cb15a4cda4791134a75a0462031b5e86b45fa0d (patch)
tree9bdda04ab2238a2e7d41ebd13ecc8393d0670bbc
parent9845e046de6f9569519d0e0ae3c50341eb35a8bf (diff)
macros3 solution
-rw-r--r--exercises/21_macros/macros3.rs4
-rw-r--r--rustlings-macros/info.toml5
-rw-r--r--solutions/21_macros/macros3.rs14
3 files changed, 16 insertions, 7 deletions
diff --git a/exercises/21_macros/macros3.rs b/exercises/21_macros/macros3.rs
index 405c397..9537494 100644
--- a/exercises/21_macros/macros3.rs
+++ b/exercises/21_macros/macros3.rs
@@ -1,5 +1,5 @@
-// Make me compile, without taking the macro out of the module!
-
+// TODO: Fix the compiler error without taking the macro definition out of this
+// module.
mod macros {
macro_rules! my_macro {
() => {
diff --git a/rustlings-macros/info.toml b/rustlings-macros/info.toml
index 7dcf344..0ec5fb2 100644
--- a/rustlings-macros/info.toml
+++ b/rustlings-macros/info.toml
@@ -1109,10 +1109,7 @@ dir = "21_macros"
test = false
hint = """
In order to use a macro outside of its module, you need to do something
-special to the module to lift the macro out into its parent.
-
-The same trick also works on "extern crate" statements for crates that have
-exported macros, if you've seen any of those around."""
+special to the module to lift the macro out into its parent."""
[[exercises]]
name = "macros4"
diff --git a/solutions/21_macros/macros3.rs b/solutions/21_macros/macros3.rs
index 4e18198..df35be4 100644
--- a/solutions/21_macros/macros3.rs
+++ b/solutions/21_macros/macros3.rs
@@ -1 +1,13 @@
-// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
+// Added the attribute `macro_use` attribute.
+#[macro_use]
+mod macros {
+ macro_rules! my_macro {
+ () => {
+ println!("Check out my macro!");
+ };
+ }
+}
+
+fn main() {
+ my_macro!();
+}