From 805099cf3eddf06f0ae6ead6f152dd1d4c37eee2 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 13 Jan 2019 01:59:51 +0300 Subject: [PATCH] hygiene: Do not treat `Self` ctor as a local variable --- src/librustc_resolve/lib.rs | 16 +++++++--------- src/test/ui/resolve/issue-57523.rs | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 src/test/ui/resolve/issue-57523.rs diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 7c05913467c54..683c9c7c35418 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2017,16 +2017,14 @@ impl<'a> Resolver<'a> { if ident.name == keywords::Invalid.name() { return Some(LexicalScopeBinding::Def(Def::Err)); } - if ns == TypeNS { - ident.span = if ident.name == keywords::SelfUpper.name() { - // FIXME(jseyfried) improve `Self` hygiene - ident.span.with_ctxt(SyntaxContext::empty()) - } else { - ident.span.modern() - } + ident.span = if ident.name == keywords::SelfUpper.name() { + // FIXME(jseyfried) improve `Self` hygiene + ident.span.with_ctxt(SyntaxContext::empty()) + } else if ns == TypeNS { + ident.span.modern() } else { - ident = ident.modern_and_legacy(); - } + ident.span.modern_and_legacy() + }; // Walk backwards up the ribs in scope. let record_used = record_used_id.is_some(); diff --git a/src/test/ui/resolve/issue-57523.rs b/src/test/ui/resolve/issue-57523.rs new file mode 100644 index 0000000000000..c2a2f28254226 --- /dev/null +++ b/src/test/ui/resolve/issue-57523.rs @@ -0,0 +1,21 @@ +// compile-pass + +struct S(u8); + +impl S { + fn method1() -> Self { + Self(0) + } +} + +macro_rules! define_method { () => { + impl S { + fn method2() -> Self { + Self(0) // OK + } + } +}} + +define_method!(); + +fn main() {}