Skip to content

Commit

Permalink
Allow T::C syntax in match patterns to refer to trait-assosociated …
Browse files Browse the repository at this point in the history
…constants.
  • Loading branch information
quantheory committed May 13, 2015
1 parent 222cd73 commit 4774d5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/librustc_resolve/lib.rs
Expand Up @@ -2528,15 +2528,18 @@ 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,
&format!("`{}` is not an enum variant, struct or const",
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);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/run-pass/associated-const-match-patterns.rs
Expand Up @@ -41,6 +41,10 @@ fn main() {
_ => false,
});
// Trait impl
assert!(match Bar::Var1 {
Foo::THEBAR => true,
_ => false,
});
assert!(match Bar::Var1 {
<Foo>::THEBAR => true,
_ => false,
Expand Down

0 comments on commit 4774d5d

Please sign in to comment.