Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the unused macros warning?

Tags:

macros

rust

This code:

#[allow(dead_code)]
macro_rules! test {
    ($x:expr) => {{}}
}

fn main() {

    println!("Results:")

}

produces the following warning about unused macro definition:

warning: unused macro definition
  --> /home/xxx/.emacs.d/rust-playground/at-2017-08-02-031315/snippet.rs:10:1
   |
10 | / macro_rules! test {
11 | |     ($x:expr) => {{}}
12 | | }
   | |_^
   |
   = note: #[warn(unused_macros)] on by default

Is it possible to suppress it? As you can see #[allow(dead_code) doesn't help in case of macros.

like image 892
user1244932 Avatar asked Aug 02 '17 00:08

user1244932


People also ask

How do I close the security warning for macros?

If the source of the file is unknown and you don't want to enable macros, you can click the 'X' button to close the security warning. The warning will disappear, but macros will remain disabled. Any attempt to run a macro will result in the following message.

How to disable macros in Excel without notification?

How to disable macros in Excel 1 In your Excel, click the File tab > Options. 2 On the left-side pane, select Trust Center, and then click Trust Center Settings… . 3 In the left menu, select Macro Settings, choose Disable all macros without notification, and click OK. More ...

Is there a way to force the user to enable macros?

Because macro security is critical for the security of Excel, Microsoft designed any VBA code to only be triggered by a user click. However, when Microsoft closes a door, the user opens a window :) As a workaround, someone suggested a way to force the user to enable macros with a kind of "splash screen" or "instruction sheet".

How do I enable macros for the duration of the file?

The following instructions will guide you through the steps to enable macros for the duration that the file is open: 1 Click the File tab > Info. 2 In the Security Warning area, click Enable Content > Advanced Options. 3 In the Microsoft Office Security Options dialog box, select Enable content for this session, and click OK.


1 Answers

The compiler warning states:

= note: #[warn(unused_macros)] on by default

Which is very similar to the warning caused by unused functions:

= note: #[warn(dead_code)] on by default

You can disable these warnings in the same way, but you need to use the matching macro attribute:

#[allow(unused_macros)]
macro_rules! test {
    ($x:expr) => {{}}
}
like image 59
ljedrz Avatar answered Nov 23 '22 13:11

ljedrz