]> git.lizzy.rs Git - rust.git/commitdiff
hygiene: Do not treat `Self` ctor as a local variable
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 12 Jan 2019 22:59:51 +0000 (01:59 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 12 Jan 2019 23:18:53 +0000 (02:18 +0300)
src/librustc_resolve/lib.rs
src/test/ui/resolve/issue-57523.rs [new file with mode: 0644]

index 7c05913467c542ad7e1a0bb49c4de43dfc3684cc..683c9c7c3541807ba088bb3b570c2700ff066065 100644 (file)
@@ -2017,16 +2017,14 @@ fn resolve_ident_in_lexical_scope(&mut self,
         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 (file)
index 0000000..c2a2f28
--- /dev/null
@@ -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() {}