Skip to content

Commit 4774d5d

Browse files
committed
Allow T::C syntax in match patterns to refer to trait-assosociated constants.
1 parent 222cd73 commit 4774d5d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/librustc_resolve/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2528,15 +2528,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
25282528
// If anything ends up here entirely resolved,
25292529
// it's an error. If anything ends up here
25302530
// partially resolved, that's OK, because it may
2531-
// be a `T::CONST` that typeck will resolve to
2532-
// an inherent impl.
2531+
// be a `T::CONST` that typeck will resolve.
25332532
if path_res.depth == 0 {
25342533
self.resolve_error(
25352534
path.span,
25362535
&format!("`{}` is not an enum variant, struct or const",
25372536
token::get_ident(
25382537
path.segments.last().unwrap().identifier)));
25392538
} else {
2539+
let const_name = path.segments.last().unwrap()
2540+
.identifier.name;
2541+
let traits = self.get_traits_containing_item(const_name);
2542+
self.trait_map.insert(pattern.id, traits);
25402543
self.record_def(pattern.id, path_res);
25412544
}
25422545
}

src/test/run-pass/associated-const-match-patterns.rs

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ fn main() {
4141
_ => false,
4242
});
4343
// Trait impl
44+
assert!(match Bar::Var1 {
45+
Foo::THEBAR => true,
46+
_ => false,
47+
});
4448
assert!(match Bar::Var1 {
4549
<Foo>::THEBAR => true,
4650
_ => false,

0 commit comments

Comments
 (0)