2 // (Closes #7911) Test that we can use the same self expression
3 // with different mutability in macro in two methods
5 #![allow(unused_variables)] // unused foobar_immut + foobar_mut
9 struct Bar(#[allow(unused_tuple_struct_fields)] i32);
10 struct Foo { bar: Bar }
12 impl FooBar for Bar {}
15 fn get_immut(&self) -> &dyn FooBar;
16 fn get_mut(&mut self) -> &mut dyn FooBar;
19 macro_rules! generate_test { ($type_:path, $slf:ident, $field:expr) => (
20 impl Test for $type_ {
21 fn get_immut(&$slf) -> &dyn FooBar {
22 &$field as &dyn FooBar
25 fn get_mut(&mut $slf) -> &mut dyn FooBar {
26 &mut $field as &mut dyn FooBar
31 generate_test!(Foo, self, self.bar);
34 let mut foo: Foo = Foo { bar: Bar(42) };
35 { let foobar_immut = foo.get_immut(); }
36 { let foobar_mut = foo.get_mut(); }