Allow T::C syntax in match patterns to refer to trait-assosociated constants.

This commit is contained in:
Sean Patrick Santos 2015-04-30 21:46:37 -06:00
parent 222cd73b8a
commit 4774d5d9a1
2 changed files with 9 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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,