Skip to content

Commit df73bc9

Browse files
committed
Fix ICE when accessing mutably an immutable enum
1 parent 324b175 commit df73bc9

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/librustc/middle/mem_categorization.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ impl<'tcx> cmt_<'tcx> {
202202
Categorization::Downcast(ref cmt, _) => {
203203
if let Categorization::Local(_) = cmt.cat {
204204
if let ty::TyAdt(def, _) = self.ty.sty {
205-
return def.struct_variant().find_field_named(name).map(|x| x.did);
205+
if def.is_struct() {
206+
return def.struct_variant().find_field_named(name).map(|x| x.did);
207+
}
206208
}
207209
None
208210
} else {
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2017 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+
enum X {
12+
Y
13+
}
14+
15+
struct Z {
16+
x: X
17+
}
18+
19+
fn main() {
20+
let z = Z { x: X::Y };
21+
let _ = &mut z.x;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: cannot borrow immutable field `z.x` as mutable
2+
--> $DIR/issue-39544.rs:21:18
3+
|
4+
21 | let _ = &mut z.x;
5+
| ^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)