]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-7911.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / issue-7911.rs
1 // Copyright 2012-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 // ignore-pretty
12
13 // (Closes #7911) Test that we can use the same self expression
14 // with different mutability in macro in two methods
15
16 #![allow(unused_variable)] // unused foobar_immut + foobar_mut
17 trait FooBar {}
18 struct Bar(i32);
19 struct Foo { bar: Bar }
20
21 impl FooBar for Bar {}
22
23 trait Test {
24     fn get_immut(&self) -> &FooBar;
25     fn get_mut(&mut self) -> &mut FooBar;
26 }
27
28 macro_rules! generate_test { ($type_:path, $slf:ident, $field:expr) => (
29     impl Test for $type_ {
30         fn get_immut(&$slf) -> &FooBar {
31             &$field as &FooBar
32         }
33
34         fn get_mut(&mut $slf) -> &mut FooBar {
35             &mut $field as &mut FooBar
36         }
37     }
38 )}
39
40 generate_test!(Foo, self, self.bar);
41
42 pub fn main() {
43     let mut foo: Foo = Foo { bar: Bar(42) };
44     { let foobar_immut = foo.get_immut(); }
45     { let foobar_mut = foo.get_mut(); }
46 }