]> git.lizzy.rs Git - rust.git/commitdiff
Suggest the `pat_param` specifier before `|` on 2021 edition
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Tue, 30 Nov 2021 06:14:38 +0000 (22:14 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Tue, 30 Nov 2021 06:20:34 +0000 (22:20 -0800)
We have a migration warning but no lint for users who have enabled the
new edition.

compiler/rustc_expand/src/mbe/macro_rules.rs

index f8491654f39e31301bd74aad8465c9a0e80aa708..537a10e98e59de2dcf0c11c0beac366c47de7511 100644 (file)
@@ -1027,6 +1027,24 @@ fn check_matcher_core(
                                 ),
                             );
                             err.span_label(sp, format!("not allowed after `{}` fragments", kind));
+
+                            if kind == NonterminalKind::PatWithOr
+                                && sess.edition == Edition::Edition2021
+                                && next_token.is_token(&BinOp(token::BinOpToken::Or))
+                            {
+                                let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(
+                                    span,
+                                    name,
+                                    Some(NonterminalKind::PatParam { inferred: false }),
+                                ));
+                                err.span_suggestion(
+                                    span,
+                                    &format!("try a `pat_param` fragment specifier instead"),
+                                    suggestion,
+                                    Applicability::MaybeIncorrect,
+                                );
+                            }
+
                             let msg = "allowed there are: ";
                             match possible {
                                 &[] => {}