crate fn add_suggestion<'tcx>(
        &self,
        body: &Body<'tcx>,
        region_infcx: &RegionInferenceContext<'tcx>,
        infcx: &InferCtxt<'_, 'tcx>,
        errors_buffer: &mut Vec<Diagnostic>,
        renctx: &mut RegionErrorNamingCtx,
    ) {
        // No constraints to add? Done.
        if self.constraints_to_add.is_empty() {
            debug!("No constraints to suggest.");
            return;
        }

        // If there is only one constraint to suggest, then we already suggested it in the
        // intermediate suggestion above.
        if self.constraints_to_add.len() == 1 {
            debug!("Only 1 suggestion. Skipping.");
            return;
        }

        // Get all suggestable constraints.
        let suggested = self.compile_all_suggestions(body, region_infcx, infcx, renctx);

        // If there are no suggestable constraints...
        if suggested.is_empty() {
            debug!("Only 1 suggestable constraint. Skipping.");
            return;
        }

        // If there is exactly one suggestable constraints, then just suggest it. Otherwise, emit a
        // list of diagnostics.
        let mut diag = if suggested.len() == 1 {
            infcx.tcx.sess.diagnostic().struct_help(&match suggested.last().unwrap() {
                SuggestedConstraint::Outlives(a, bs) => {
                    let bs: SmallVec<[String; 2]> = bs.iter().map(|r| format!("{}", r)).collect();
                    format!("add bound `{}: {}`", a, bs.join(" + "))
                }

                SuggestedConstraint::Equal(a, b) => {
                    format!("`{}` and `{}` must be the same: replace one with the other", a, b)
                }
                SuggestedConstraint::Static(a) => format!("replace `{}` with `'static`", a),
            })
        } else {
            // Create a new diagnostic.
            let mut diag = infcx
                .tcx
                .sess
                .diagnostic()
                .struct_help("the following changes may resolve your lifetime errors");

            // Add suggestions.
            for constraint in suggested {
                match constraint {
                    SuggestedConstraint::Outlives(a, bs) => {
                        let bs: SmallVec<[String; 2]> =
                            bs.iter().map(|r| format!("{}", r)).collect();
                        diag.help(&format!("add bound `{}: {}`", a, bs.join(" + ")));
                    }
                    SuggestedConstraint::Equal(a, b) => {
                        diag.help(&format!(
                            "`{}` and `{}` must be the same: replace one with the other",
                            a, b
                        ));
                    }
                    SuggestedConstraint::Static(a) => {
                        diag.help(&format!("replace `{}` with `'static`", a));
                    }
                }
            }

            diag
        };

        // We want this message to appear after other messages on the mir def.
        let mir_span = infcx.tcx.def_span(self.mir_def_id);
        diag.sort_span = mir_span.shrink_to_hi();

        // Buffer the diagnostic
        diag.buffer(errors_buffer);
    }
/// If there is a suggestion to emit, add a diagnostic to the buffer. This is the final
/// suggestion including all collected constraints.
If there is a suggestion to emit, add a diagnostic to the buffer. This is the final
suggestion including all collected constraints.
If there is a suggestion to emit add a diagnostic to the buffer . This is the final suggestion including all collected constraints .
crate fn add_suggestion<'tcx>(
        &self,
        body: &Body<'tcx>,
        region_infcx: &RegionInferenceContext<'tcx>,
        infcx: &InferCtxt<'_, 'tcx>,
        errors_buffer: &mut Vec<Diagnostic>,
        renctx: &mut RegionErrorNamingCtx,
    ) {
        // No constraints to add? Done.
        if self.constraints_to_add.is_empty() {
            debug!("No constraints to suggest.");
            return;
        }
        // If there is only one constraint to suggest, then we already suggested it in the
        // intermediate suggestion above.
        if self.constraints_to_add.len() == 1 {
            debug!("Only 1 suggestion. Skipping.");
            return;
        }
        // Get all suggestable constraints.
        let suggested = self.compile_all_suggestions(body, region_infcx, infcx, renctx);
        // If there are no suggestable constraints...
        if suggested.is_empty() {
            debug!("Only 1 suggestable constraint. Skipping.");
            return;
        }
        // If there is exactly one suggestable constraints, then just suggest it. Otherwise, emit a
        // list of diagnostics.
        let mut diag = if suggested.len() == 1 {
            infcx.tcx.sess.diagnostic().struct_help(&match suggested.last().unwrap() {
                SuggestedConstraint::Outlives(a, bs) => {
                    let bs: SmallVec<[String; 2]> = bs.iter().map(|r| format!("{}", r)).collect();
                    format!("add bound `{}: {}`", a, bs.join(" + "))
                }
                SuggestedConstraint::Equal(a, b) => {
                    format!("`{}` and `{}` must be the same: replace one with the other", a, b)
                }
                SuggestedConstraint::Static(a) => format!("replace `{}` with `'static`", a),
            })
        } else {
            // Create a new diagnostic.
            let mut diag = infcx
                .tcx
                .sess
                .diagnostic()
                .struct_help("the following changes may resolve your lifetime errors");
            // Add suggestions.
            for constraint in suggested {
                match constraint {
                    SuggestedConstraint::Outlives(a, bs) => {
                        let bs: SmallVec<[String; 2]> =
                            bs.iter().map(|r| format!("{}", r)).collect();
                        diag.help(&format!("add bound `{}: {}`", a, bs.join(" + ")));
                    }
                    SuggestedConstraint::Equal(a, b) => {
                        diag.help(&format!(
                            "`{}` and `{}` must be the same: replace one with the other",
                            a, b
                        ));
                    }
                    SuggestedConstraint::Static(a) => {
                        diag.help(&format!("replace `{}` with `'static`", a));
                    }
                }
            }
            diag
        };
        // We want this message to appear after other messages on the mir def.
        let mir_span = infcx.tcx.def_span(self.mir_def_id);
        diag.sort_span = mir_span.shrink_to_hi();
        // Buffer the diagnostic
        diag.buffer(errors_buffer);
    }
crate fn add_suggestion < ' tcx > ( & self , body : & Body < ' tcx > , region_infcx : & RegionInferenceContext < ' tcx > , infcx : & InferCtxt < ' _ , ' tcx > , errors_buffer : & mut Vec < Diagnostic > , renctx : & mut RegionErrorNamingCtx , ) { // No constraints to add? Done. if self . constraints_to_add . is_empty ( ) { debug ! ( " " ) ; return ; } // If there is only one constraint to suggest, then we already suggested it in the // intermediate suggestion above. if self . constraints_to_add . len ( ) == 1 { debug ! ( " " ) ; return ; } // Get all suggestable constraints. let suggested = self . compile_all_suggestions ( body , region_infcx , infcx , renctx ) ; // If there are no suggestable constraints... if suggested . is_empty ( ) { debug ! ( " " ) ; return ; } // If there is exactly one suggestable constraints, then just suggest it. Otherwise, emit a // list of diagnostics. let mut diag = if suggested . len ( ) == 1 { infcx . tcx . sess . diagnostic ( ) . struct_help ( & match suggested . last ( ) . unwrap ( ) { SuggestedConstraint :: Outlives ( a , bs ) => { let bs : SmallVec < [ String ; 2 ] > = bs . iter ( ) . map ( | r | format ! ( " " r ) ) . collect ( ) ; format ! ( " " a bs join ( " " ) ) } SuggestedConstraint :: Equal ( a , b ) => { format ! ( " " a b ) } SuggestedConstraint :: Static ( a ) => format ! ( " " a ) , } ) } else { // Create a new diagnostic. let mut diag = infcx . tcx . sess . diagnostic ( ) . struct_help ( " " ) ; // Add suggestions. for constraint in suggested { match constraint { SuggestedConstraint :: Outlives ( a , bs ) => { let bs : SmallVec < [ String ; 2 ] > = bs . iter ( ) . map ( | r | format ! ( " " r ) ) . collect ( ) ; diag . help ( & format ! ( " " a bs join ( " " ) ) ) ; } SuggestedConstraint :: Equal ( a , b ) => { diag . help ( & format ! ( " " a b ) ) ; } SuggestedConstraint :: Static ( a ) => { diag . help ( & format ! ( " " a ) ) ; } } } diag } ; // We want this message to appear after other messages on the mir def. let mir_span = infcx . tcx . def_span ( self . mir_def_id ) ; diag . sort_span = mir_span . shrink_to_hi ( ) ; // Buffer the diagnostic diag . buffer ( errors_buffer ) ; }
If there is a suggestion to emit, add a diagnostic to the buffer.
If there is a suggestion to emit add a diagnostic to the buffer .
&self
body
&Body<'tcx>
region_infcx
&RegionInferenceContext<'tcx>
infcx
&InferCtxt<'_, 'tcx>
errors_buffer
&mut Vec<Diagnostic>
renctx
&mut RegionErrorNamingCtx