]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #79819 - Aaron1011:feature/macro-trailing-semicolon, r=petrochenkov
authorYuki Okushi <huyuumi.dev@gmail.com>
Fri, 29 Jan 2021 00:17:26 +0000 (09:17 +0900)
committerGitHub <noreply@github.com>
Fri, 29 Jan 2021 00:17:26 +0000 (09:17 +0900)
Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint

cc #79813

This PR adds an allow-by-default future-compatibility lint
`SEMICOLON_IN_EXPRESSIONS_FROM_MACROS`. It fires when a trailing semicolon in a
macro body is ignored due to the macro being used in expression
position:

```rust
macro_rules! foo {
    () => {
        true; // WARN
    }
}

fn main() {
    let val = match true {
        true => false,
        _ => foo!()
    };
}
```

The lint takes its level from the macro call site, and
can be allowed for a particular macro by adding
`#[allow(macro_trailing_semicolon)]`.

The lint is set to warn for all internal rustc crates (when being built
by a stage1 compiler). After the next beta bump, we can enable
the lint for the bootstrap compiler as well.

1  2 
src/bootstrap/builder.rs

diff --combined src/bootstrap/builder.rs
index 2f655e3b396f16175906d59180ed811983ccc7e7,4b58e609f1560835e12e66523d802fb2f9cf17ec..f1a160250dbe1cbbcde70c617de27306b4c13c9c
@@@ -1139,18 -1139,10 +1139,18 @@@ impl<'a> Builder<'a> 
          // itself, we skip it by default since we know it's safe to do so in that case.
          // See https://github.com/rust-lang/rust/issues/79361 for more info on this flag.
          if target.contains("apple") {
 -            if self.config.rust_run_dsymutil {
 -                rustflags.arg("-Zrun-dsymutil=yes");
 +            if stage == 0 {
 +                if self.config.rust_run_dsymutil {
 +                    rustflags.arg("-Zrun-dsymutil=yes");
 +                } else {
 +                    rustflags.arg("-Zrun-dsymutil=no");
 +                }
              } else {
 -                rustflags.arg("-Zrun-dsymutil=no");
 +                if self.config.rust_run_dsymutil {
 +                    rustflags.arg("-Csplit-debuginfo=packed");
 +                } else {
 +                    rustflags.arg("-Csplit-debuginfo=unpacked");
 +                }
              }
          }
  
              // some code doesn't go through this `rustc` wrapper.
              lint_flags.push("-Wrust_2018_idioms");
              lint_flags.push("-Wunused_lifetimes");
+             // cfg(bootstrap): unconditionally enable this warning after the next beta bump
+             // This is currently disabled for the stage1 libstd, since build scripts
+             // will end up using the bootstrap compiler (which doesn't yet support this lint)
+             if compiler.stage != 0 && mode != Mode::Std {
+                 lint_flags.push("-Wsemicolon_in_expressions_from_macros");
+             }
  
              if self.config.deny_warnings {
                  lint_flags.push("-Dwarnings");