Skip to content

Commit 6468292

Browse files
committed
Fix ICE with unresolved associated items in closures (fixes #28971)
1 parent a5fbb3a commit 6468292

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/librustc/middle/mem_categorization.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,18 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
11961196

11971197
(*op)(self, cmt.clone(), pat);
11981198

1199-
let opt_def = self.tcx().def_map.borrow().get(&pat.id).map(|d| d.full_def());
1199+
let opt_def = if let Some(path_res) = self.tcx().def_map.borrow().get(&pat.id) {
1200+
if path_res.depth != 0 {
1201+
// Since patterns can be associated constants
1202+
// which are resolved during typeck, we might have
1203+
// some unresolved patterns reaching this stage
1204+
// without aborting
1205+
return Err(());
1206+
}
1207+
Some(path_res.full_def())
1208+
} else {
1209+
None
1210+
};
12001211

12011212
// Note: This goes up here (rather than within the PatEnum arm
12021213
// alone) because struct patterns can refer to struct types or

src/test/compile-fail/issue-28971.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This should not cause an ICE
12+
13+
enum Foo {
14+
Bar(u8)
15+
}
16+
fn main(){
17+
foo(|| {
18+
match Foo::Bar(1) {
19+
Foo::Baz(..) => (), //~ ERROR no associated
20+
_ => (),
21+
}
22+
});
23+
}
24+
25+
fn foo<F>(f: F) where F: FnMut() {
26+
f();
27+
}

0 commit comments

Comments
 (0)