mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #39602 - estebank:fix-39544, r=eddyb
Fix ICE when accessing mutably an immutable enum Fix #39544.
This commit is contained in:
commit
e32e2d47d0
@ -202,7 +202,9 @@ impl<'tcx> cmt_<'tcx> {
|
||||
Categorization::Downcast(ref cmt, _) => {
|
||||
if let Categorization::Local(_) = cmt.cat {
|
||||
if let ty::TyAdt(def, _) = self.ty.sty {
|
||||
return def.struct_variant().find_field_named(name).map(|x| x.did);
|
||||
if def.is_struct() {
|
||||
return def.struct_variant().find_field_named(name).map(|x| x.did);
|
||||
}
|
||||
}
|
||||
None
|
||||
} else {
|
||||
|
22
src/test/ui/did_you_mean/issue-39544.rs
Normal file
22
src/test/ui/did_you_mean/issue-39544.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
enum X {
|
||||
Y
|
||||
}
|
||||
|
||||
struct Z {
|
||||
x: X
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let z = Z { x: X::Y };
|
||||
let _ = &mut z.x;
|
||||
}
|
8
src/test/ui/did_you_mean/issue-39544.stderr
Normal file
8
src/test/ui/did_you_mean/issue-39544.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
error: cannot borrow immutable field `z.x` as mutable
|
||||
--> $DIR/issue-39544.rs:21:18
|
||||
|
|
||||
21 | let _ = &mut z.x;
|
||||
| ^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user