fn report_escaping_data_error(
        &self,
        mir: &Mir<'tcx>,
        infcx: &InferCtxt<'_, '_, 'tcx>,
        mir_def_id: DefId,
        fr: RegionVid,
        outlived_fr: RegionVid,
        category: ConstraintCategory,
        span: Span,
        errors_buffer: &mut Vec<Diagnostic>,
    ) {
        let fr_name_and_span = self.get_var_name_and_span_for_region(infcx.tcx, mir, fr);
        let outlived_fr_name_and_span =
            self.get_var_name_and_span_for_region(infcx.tcx, mir, outlived_fr);

        let escapes_from = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" };

        // 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")
        {
            return self.report_general_error(mir, infcx, mir_def_id,
                                             fr, true, outlived_fr, false,
                                             category, span, errors_buffer);
        }

        let mut diag = infcx.tcx.sess.struct_span_err(
            span, &format!("borrowed data escapes outside of {}", 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.buffer(errors_buffer);
    }
/// 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,
        mir: &Mir<'tcx>,
        infcx: &InferCtxt<'_, '_, 'tcx>,
        mir_def_id: DefId,
        fr: RegionVid,
        outlived_fr: RegionVid,
        category: ConstraintCategory,
        span: Span,
        errors_buffer: &mut Vec<Diagnostic>,
    ) {
        let fr_name_and_span = self.get_var_name_and_span_for_region(infcx.tcx, mir, fr);
        let outlived_fr_name_and_span =
            self.get_var_name_and_span_for_region(infcx.tcx, mir, outlived_fr);
        let escapes_from = if infcx.tcx.is_closure(mir_def_id) { "closure" } else { "function" };
        // 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")
        {
            return self.report_general_error(mir, infcx, mir_def_id,
                                             fr, true, outlived_fr, false,
                                             category, span, errors_buffer);
        }
        let mut diag = infcx.tcx.sess.struct_span_err(
            span, &format!("borrowed data escapes outside of {}", 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.buffer(errors_buffer);
    }
fn report_escaping_data_error ( & self , mir : & Mir < ' tcx > , infcx : & InferCtxt < ' _ , ' _ , ' tcx > , mir_def_id : DefId , fr : RegionVid , outlived_fr : RegionVid , category : ConstraintCategory , span : Span , errors_buffer : & mut Vec < Diagnostic > , ) { let fr_name_and_span = self . get_var_name_and_span_for_region ( infcx . tcx , mir , fr ) ; let outlived_fr_name_and_span = self . get_var_name_and_span_for_region ( infcx . tcx , mir , outlived_fr ) ; let escapes_from = if infcx . tcx . is_closure ( mir_def_id ) { " " } else { " " } ; // 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 == " " ) { return self . report_general_error ( mir , infcx , mir_def_id , fr , true , outlived_fr , false , category , span , errors_buffer ) ; } let mut diag = infcx . tcx . sess . struct_span_err ( span , & format ! ( " " 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 . buffer ( errors_buffer ) ; }
Reports a error specifically for when data is escaping a closure.
Reports a error specifically for when data is escaping a closure .
&self
mir
&Mir<'tcx>
infcx
&InferCtxt<'_, '_, 'tcx>
mir_def_id
DefId
fr
RegionVid
outlived_fr
RegionVid
category
ConstraintCategory
span
Span
errors_buffer
&mut Vec<Diagnostic>