about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-01-20 21:08:50 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-01-20 21:50:57 +0300
commitd6c9aa89018e24540ba017c7c77b12fe12fb233d (patch)
tree566cea5b5ed04fc1737351ac2a17538f05e901cb
parentceaaa1bc3388e9a198af198729a6a8821ce54ffb (diff)
downloadrust-d6c9aa89018e24540ba017c7c77b12fe12fb233d.tar.gz
rust-d6c9aa89018e24540ba017c7c77b12fe12fb233d.zip
Fix associated const resolution on structs
-rw-r--r--src/librustc_resolve/lib.rs5
-rw-r--r--src/test/run-pass/associated-const-match-patterns.rs24
2 files changed, 26 insertions, 3 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index aebe00f3b1f..718e12143bf 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -2752,7 +2752,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
                     };
                     if let Some(path_res) = resolution {
                         match path_res.base_def {
-                            DefVariant(..) | DefStruct(..) | DefConst(..) => {
+                            DefStruct(..) if path_res.depth == 0 => {
+                                self.record_def(pattern.id, path_res);
+                            }
+                            DefVariant(..) | DefConst(..) => {
                                 self.record_def(pattern.id, path_res);
                             }
                             DefStatic(..) => {
diff --git a/src/test/run-pass/associated-const-match-patterns.rs b/src/test/run-pass/associated-const-match-patterns.rs
index b8282ae1c4d..605ca6b65e2 100644
--- a/src/test/run-pass/associated-const-match-patterns.rs
+++ b/src/test/run-pass/associated-const-match-patterns.rs
@@ -8,10 +8,14 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// aux-build:empty-struct.rs
+
 #![feature(associated_consts)]
 
+extern crate empty_struct;
+use empty_struct::XEmpty2 as XFoo;
+
 struct Foo;
-type FooWorkaround = Foo;
 
 enum Bar {
     Var1,
@@ -31,6 +35,10 @@ impl HasBar for Foo {
     const THEBAR: Bar = Bar::Var1;
 }
 
+impl HasBar for XFoo {
+    const THEBAR: Bar = Bar::Var1;
+}
+
 fn main() {
     // Inherent impl
     assert!(match Bar::Var2 {
@@ -43,7 +51,7 @@ fn main() {
     });
     // Trait impl
     assert!(match Bar::Var1 {
-        FooWorkaround::THEBAR => true,
+        Foo::THEBAR => true,
         _ => false,
     });
     assert!(match Bar::Var1 {
@@ -54,4 +62,16 @@ fn main() {
         <Foo as HasBar>::THEBAR => true,
         _ => false,
     });
+    assert!(match Bar::Var1 {
+        XFoo::THEBAR => true,
+        _ => false,
+    });
+    assert!(match Bar::Var1 {
+        <XFoo>::THEBAR => true,
+        _ => false,
+    });
+    assert!(match Bar::Var1 {
+        <XFoo as HasBar>::THEBAR => true,
+        _ => false,
+    });
 }