diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-10-16 16:46:04 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-10-16 16:58:08 +0200 |
| commit | 3587ff58cce2f00d1be4d4e09d85b4ca9b4baff7 (patch) | |
| tree | e04ed1c2169045b8fc4eeed6f3bd09ffcf11c26d /src | |
| parent | 57c467824bf72e0346fc7bc7140e232664c4e891 (diff) | |
| download | rust-3587ff58cce2f00d1be4d4e09d85b4ca9b4baff7.tar.gz rust-3587ff58cce2f00d1be4d4e09d85b4ca9b4baff7.zip | |
Don't complain re missing `mut` on attempt to partially initialize an uninitialized struct.
Under the semantics of #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`.)
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/borrow_check/mod.rs | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index ae79394dfeb..1f8d077fb69 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -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 { .. })) @@ -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, |
