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(semicolon_in_expressions_from_macros)]`.

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.
This commit is contained in:
Aaron Hill 2020-12-07 18:55:00 -05:00
parent 0e190206e2
commit f9025512e7
No known key found for this signature in database
GPG key ID: B4087E510E98B164
10 changed files with 150 additions and 1 deletions

View file

@ -344,6 +344,8 @@ impl<'a> ResolverExpand for Resolver<'a> {
}
fn lint_node_id(&mut self, expn_id: ExpnId) -> NodeId {
// FIXME - make this more precise. This currently returns the NodeId of the
// nearest closing item - we should try to return the closest parent of the ExpnId
self.invocation_parents
.get(&expn_id)
.map_or(ast::CRATE_NODE_ID, |id| self.def_id_to_node_id[*id])