Rust: 맀크둜 ν™•μž₯에 λŒ€ν•œ μ„€λͺ…

에 λ§Œλ“  2016λ…„ 10μ›” 19일  Β·  3μ½”λ©˜νŠΈ  Β·  좜처: rust-lang/rust

macro_rules! foo_macro {
    ($name:ident) => {
        pub struct $name;
    }
}

/// Doc comment for Foo struct.
foo_macro!(Foo);

/// Doc comment for Bar struct.
foo_macro!(Bar);

이 κ°„λ‹¨ν•œ μ½”λ“œ μƒ˜ν”Œμ—μ„œ μ‚¬μš©μžλŠ” 맀크둜 ν™•μž₯을 톡해 ꡬ쑰체λ₯Ό λ§Œλ“€κ³  λͺ¨λ“  λ‹€λ₯Έ 맀크둜 ν˜ΈμΆœμ— λŒ€ν•΄ κ³ μœ ν•œ 주석을 μž‘μ„±ν•˜λ €κ³  ν•©λ‹ˆλ‹€.
이것은 struct Foo 및 Bar에 λŒ€ν•œ κ³ μœ ν•œ 주석을 μ˜λ―Έν•©λ‹ˆλ‹€. μ΄λŠ” ν˜„μž¬ Rust μ»΄νŒŒμΌλŸ¬μ—μ„œ λ‹€μŒμ„ ν™œμ„±ν™”ν•  λ•Œ κ°€λŠ₯ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

#![warn(missing_docs)]

λ‹€μŒ 경고와 ν•¨κ»˜:

warning: missing documentation for a struct
  --> src/activation_fn.rs:9:3
   |
9  |        pub struct $name;
   |        ^^^^^^^^^^^^^^^^^
...
14 | foo_macro!(Foo);
   | ---------------- in this macro invocation
   |
note: lint level defined here
  --> src/lib.rs:1:9
   |
1  | #![warn(missing_docs)]
   |         ^^^^^^^^^^^^

warning: missing documentation for a struct
  --> src/activation_fn.rs:9:3
   |
9  |        pub struct $name;
   |        ^^^^^^^^^^^^^^^^^
...
17 | foo_macro!(Bar);
   | ---------------- in this macro invocation
   |
note: lint level defined here
  --> src/lib.rs:1:9
   |
1  | #![warn(missing_docs)]
   |         ^^^^^^^^^^^^

이것은 λΆ„λͺ…νžˆ μž‘λ™ν•˜μ§€λ§Œ:

macro_rules! foo_macro {
    /// Unified comment for any macro expansion which is bad!
    ($name:ident) => {
        pub struct $name;
    }
}

foo_macro!(Foo);
foo_macro!(Bar);

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

μ—¬κΈ°μ„œ λ¬Έμ œκ°€ ν•΄κ²°λ˜μ§€ μ•Šμ€ 것 κ°™μŠ΅λ‹ˆλ‹€. ident μ‹œμž‘ν•˜λŠ” λ§€ν¬λ‘œμ— λŒ€ν•œ λ¬Έμ„œ 주석을 μž‘μ„±ν•˜λŠ” 방법

λͺ¨λ“  3 λŒ“κΈ€

λͺ¨λ“  속성(λ¬Έμ„œ 주석은 #[doc] 속성)을 전달할 수 μžˆμ§€λ§Œ μ†μ„±μ˜ 반볡 뒀에 identκ°€ 직접 올 수 μ—†κΈ° λ•Œλ¬Έμ— ꡬ문을 μ•½κ°„ λ³€κ²½ν•΄μ•Ό ν•©λ‹ˆλ‹€.

예 (놀이터)

macro_rules! foo_macro {
    ($(#[$attr:meta])* struct $name:ident) => {
        $(#[$attr])*
        pub struct $name;
    }
}

foo_macro!(
    /// Doc comment for Foo struct.
    struct Foo
);

foo_macro!(
    /// Doc comment for Bar struct.
    struct Bar
);

fn main() {
}

μ‚¬μš©μž ν¬λŸΌμ€ 이와 같은 μ§ˆλ¬Έμ— λŒ€ν•΄ ν† λ‘ ν•  수 μžˆλŠ” 쒋은 μž₯μ†Œμž…λ‹ˆλ‹€. https://users.rust-lang.org/

ꡬ체적인 버그 λ³΄κ³ μ„œλŠ” μ—¬κΈ°μ—μ„œ 맀우 ν™˜μ˜ν•©λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ 닡변이 μ™„λ£Œλ˜μ—ˆκ³  μ‚¬μš©μž ν¬λŸΌμ—μ„œ μΆ”κ°€ 토둠이 κ°€μž₯ μ’‹κΈ° λ•Œλ¬Έμ— 이 글을 λ‹«κ² μŠ΅λ‹ˆλ‹€.

μ—¬κΈ°μ„œ λ¬Έμ œκ°€ ν•΄κ²°λ˜μ§€ μ•Šμ€ 것 κ°™μŠ΅λ‹ˆλ‹€. ident μ‹œμž‘ν•˜λŠ” λ§€ν¬λ‘œμ— λŒ€ν•œ λ¬Έμ„œ 주석을 μž‘μ„±ν•˜λŠ” 방법

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰