pub(super) fn report_illegal_reassignment(
        &mut self,
        _context: Context,
        (place, span): (&Place<'tcx>, Span),
        assigned_span: Span,
        err_place: &Place<'tcx>,
    ) {
        let (from_arg, local_decl) = if let Place::Local(local) = *err_place {
            if let LocalKind::Arg = self.mir.local_kind(local) {
                (true, Some(&self.mir.local_decls[local]))
            } else {
                (false, Some(&self.mir.local_decls[local]))
            }
        } else {
            (false, None)
        };

        // If root local is initialized immediately (everything apart from let
        // PATTERN;) then make the error refer to that local, rather than the
        // place being assigned later.
        let (place_description, assigned_span) = match local_decl {
            Some(LocalDecl {
                is_user_variable: Some(ClearCrossCrate::Clear),
                ..
            })
            | Some(LocalDecl {
                is_user_variable:
                    Some(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
                        opt_match_place: None,
                        ..
                    }))),
                ..
            })
            | Some(LocalDecl {
                is_user_variable: None,
                ..
            })
            | None => (self.describe_place(place), assigned_span),
            Some(decl) => (self.describe_place(err_place), decl.source_info.span),
        };

        let mut err = self.tcx.cannot_reassign_immutable(
            span,
            place_description.as_ref().map(AsRef::as_ref).unwrap_or("_"),
            from_arg,
            Origin::Mir,
        );
        let msg = if from_arg {
            "cannot assign to immutable argument"
        } else {
            "cannot assign twice to immutable variable"
        };
        if span != assigned_span {
            if !from_arg {
                let value_msg = match place_description {
                    Some(name) => format!("`{}`", name),
                    None => "value".to_owned(),
                };
                err.span_label(assigned_span, format!("first assignment to {}", value_msg));
            }
        }
        if let Some(decl) = local_decl {
            if let Some(name) = decl.name {
                if decl.can_be_made_mutable() {
                    err.span_label(
                        decl.source_info.span,
                        format!("consider changing this to `mut {}`", name),
                    );
                }
            }
        }
        err.span_label(span, msg);
        err.buffer(&mut self.errors_buffer);
    }
/// Reports an illegal reassignment; for example, an assignment to
/// (part of) a non-`mut` local that occurs potentially after that
/// local has already been initialized. `place` is the path being
/// assigned; `err_place` is a place providing a reason why
/// `place` is not mutable (e.g. the non-`mut` local `x` in an
/// assignment to `x.f`).
Reports an illegal reassignment; for example, an assignment to
(part of) a non-`mut` local that occurs potentially after that
local has already been initialized.
Reports an illegal reassignment ; for example an assignment to ( part of ) a non - ` mut ` local that occurs potentially after that local has already been initialized .
pub(super) fn report_illegal_reassignment(
        &mut self,
        _context: Context,
        (place, span): (&Place<'tcx>, Span),
        assigned_span: Span,
        err_place: &Place<'tcx>,
    ) {
        let (from_arg, local_decl) = if let Place::Local(local) = *err_place {
            if let LocalKind::Arg = self.mir.local_kind(local) {
                (true, Some(&self.mir.local_decls[local]))
            } else {
                (false, Some(&self.mir.local_decls[local]))
            }
        } else {
            (false, None)
        };
        // If root local is initialized immediately (everything apart from let
        // PATTERN;) then make the error refer to that local, rather than the
        // place being assigned later.
        let (place_description, assigned_span) = match local_decl {
            Some(LocalDecl {
                is_user_variable: Some(ClearCrossCrate::Clear),
                ..
            })
            | Some(LocalDecl {
                is_user_variable:
                    Some(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm {
                        opt_match_place: None,
                        ..
                    }))),
                ..
            })
            | Some(LocalDecl {
                is_user_variable: None,
                ..
            })
            | None => (self.describe_place(place), assigned_span),
            Some(decl) => (self.describe_place(err_place), decl.source_info.span),
        };
        let mut err = self.tcx.cannot_reassign_immutable(
            span,
            place_description.as_ref().map(AsRef::as_ref).unwrap_or("_"),
            from_arg,
            Origin::Mir,
        );
        let msg = if from_arg {
            "cannot assign to immutable argument"
        } else {
            "cannot assign twice to immutable variable"
        };
        if span != assigned_span {
            if !from_arg {
                let value_msg = match place_description {
                    Some(name) => format!("`{}`", name),
                    None => "value".to_owned(),
                };
                err.span_label(assigned_span, format!("first assignment to {}", value_msg));
            }
        }
        if let Some(decl) = local_decl {
            if let Some(name) = decl.name {
                if decl.can_be_made_mutable() {
                    err.span_label(
                        decl.source_info.span,
                        format!("consider changing this to `mut {}`", name),
                    );
                }
            }
        }
        err.span_label(span, msg);
        err.buffer(&mut self.errors_buffer);
    }
pub ( super ) fn report_illegal_reassignment ( & mut self , _context : Context , ( place , span ) : ( & Place < ' tcx > , Span ) , assigned_span : Span , err_place : & Place < ' tcx > , ) { let ( from_arg , local_decl ) = if let Place :: Local ( local ) = * err_place { if let LocalKind :: Arg = self . mir . local_kind ( local ) { ( true , Some ( & self . mir . local_decls [ local ] ) ) } else { ( false , Some ( & self . mir . local_decls [ local ] ) ) } } else { ( false , None ) } ; // If root local is initialized immediately (everything apart from let // PATTERN;) then make the error refer to that local, rather than the // place being assigned later. let ( place_description , assigned_span ) = match local_decl { Some ( LocalDecl { is_user_variable : Some ( ClearCrossCrate :: Clear ) , .. } ) | Some ( LocalDecl { is_user_variable : Some ( ClearCrossCrate :: Set ( BindingForm :: Var ( VarBindingForm { opt_match_place : None , .. } ) ) ) , .. } ) | Some ( LocalDecl { is_user_variable : None , .. } ) | None => ( self . describe_place ( place ) , assigned_span ) , Some ( decl ) => ( self . describe_place ( err_place ) , decl . source_info . span ) , } ; let mut err = self . tcx . cannot_reassign_immutable ( span , place_description . as_ref ( ) . map ( AsRef :: as_ref ) . unwrap_or ( " " ) , from_arg , Origin :: Mir , ) ; let msg = if from_arg { " " } else { " " } ; if span != assigned_span { if ! from_arg { let value_msg = match place_description { Some ( name ) => format ! ( " " name ) , None => " " . to_owned ( ) , } ; err . span_label ( assigned_span , format ! ( " " value_msg ) ) ; } } if let Some ( decl ) = local_decl { if let Some ( name ) = decl . name { if decl . can_be_made_mutable ( ) { err . span_label ( decl . source_info . span , format ! ( " " name ) , ) ; } } } err . span_label ( span , msg ) ; err . buffer ( & mut self . errors_buffer ) ; }
Reports an illegal reassignment; for example, an assignment to
(part of) a non-`mut` local that occurs potentially after that
local has already been initialized.
Reports an illegal reassignment ; for example an assignment to ( part of ) a non - ` mut ` local that occurs potentially after that local has already been initialized .
&mut self
_context
(&Place<'tcx>, Span)
assigned_span
Span
err_place
&Place<'tcx>
&mut self
_context
(&Place<'tcx>, Span)
assigned_span
Span
err_place
&Place<'tcx>