Auto merge of #86574 - m-ou-se:or-pattern-lint-fix, r=petrochenkov

Don't lint :pat when re-parsing a macro from another crate.

`compile_macro` is used both when compiling the original definition in the crate that defines it, and to compile the macro when loading it when compiling a crate that uses it. We should only emit lints in the first case.

This adds a `is_definition: bool` to pass this information in, so we don't warn about things that only concern the definition site.

Fixes #86567
This commit is contained in:
bors 2021-06-25 01:23:16 +00:00
commit 079aa837d2
5 changed files with 57 additions and 37 deletions

View file

@ -0,0 +1,6 @@
#![crate_type = "lib"]
#[macro_export]
macro_rules! a {
($x:pat|) => ();
}

View file

@ -1,14 +1,19 @@
// run-rustfix
// aux-build:or-pattern.rs
#![deny(or_patterns_back_compat)]
#![allow(unused_macros)]
#[macro_use]
extern crate or_pattern;
macro_rules! foo { ($x:pat_param | $y:pat) => {} }
//~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
//~| WARN this was previously accepted
macro_rules! bar { ($($x:pat_param)+ | $($y:pat)+) => {} }
//~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
//~| WARN this was previously accepted
macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok
macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok
macro_rules! ogg { ($x:pat_param | $y:pat_param) => {} }
@ -30,4 +35,5 @@ fn main() {
let result: Result<i64, i32> = Err(42);
let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
assert_eq!(int, 42);
a!(1|);
}

View file

@ -1,14 +1,19 @@
// run-rustfix
// aux-build:or-pattern.rs
#![deny(or_patterns_back_compat)]
#![allow(unused_macros)]
#[macro_use]
extern crate or_pattern;
macro_rules! foo { ($x:pat | $y:pat) => {} }
//~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
//~| WARN this was previously accepted
macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} }
//~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
//~| WARN this was previously accepted
macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok
macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok
macro_rules! ogg { ($x:pat | $y:pat_param) => {} }
@ -30,4 +35,5 @@ fn main() {
let result: Result<i64, i32> = Err(42);
let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
assert_eq!(int, 42);
a!(1|);
}

View file

@ -1,11 +1,11 @@
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
--> $DIR/macro-or-patterns-back-compat.rs:6:21
--> $DIR/macro-or-patterns-back-compat.rs:10:21
|
LL | macro_rules! foo { ($x:pat | $y:pat) => {} }
| ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param`
|
note: the lint level is defined here
--> $DIR/macro-or-patterns-back-compat.rs:3:9
--> $DIR/macro-or-patterns-back-compat.rs:4:9
|
LL | #![deny(or_patterns_back_compat)]
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -13,7 +13,7 @@ LL | #![deny(or_patterns_back_compat)]
= note: for more information, see issue #84869 <https://github.com/rust-lang/rust/issues/84869>
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
--> $DIR/macro-or-patterns-back-compat.rs:9:23
--> $DIR/macro-or-patterns-back-compat.rs:13:23
|
LL | macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} }
| ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param`
@ -22,7 +22,7 @@ LL | macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} }
= note: for more information, see issue #84869 <https://github.com/rust-lang/rust/issues/84869>
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
--> $DIR/macro-or-patterns-back-compat.rs:14:21
--> $DIR/macro-or-patterns-back-compat.rs:19:21
|
LL | macro_rules! ogg { ($x:pat | $y:pat_param) => {} }
| ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param`
@ -31,7 +31,7 @@ LL | macro_rules! ogg { ($x:pat | $y:pat_param) => {} }
= note: for more information, see issue #84869 <https://github.com/rust-lang/rust/issues/84869>
error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
--> $DIR/macro-or-patterns-back-compat.rs:18:26
--> $DIR/macro-or-patterns-back-compat.rs:23:26
|
LL | ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
| ^^^^^^^^ help: use pat_param to preserve semantics: `$pat:pat_param`