diff --git a/src/test/run-pass/self-unhygienic.rs b/src/test/run-pass/self-unhygienic.rs new file mode 100644 index 0000000000000..1bdd39fdeb855 --- /dev/null +++ b/src/test/run-pass/self-unhygienic.rs @@ -0,0 +1,32 @@ +// Copyright 2016 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that `self` is unhygienic + +struct A { + pub v: i64 +} + +macro_rules! pretty { + ( $t:ty, $field:ident ) => ( + impl $t { + pub fn pretty(&self) -> String { + format!("", self.$field) + } + } + ) +} + +pretty!(A, v); + +fn main() { + assert_eq!(format!("Pretty: {}", A { v: 3 }.pretty()), "Pretty: "); + println!("{}", A{ v: 42 }.pretty()); +}