about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-01-13 05:27:00 +0100
committerGitHub <noreply@github.com>2019-01-13 05:27:00 +0100
commit33c5874966d4f0776f7af6e9dcb253edb985974e (patch)
tree1632c6f43a837117b2e66e2da987226d5aaf77f9
parentc04d6fa08450831ef26ad27b73345b8bbb0ac9fb (diff)
parent805099cf3eddf06f0ae6ead6f152dd1d4c37eee2 (diff)
downloadrust-33c5874966d4f0776f7af6e9dcb253edb985974e.tar.gz
rust-33c5874966d4f0776f7af6e9dcb253edb985974e.zip
Rollup merge of #57560 - petrochenkov:selfinmac, r=alexreg
hygiene: Do not treat `Self` ctor as a local variable

Fixes https://github.com/rust-lang/rust/issues/57523
-rw-r--r--src/librustc_resolve/lib.rs16
-rw-r--r--src/test/ui/resolve/issue-57523.rs21
2 files changed, 28 insertions, 9 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index f7a82c7bf4a..39be3cb7440 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 00000000000..c2a2f282542
--- /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() {}