Skip to content

Commit 952f344

Browse files
committed
Auto merge of #50697 - KiChjang:issue-50461, r=pnkfelix
Use EverInit instead of MaybeInit to determine initialization Fixes #50461. Fixes #50463.
2 parents a722296 + 8b24644 commit 952f344

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
@@ -1808,9 +1808,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18081808
}
18091809
}
18101810
Reservation(WriteKind::Move)
1811+
| Write(WriteKind::Move)
18111812
| Reservation(WriteKind::StorageDeadOrDrop)
18121813
| Reservation(WriteKind::MutableBorrow(BorrowKind::Shared))
1813-
| Write(WriteKind::Move)
18141814
| Write(WriteKind::StorageDeadOrDrop)
18151815
| Write(WriteKind::MutableBorrow(BorrowKind::Shared)) => {
18161816
if let Err(_place_err) = self.is_mutable(place, is_local_mutation_allowed) {
@@ -1849,8 +1849,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18491849
// mutated, then it is justified to be annotated with the `mut`
18501850
// keyword, since the mutation may be a possible reassignment.
18511851
let mpi = self.move_data.rev_lookup.find_local(*local);
1852-
if flow_state.inits.contains(&mpi) {
1853-
self.used_mut.insert(*local);
1852+
let ii = &self.move_data.init_path_map[mpi];
1853+
for index in ii {
1854+
if flow_state.ever_inits.contains(index) {
1855+
self.used_mut.insert(*local);
1856+
}
18541857
}
18551858
}
18561859
}
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)