Skip to content

Commit d6c9aa8

Browse files
committed
Fix associated const resolution on structs
1 parent ceaaa1b commit d6c9aa8

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/librustc_resolve/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27522752
};
27532753
if let Some(path_res) = resolution {
27542754
match path_res.base_def {
2755-
DefVariant(..) | DefStruct(..) | DefConst(..) => {
2755+
DefStruct(..) if path_res.depth == 0 => {
2756+
self.record_def(pattern.id, path_res);
2757+
}
2758+
DefVariant(..) | DefConst(..) => {
27562759
self.record_def(pattern.id, path_res);
27572760
}
27582761
DefStatic(..) => {

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

+22-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// aux-build:empty-struct.rs
12+
1113
#![feature(associated_consts)]
1214

15+
extern crate empty_struct;
16+
use empty_struct::XEmpty2 as XFoo;
17+
1318
struct Foo;
14-
type FooWorkaround = Foo;
1519

1620
enum Bar {
1721
Var1,
@@ -31,6 +35,10 @@ impl HasBar for Foo {
3135
const THEBAR: Bar = Bar::Var1;
3236
}
3337

38+
impl HasBar for XFoo {
39+
const THEBAR: Bar = Bar::Var1;
40+
}
41+
3442
fn main() {
3543
// Inherent impl
3644
assert!(match Bar::Var2 {
@@ -43,7 +51,7 @@ fn main() {
4351
});
4452
// Trait impl
4553
assert!(match Bar::Var1 {
46-
FooWorkaround::THEBAR => true,
54+
Foo::THEBAR => true,
4755
_ => false,
4856
});
4957
assert!(match Bar::Var1 {
@@ -54,4 +62,16 @@ fn main() {
5462
<Foo as HasBar>::THEBAR => true,
5563
_ => false,
5664
});
65+
assert!(match Bar::Var1 {
66+
XFoo::THEBAR => true,
67+
_ => false,
68+
});
69+
assert!(match Bar::Var1 {
70+
<XFoo>::THEBAR => true,
71+
_ => false,
72+
});
73+
assert!(match Bar::Var1 {
74+
<XFoo as HasBar>::THEBAR => true,
75+
_ => false,
76+
});
5777
}

0 commit comments

Comments
 (0)