fn report_escaping_data_error(
        &self,
        errctx: &ErrorReportingCtx<'_, '_, 'tcx>,
        errci: &ErrorConstraintInfo,
        renctx: &mut RegionErrorNamingCtx,
    ) -> DiagnosticBuilder<'_> {
        let ErrorReportingCtx {
            infcx, body, upvars, local_names, ..
        } = errctx;

        let ErrorConstraintInfo {
            span, category, ..
        } = errci;

        let fr_name_and_span =
            self.get_var_name_and_span_for_region(infcx.tcx, body, local_names, upvars, errci.fr);
        let outlived_fr_name_and_span = self.get_var_name_and_span_for_region(
            infcx.tcx,
            body,
            local_names,
            upvars,
            errci.outlived_fr,
        );

        let escapes_from = match self.universal_regions.defining_ty {
            DefiningTy::Closure(..) => "closure",
            DefiningTy::Generator(..) => "generator",
            DefiningTy::FnDef(..) => "function",
            DefiningTy::Const(..) => "const",
        };

        // Revert to the normal error in these cases.
        // Assignments aren't "escapes" in function items.
        if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none())
            || (*category == ConstraintCategory::Assignment && escapes_from == "function")
            || escapes_from == "const"
        {
            return self.report_general_error(
                errctx,
                &ErrorConstraintInfo {
                    fr_is_local: true,
                    outlived_fr_is_local: false,
                    .. *errci
                },
                renctx,
            );
        }

        let mut diag = borrowck_errors::borrowed_data_escapes_closure(
            infcx.tcx,
            *span,
            escapes_from,
        );

        if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span {
            diag.span_label(
                outlived_fr_span,
                format!(
                    "`{}` is declared here, outside of the {} body",
                    outlived_fr_name, escapes_from
                ),
            );
        }

        if let Some((Some(fr_name), fr_span)) = fr_name_and_span {
            diag.span_label(
                fr_span,
                format!(
                    "`{}` is a reference that is only valid in the {} body",
                    fr_name, escapes_from
                ),
            );

            diag.span_label(
                *span,
                format!("`{}` escapes the {} body here", fr_name, escapes_from),
            );
        }

        diag
    }
/// Reports a error specifically for when data is escaping a closure.
///
/// ```text
/// error: borrowed data escapes outside of function
///   --> $DIR/lifetime-bound-will-change-warning.rs:44:5
///    |
/// LL | fn test2<'a>(x: &'a Box<Fn()+'a>) {
///    |              - `x` is a reference that is only valid in the function body
/// LL |     // but ref_obj will not, so warn.
/// LL |     ref_obj(x)
///    |     ^^^^^^^^^^ `x` escapes the function body here
/// ```
Reports a error specifically for when data is escaping a closure.
Reports a error specifically for when data is escaping a closure .
fn report_escaping_data_error(
        &self,
        errctx: &ErrorReportingCtx<'_, '_, 'tcx>,
        errci: &ErrorConstraintInfo,
        renctx: &mut RegionErrorNamingCtx,
    ) -> DiagnosticBuilder<'_> {
        let ErrorReportingCtx {
            infcx, body, upvars, local_names, ..
        } = errctx;
        let ErrorConstraintInfo {
            span, category, ..
        } = errci;
        let fr_name_and_span =
            self.get_var_name_and_span_for_region(infcx.tcx, body, local_names, upvars, errci.fr);
        let outlived_fr_name_and_span = self.get_var_name_and_span_for_region(
            infcx.tcx,
            body,
            local_names,
            upvars,
            errci.outlived_fr,
        );
        let escapes_from = match self.universal_regions.defining_ty {
            DefiningTy::Closure(..) => "closure",
            DefiningTy::Generator(..) => "generator",
            DefiningTy::FnDef(..) => "function",
            DefiningTy::Const(..) => "const",
        };
        // Revert to the normal error in these cases.
        // Assignments aren't "escapes" in function items.
        if (fr_name_and_span.is_none() && outlived_fr_name_and_span.is_none())
            || (*category == ConstraintCategory::Assignment && escapes_from == "function")
            || escapes_from == "const"
        {
            return self.report_general_error(
                errctx,
                &ErrorConstraintInfo {
                    fr_is_local: true,
                    outlived_fr_is_local: false,
                    .. *errci
                },
                renctx,
            );
        }
        let mut diag = borrowck_errors::borrowed_data_escapes_closure(
            infcx.tcx,
            *span,
            escapes_from,
        );
        if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span {
            diag.span_label(
                outlived_fr_span,
                format!(
                    "`{}` is declared here, outside of the {} body",
                    outlived_fr_name, escapes_from
                ),
            );
        }
        if let Some((Some(fr_name), fr_span)) = fr_name_and_span {
            diag.span_label(
                fr_span,
                format!(
                    "`{}` is a reference that is only valid in the {} body",
                    fr_name, escapes_from
                ),
            );
            diag.span_label(
                *span,
                format!("`{}` escapes the {} body here", fr_name, escapes_from),
            );
        }
        diag
    }
fn report_escaping_data_error ( & self , errctx : & ErrorReportingCtx < ' _ , ' _ , ' tcx > , errci : & ErrorConstraintInfo , renctx : & mut RegionErrorNamingCtx , ) -> DiagnosticBuilder < ' _ > { let ErrorReportingCtx { infcx , body , upvars , local_names , .. } = errctx ; let ErrorConstraintInfo { span , category , .. } = errci ; let fr_name_and_span = self . get_var_name_and_span_for_region ( infcx . tcx , body , local_names , upvars , errci . fr ) ; let outlived_fr_name_and_span = self . get_var_name_and_span_for_region ( infcx . tcx , body , local_names , upvars , errci . outlived_fr , ) ; let escapes_from = match self . universal_regions . defining_ty { DefiningTy :: Closure ( .. ) => " " , DefiningTy :: Generator ( .. ) => " " , DefiningTy :: FnDef ( .. ) => " " , DefiningTy :: Const ( .. ) => " " , } ; // Revert to the normal error in these cases. // Assignments aren't "escapes" in function items. if ( fr_name_and_span . is_none ( ) && outlived_fr_name_and_span . is_none ( ) ) || ( * category == ConstraintCategory :: Assignment && escapes_from == " " ) || escapes_from == " " { return self . report_general_error ( errctx , & ErrorConstraintInfo { fr_is_local : true , outlived_fr_is_local : false , .. * errci } , renctx , ) ; } let mut diag = borrowck_errors :: borrowed_data_escapes_closure ( infcx . tcx , * span , escapes_from , ) ; if let Some ( ( Some ( outlived_fr_name ) , outlived_fr_span ) ) = outlived_fr_name_and_span { diag . span_label ( outlived_fr_span , format ! ( " " outlived_fr_name escapes_from ) , ) ; } if let Some ( ( Some ( fr_name ) , fr_span ) ) = fr_name_and_span { diag . span_label ( fr_span , format ! ( " " fr_name escapes_from ) , ) ; diag . span_label ( * span , format ! ( " " fr_name escapes_from ) , ) ; } diag }
Reports a error specifically for when data is escaping a closure.
Reports a error specifically for when data is escaping a closure .
&self
errctx
&ErrorReportingCtx<'_, '_, 'tcx>
errci
&ErrorConstraintInfo
renctx
&mut RegionErrorNamingCtx