Skip to content

Commit

Permalink
Don't complain re missing mut on attempt to partially initialize an…
Browse files Browse the repository at this point in the history
… uninitialized struct.

Under the semantics of rust-lang#54986 (our short term plan), the partial
initialization itself will signal an error. We don't need to add noise
to the output by also complaining about `mut`. (In particular, the
user may well revise their code in a way that does not require `mut`.)
  • Loading branch information
pnkfelix committed Oct 16, 2018
1 parent 57c4678 commit 3587ff5
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1776,13 +1776,23 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
location: Location,
) -> bool {
debug!(
"check_access_permissions({:?}, {:?}, {:?})",
"check_access_permissions({:?}, {:?}, is_local_mutation_allowed: {:?})",
place, kind, is_local_mutation_allowed
);

let error_access;
let the_place_err;

// rust-lang/rust#21232, #54986: during period where we reject
// partial initialization, do not complain about mutability
// errors except for actual mutation (as opposed to an attempt
// to do a partial initialization).
let previously_initialized = if let Some(local) = place.base_local() {
self.is_local_ever_initialized(local, flow_state).is_some()
} else {
true
};

match kind {
Reservation(WriteKind::MutableBorrow(borrow_kind @ BorrowKind::Unique))
| Reservation(WriteKind::MutableBorrow(borrow_kind @ BorrowKind::Mut { .. }))
Expand Down Expand Up @@ -1875,14 +1885,18 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
}

// at this point, we have set up the error reporting state.
self.report_mutability_error(
place,
span,
the_place_err,
error_access,
location,
);
return true;
if previously_initialized {
self.report_mutability_error(
place,
span,
the_place_err,
error_access,
location,
);
return true;
} else {
return false;
}
}

fn is_local_ever_initialized(&self,
Expand Down

0 comments on commit 3587ff5

Please sign in to comment.