fn report_escaping_data_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
        let ErrorConstraintInfo { span, category, .. } = errci;

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

        let (_, escapes_from) = self
            .infcx
            .tcx
            .article_and_description(self.regioncx.universal_regions().defining_ty.def_id());

        // 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
                && self.regioncx.universal_regions().defining_ty.is_fn_def())
            || self.regioncx.universal_regions().defining_ty.is_const()
        {
            return self.report_general_error(&ErrorConstraintInfo {
                fr_is_local: true,
                outlived_fr_is_local: false,
                ..*errci
            });
        }

        let mut diag =
            borrowck_errors::borrowed_data_escapes_closure(self.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!(
                    "`{}` 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));
        }

        // Only show an extra note if we can find an 'error region' for both of the region
        // variables. This avoids showing a noisy note that just mentions 'synthetic' regions
        // that don't help the user understand the error.
        if self.to_error_region(errci.fr).is_some()
            && self.to_error_region(errci.outlived_fr).is_some()
        {
            let fr_region_name = self.give_region_a_name(errci.fr).unwrap();
            fr_region_name.highlight_region_name(&mut diag);
            let outlived_fr_region_name = self.give_region_a_name(errci.outlived_fr).unwrap();
            outlived_fr_region_name.highlight_region_name(&mut diag);

            diag.span_label(
                *span,
                format!(
                    "{}requires that `{}` must outlive `{}`",
                    category.description(),
                    fr_region_name,
                    outlived_fr_region_name,
                ),
            );
        }
        diag
    }
/// Reports an 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 an error specifically for when data is escaping a closure.
Reports an error specifically for when data is escaping a closure .
fn report_escaping_data_error(&self, errci: &ErrorConstraintInfo) -> DiagnosticBuilder<'tcx> {
        let ErrorConstraintInfo { span, category, .. } = errci;
        let fr_name_and_span = self.regioncx.get_var_name_and_span_for_region(
            self.infcx.tcx,
            &self.body,
            &self.local_names,
            &self.upvars,
            errci.fr,
        );
        let outlived_fr_name_and_span = self.regioncx.get_var_name_and_span_for_region(
            self.infcx.tcx,
            &self.body,
            &self.local_names,
            &self.upvars,
            errci.outlived_fr,
        );
        let (_, escapes_from) = self
            .infcx
            .tcx
            .article_and_description(self.regioncx.universal_regions().defining_ty.def_id());
        // 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
                && self.regioncx.universal_regions().defining_ty.is_fn_def())
            || self.regioncx.universal_regions().defining_ty.is_const()
        {
            return self.report_general_error(&ErrorConstraintInfo {
                fr_is_local: true,
                outlived_fr_is_local: false,
                ..*errci
            });
        }
        let mut diag =
            borrowck_errors::borrowed_data_escapes_closure(self.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!(
                    "`{}` 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));
        }
        // Only show an extra note if we can find an 'error region' for both of the region
        // variables. This avoids showing a noisy note that just mentions 'synthetic' regions
        // that don't help the user understand the error.
        if self.to_error_region(errci.fr).is_some()
            && self.to_error_region(errci.outlived_fr).is_some()
        {
            let fr_region_name = self.give_region_a_name(errci.fr).unwrap();
            fr_region_name.highlight_region_name(&mut diag);
            let outlived_fr_region_name = self.give_region_a_name(errci.outlived_fr).unwrap();
            outlived_fr_region_name.highlight_region_name(&mut diag);
            diag.span_label(
                *span,
                format!(
                    "{}requires that `{}` must outlive `{}`",
                    category.description(),
                    fr_region_name,
                    outlived_fr_region_name,
                ),
            );
        }
        diag
    }
fn report_escaping_data_error ( & self , errci : & ErrorConstraintInfo ) -> DiagnosticBuilder < ' tcx > { let ErrorConstraintInfo { span , category , .. } = errci ; let fr_name_and_span = self . regioncx . get_var_name_and_span_for_region ( self . infcx . tcx , & self . body , & self . local_names , & self . upvars , errci . fr , ) ; let outlived_fr_name_and_span = self . regioncx . get_var_name_and_span_for_region ( self . infcx . tcx , & self . body , & self . local_names , & self . upvars , errci . outlived_fr , ) ; let ( _ , escapes_from ) = self . infcx . tcx . article_and_description ( self . regioncx . universal_regions ( ) . defining_ty . def_id ( ) ) ; // 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 && self . regioncx . universal_regions ( ) . defining_ty . is_fn_def ( ) ) || self . regioncx . universal_regions ( ) . defining_ty . is_const ( ) { return self . report_general_error ( & ErrorConstraintInfo { fr_is_local : true , outlived_fr_is_local : false , .. * errci } ) ; } let mut diag = borrowck_errors :: borrowed_data_escapes_closure ( self . 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 ) ) ; } // Only show an extra note if we can find an 'error region' for both of the region // variables. This avoids showing a noisy note that just mentions 'synthetic' regions // that don't help the user understand the error. if self . to_error_region ( errci . fr ) . is_some ( ) && self . to_error_region ( errci . outlived_fr ) . is_some ( ) { let fr_region_name = self . give_region_a_name ( errci . fr ) . unwrap ( ) ; fr_region_name . highlight_region_name ( & mut diag ) ; let outlived_fr_region_name = self . give_region_a_name ( errci . outlived_fr ) . unwrap ( ) ; outlived_fr_region_name . highlight_region_name ( & mut diag ) ; diag . span_label ( * span , format ! ( " " category description ( ) fr_region_name outlived_fr_region_name ) , ) ; } diag }
Reports an error specifically for when data is escaping a closure.
Reports an error specifically for when data is escaping a closure .
&self
errci
&ErrorConstraintInfo
&self
errci
&ErrorConstraintInfo