From d6c9aa89018e24540ba017c7c77b12fe12fb233d Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 20 Jan 2016 21:08:50 +0300 Subject: [PATCH] Fix associated const resolution on structs --- src/librustc_resolve/lib.rs | 5 +++- .../associated-const-match-patterns.rs | 24 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index aebe00f3b1f62..718e12143bffa 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 b8282ae1c4dd5..605ca6b65e2cf 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() { ::THEBAR => true, _ => false, }); + assert!(match Bar::Var1 { + XFoo::THEBAR => true, + _ => false, + }); + assert!(match Bar::Var1 { + ::THEBAR => true, + _ => false, + }); + assert!(match Bar::Var1 { + ::THEBAR => true, + _ => false, + }); }