From 247b3b6e6524f737e3d092797af4a574748376aa Mon Sep 17 00:00:00 2001 From: Joel Self Date: Thu, 16 Jun 2016 21:32:54 -0600 Subject: [PATCH 1/2] Added a test to check that self can be used in a macro without having to be specified as an argument. --- src/test/run-pass/self-unhygienic.rs | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/test/run-pass/self-unhygienic.rs diff --git a/src/test/run-pass/self-unhygienic.rs b/src/test/run-pass/self-unhygienic.rs new file mode 100644 index 0000000000000..3c1061a0f68ed --- /dev/null +++ b/src/test/run-pass/self-unhygienic.rs @@ -0,0 +1,31 @@ +// 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: "); +} \ No newline at end of file From 28e036bcb37e4bc833baa5b7d2f8b285e058ee2c Mon Sep 17 00:00:00 2001 From: Joel Self Date: Thu, 16 Jun 2016 23:36:24 -0600 Subject: [PATCH 2/2] Add newline at the end of the file. --- src/test/run-pass/self-unhygienic.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/run-pass/self-unhygienic.rs b/src/test/run-pass/self-unhygienic.rs index 3c1061a0f68ed..1bdd39fdeb855 100644 --- a/src/test/run-pass/self-unhygienic.rs +++ b/src/test/run-pass/self-unhygienic.rs @@ -28,4 +28,5 @@ pretty!(A, v); fn main() { assert_eq!(format!("Pretty: {}", A { v: 3 }.pretty()), "Pretty: "); -} \ No newline at end of file + println!("{}", A{ v: 42 }.pretty()); +}