diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-03-24 16:00:44 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-04-14 02:28:39 +0300 |
| commit | 7e1f73beb6144503851c71b28fc50fd477afe622 (patch) | |
| tree | 206d47ca6c655f7d017236c3d119fa71fbee7e7c /src/test | |
| parent | 7291829268ced93054aa74072b074799e0e563e3 (diff) | |
| download | rust-7e1f73beb6144503851c71b28fc50fd477afe622.tar.gz rust-7e1f73beb6144503851c71b28fc50fd477afe622.zip | |
macros: Do not match on "complex" nonterminals requiring AST comparisons
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/macros/nonterminal-matching.rs | 36 | ||||
| -rw-r--r-- | src/test/ui/macros/nonterminal-matching.stderr | 11 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/test/ui/macros/nonterminal-matching.rs b/src/test/ui/macros/nonterminal-matching.rs new file mode 100644 index 00000000000..4dcb8afa94e --- /dev/null +++ b/src/test/ui/macros/nonterminal-matching.rs @@ -0,0 +1,36 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that we are refusing to match on complex nonterminals for which tokens are +// unavailable and we'd have to go through AST comparisons. + +#![feature(decl_macro, macro_lifetime_matcher)] + +macro simple_nonterminal($nt_ident: ident, $nt_lifetime: lifetime, $nt_tt: tt) { + macro n(a $nt_ident b $nt_lifetime c $nt_tt d) { + struct S; + } + + n!(a $nt_ident b $nt_lifetime c $nt_tt d); +} + +macro complex_nonterminal($nt_item: item) { + macro n(a $nt_item b) { + struct S; + } + + n!(a $nt_item b); //~ ERROR no rules expected the token `enum E { }` +} + +simple_nonterminal!(a, 'a, (x, y, z)); // OK + +complex_nonterminal!(enum E {}); + +fn main() {} diff --git a/src/test/ui/macros/nonterminal-matching.stderr b/src/test/ui/macros/nonterminal-matching.stderr new file mode 100644 index 00000000000..bf2221d52a4 --- /dev/null +++ b/src/test/ui/macros/nonterminal-matching.stderr @@ -0,0 +1,11 @@ +error: no rules expected the token `enum E { }` + --> $DIR/nonterminal-matching.rs:29:10 + | +LL | n!(a $nt_item b); //~ ERROR no rules expected the token `enum E { }` + | ^^^^^^^^ +... +LL | complex_nonterminal!(enum E {}); + | -------------------------------- in this macro invocation + +error: aborting due to previous error + |
