From 3587ff58cce2f00d1be4d4e09d85b4ca9b4baff7 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 16 Oct 2018 16:46:04 +0200 Subject: [PATCH] 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`.) --- src/librustc_mir/borrow_check/mod.rs | 32 ++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index ae79394dfebe0..1f8d077fb6904 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,