From 4774d5d9a112563b86e8294f6fb76dcee6577d25 Mon Sep 17 00:00:00 2001 From: Sean Patrick Santos Date: Thu, 30 Apr 2015 21:46:37 -0600 Subject: [PATCH] Allow `T::C` syntax in match patterns to refer to trait-assosociated constants. --- src/librustc_resolve/lib.rs | 7 +++++-- src/test/run-pass/associated-const-match-patterns.rs | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 447230ada2230..38ab0a8c5ed0d 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2528,8 +2528,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // If anything ends up here entirely resolved, // it's an error. If anything ends up here // partially resolved, that's OK, because it may - // be a `T::CONST` that typeck will resolve to - // an inherent impl. + // be a `T::CONST` that typeck will resolve. if path_res.depth == 0 { self.resolve_error( path.span, @@ -2537,6 +2536,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { token::get_ident( path.segments.last().unwrap().identifier))); } else { + let const_name = path.segments.last().unwrap() + .identifier.name; + let traits = self.get_traits_containing_item(const_name); + self.trait_map.insert(pattern.id, traits); self.record_def(pattern.id, path_res); } } diff --git a/src/test/run-pass/associated-const-match-patterns.rs b/src/test/run-pass/associated-const-match-patterns.rs index eeaacbf9dcc78..62e90d7a6e22b 100644 --- a/src/test/run-pass/associated-const-match-patterns.rs +++ b/src/test/run-pass/associated-const-match-patterns.rs @@ -41,6 +41,10 @@ fn main() { _ => false, }); // Trait impl + assert!(match Bar::Var1 { + Foo::THEBAR => true, + _ => false, + }); assert!(match Bar::Var1 { ::THEBAR => true, _ => false,