fn report_fnmut_error(
        &self,
        errctx: &ErrorReportingCtx<'_, '_, 'tcx>,
        errci: &ErrorConstraintInfo,
        renctx: &mut RegionErrorNamingCtx,
    ) -> DiagnosticBuilder<'_> {
        let ErrorConstraintInfo {
            outlived_fr, span, ..
        } = errci;

        let mut diag = errctx
            .infcx
            .tcx
            .sess
            .struct_span_err(*span, "captured variable cannot escape `FnMut` closure body");

        // We should check if the return type of this closure is in fact a closure - in that
        // case, we can special case the error further.
        let return_type_is_closure = self.universal_regions.unnormalized_output_ty.is_closure();
        let message = if return_type_is_closure {
            "returns a closure that contains a reference to a captured variable, which then \
             escapes the closure body"
        } else {
            "returns a reference to a captured variable which escapes the closure body"
        };

        diag.span_label(*span, message);

        match self.give_region_a_name(errctx, renctx, *outlived_fr).unwrap().source {
            RegionNameSource::NamedEarlyBoundRegion(fr_span)
            | RegionNameSource::NamedFreeRegion(fr_span)
            | RegionNameSource::SynthesizedFreeEnvRegion(fr_span, _)
            | RegionNameSource::CannotMatchHirTy(fr_span, _)
            | RegionNameSource::MatchedHirTy(fr_span)
            | RegionNameSource::MatchedAdtAndSegment(fr_span)
            | RegionNameSource::AnonRegionFromUpvar(fr_span, _)
            | RegionNameSource::AnonRegionFromOutput(fr_span, _, _) => {
                diag.span_label(fr_span, "inferred to be a `FnMut` closure");
            }
            _ => {}
        }

        diag.note(
            "`FnMut` closures only have access to their captured variables while they are \
             executing...",
        );
        diag.note("...therefore, they cannot allow references to captured variables to escape");

        diag
    }
/// Report a specialized error when `FnMut` closures return a reference to a captured variable.
/// This function expects `fr` to be local and `outlived_fr` to not be local.
///
/// ```text
/// error: captured variable cannot escape `FnMut` closure body
///   --> $DIR/issue-53040.rs:15:8
///    |
/// LL |     || &mut v;
///    |     -- ^^^^^^ creates a reference to a captured variable which escapes the closure body
///    |     |
///    |     inferred to be a `FnMut` closure
///    |
///    = note: `FnMut` closures only have access to their captured variables while they are
///            executing...
///    = note: ...therefore, returned references to captured variables will escape the closure
/// ```
Report a specialized error when `FnMut` closures return a reference to a captured variable.
This function expects `fr` to be local and `outlived_fr` to not be local.


Report a specialized error when ` FnMut ` closures return a reference to a captured variable . This function expects ` fr ` to be local and ` outlived_fr ` to not be local .
fn report_fnmut_error(
        &self,
        errctx: &ErrorReportingCtx<'_, '_, 'tcx>,
        errci: &ErrorConstraintInfo,
        renctx: &mut RegionErrorNamingCtx,
    ) -> DiagnosticBuilder<'_> {
        let ErrorConstraintInfo {
            outlived_fr, span, ..
        } = errci;
        let mut diag = errctx
            .infcx
            .tcx
            .sess
            .struct_span_err(*span, "captured variable cannot escape `FnMut` closure body");
        // We should check if the return type of this closure is in fact a closure - in that
        // case, we can special case the error further.
        let return_type_is_closure = self.universal_regions.unnormalized_output_ty.is_closure();
        let message = if return_type_is_closure {
            "returns a closure that contains a reference to a captured variable, which then \
             escapes the closure body"
        } else {
            "returns a reference to a captured variable which escapes the closure body"
        };
        diag.span_label(*span, message);
        match self.give_region_a_name(errctx, renctx, *outlived_fr).unwrap().source {
            RegionNameSource::NamedEarlyBoundRegion(fr_span)
            | RegionNameSource::NamedFreeRegion(fr_span)
            | RegionNameSource::SynthesizedFreeEnvRegion(fr_span, _)
            | RegionNameSource::CannotMatchHirTy(fr_span, _)
            | RegionNameSource::MatchedHirTy(fr_span)
            | RegionNameSource::MatchedAdtAndSegment(fr_span)
            | RegionNameSource::AnonRegionFromUpvar(fr_span, _)
            | RegionNameSource::AnonRegionFromOutput(fr_span, _, _) => {
                diag.span_label(fr_span, "inferred to be a `FnMut` closure");
            }
            _ => {}
        }
        diag.note(
            "`FnMut` closures only have access to their captured variables while they are \
             executing...",
        );
        diag.note("...therefore, they cannot allow references to captured variables to escape");
        diag
    }
fn report_fnmut_error ( & self , errctx : & ErrorReportingCtx < ' _ , ' _ , ' tcx > , errci : & ErrorConstraintInfo , renctx : & mut RegionErrorNamingCtx , ) -> DiagnosticBuilder < ' _ > { let ErrorConstraintInfo { outlived_fr , span , .. } = errci ; let mut diag = errctx . infcx . tcx . sess . struct_span_err ( * span , " " ) ; // We should check if the return type of this closure is in fact a closure - in that // case, we can special case the error further. let return_type_is_closure = self . universal_regions . unnormalized_output_ty . is_closure ( ) ; let message = if return_type_is_closure { " \
 " } else { " " } ; diag . span_label ( * span , message ) ; match self . give_region_a_name ( errctx , renctx , * outlived_fr ) . unwrap ( ) . source { RegionNameSource :: NamedEarlyBoundRegion ( fr_span ) | RegionNameSource :: NamedFreeRegion ( fr_span ) | RegionNameSource :: SynthesizedFreeEnvRegion ( fr_span , _ ) | RegionNameSource :: CannotMatchHirTy ( fr_span , _ ) | RegionNameSource :: MatchedHirTy ( fr_span ) | RegionNameSource :: MatchedAdtAndSegment ( fr_span ) | RegionNameSource :: AnonRegionFromUpvar ( fr_span , _ ) | RegionNameSource :: AnonRegionFromOutput ( fr_span , _ , _ ) => { diag . span_label ( fr_span , " " ) ; } _ => { } } diag . note ( " \
 " , ) ; diag . note ( " " ) ; diag }
Report a specialized error when `FnMut` closures return a reference to a captured variable.
Report a specialized error when ` FnMut ` closures return a reference to a captured variable .
&self
errctx
&ErrorReportingCtx<'_, '_, 'tcx>
errci
&ErrorConstraintInfo
renctx
&mut RegionErrorNamingCtx