]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/borrowck-macro-interaction-issue-6304.rs
rollup merge of #20482: kmcallister/macro-reform
[rust.git] / src / test / run-pass / borrowck-macro-interaction-issue-6304.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Check that we do not ICE when compiling this
12 // macro, which reuses the expression `$id`
13
14
15 struct Foo {
16   a: int
17 }
18
19 pub enum Bar {
20   Bar1, Bar2(int, Box<Bar>),
21 }
22
23 impl Foo {
24   fn elaborate_stm(&mut self, s: Box<Bar>) -> Box<Bar> {
25     macro_rules! declare {
26       ($id:expr, $rest:expr) => ({
27         self.check_id($id);
28         box Bar::Bar2($id, $rest)
29       })
30     }
31     match s {
32       box Bar::Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)),
33       _ => panic!()
34     }
35   }
36
37   fn check_id(&mut self, s: int) { panic!() }
38 }
39
40 pub fn main() { }