Skip to content

Commit

Permalink
Fix associated const resolution on structs
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 20, 2016
1 parent ceaaa1b commit d6c9aa8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -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(..) => {
Expand Down
24 changes: 22 additions & 2 deletions src/test/run-pass/associated-const-match-patterns.rs
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -43,7 +51,7 @@ fn main() {
});
// Trait impl
assert!(match Bar::Var1 {
FooWorkaround::THEBAR => true,
Foo::THEBAR => true,
_ => false,
});
assert!(match Bar::Var1 {
Expand All @@ -54,4 +62,16 @@ fn main() {
<Foo as HasBar>::THEBAR => true,
_ => false,
});
assert!(match Bar::Var1 {
XFoo::THEBAR => true,
_ => false,
});
assert!(match Bar::Var1 {
<XFoo>::THEBAR => true,
_ => false,
});
assert!(match Bar::Var1 {
<XFoo as HasBar>::THEBAR => true,
_ => false,
});
}

0 comments on commit d6c9aa8

Please sign in to comment.