Skip to content

Commit 8b24644

Browse files
committed
Use EverInit instead of MaybeInit to determine initialization
1 parent dbd10f8 commit 8b24644

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/librustc_mir/borrow_check/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1810,9 +1810,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18101810
}
18111811
}
18121812
Reservation(WriteKind::Move)
1813+
| Write(WriteKind::Move)
18131814
| Reservation(WriteKind::StorageDeadOrDrop)
18141815
| Reservation(WriteKind::MutableBorrow(BorrowKind::Shared))
1815-
| Write(WriteKind::Move)
18161816
| Write(WriteKind::StorageDeadOrDrop)
18171817
| Write(WriteKind::MutableBorrow(BorrowKind::Shared)) => {
18181818
if let Err(_place_err) = self.is_mutable(place, is_local_mutation_allowed) {
@@ -1851,8 +1851,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18511851
// mutated, then it is justified to be annotated with the `mut`
18521852
// keyword, since the mutation may be a possible reassignment.
18531853
let mpi = self.move_data.rev_lookup.find_local(*local);
1854-
if flow_state.inits.contains(&mpi) {
1855-
self.used_mut.insert(*local);
1854+
let ii = &self.move_data.init_path_map[mpi];
1855+
for index in ii {
1856+
if flow_state.ever_inits.contains(index) {
1857+
self.used_mut.insert(*local);
1858+
}
18561859
}
18571860
}
18581861
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2016 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+
#![feature(nll)]
12+
#![deny(unused_mut)]
13+
14+
struct Foo {
15+
pub value: i32
16+
}
17+
18+
fn use_foo_mut(mut foo: Foo) {
19+
foo = foo;
20+
println!("{}", foo.value);
21+
}
22+
23+
fn main() {
24+
use_foo_mut(Foo { value: 413 });
25+
}

0 commit comments

Comments
 (0)