/// Produces nice borrowck error diagnostics for all the errors collected in `nll_errors`.
Produces nice borrowck error diagnostics for all the errors collected in `nll_errors`.
Produces nice borrowck error diagnostics for all the errors collected in ` nll_errors ` .
pub(crate) fn report_region_errors(&mut self, nll_errors: RegionErrors<'tcx>) {
        // Iterate through all the errors, producing a diagnostic for each one. The diagnostics are
        // buffered in the `MirBorrowckCtxt`.
        let mut outlives_suggestion = OutlivesSuggestionBuilder::default();
        for nll_error in nll_errors.into_iter() {
            match nll_error {
                RegionErrorKind::TypeTestError { type_test } => {
                    // Try to convert the lower-bound region into something named we can print for the user.
                    let lower_bound_region = self.to_error_region(type_test.lower_bound);
                    let type_test_span = type_test.locations.span(&self.body);
                    if let Some(lower_bound_region) = lower_bound_region {
                        self.infcx
                            .construct_generic_bound_failure(
                                type_test_span,
                                None,
                                type_test.generic_kind,
                                lower_bound_region,
                            )
                            .buffer(&mut self.errors_buffer);
                    } else {
                        // FIXME. We should handle this case better. It
                        // indicates that we have e.g., some region variable
                        // whose value is like `'a+'b` where `'a` and `'b` are
                        // distinct unrelated univesal regions that are not
                        // known to outlive one another. It'd be nice to have
                        // some examples where this arises to decide how best
                        // to report it; we could probably handle it by
                        // iterating over the universal regions and reporting
                        // an error that multiple bounds are required.
                        self.infcx
                            .tcx
                            .sess
                            .struct_span_err(
                                type_test_span,
                                &format!("`{}` does not live long enough", type_test.generic_kind),
                            )
                            .buffer(&mut self.errors_buffer);
                    }
                }
                RegionErrorKind::UnexpectedHiddenRegion { span, hidden_ty, member_region } => {
                    let named_ty = self.regioncx.name_regions(self.infcx.tcx, hidden_ty);
                    let named_region = self.regioncx.name_regions(self.infcx.tcx, member_region);
                    unexpected_hidden_region_diagnostic(
                        self.infcx.tcx,
                        span,
                        named_ty,
                        named_region,
                    )
                    .buffer(&mut self.errors_buffer);
                }
                RegionErrorKind::BoundUniversalRegionError {
                    longer_fr,
                    placeholder,
                    error_element,
                } => {
                    let error_vid = self.regioncx.region_from_element(longer_fr, &error_element);
                    // Find the code to blame for the fact that `longer_fr` outlives `error_fr`.
                    let (_, cause) = self.regioncx.find_outlives_blame_span(
                        &self.body,
                        longer_fr,
                        NllRegionVariableOrigin::Placeholder(placeholder),
                        error_vid,
                    );
                    let universe = placeholder.universe;
                    let universe_info = self.regioncx.universe_info(universe);
                    universe_info.report_error(self, placeholder, error_element, cause);
                }
                RegionErrorKind::RegionError { fr_origin, longer_fr, shorter_fr, is_reported } => {
                    if is_reported {
                        self.report_region_error(
                            longer_fr,
                            fr_origin,
                            shorter_fr,
                            &mut outlives_suggestion,
                        );
                    } else {
                        // We only report the first error, so as not to overwhelm the user. See
                        // `RegRegionErrorKind` docs.
                        //
                        // FIXME: currently we do nothing with these, but perhaps we can do better?
                        // FIXME: try collecting these constraints on the outlives suggestion
                        // builder. Does it make the suggestions any better?
                        debug!(
                            "Unreported region error: can't prove that {:?}: {:?}",
                            longer_fr, shorter_fr
                        );
                    }
                }
            }
        }
        // Emit one outlives suggestions for each MIR def we borrowck
        outlives_suggestion.add_suggestion(self);
    }
pub ( crate ) fn report_region_errors ( & mut self , nll_errors : RegionErrors < ' tcx > ) { // Iterate through all the errors, producing a diagnostic for each one. The diagnostics are // buffered in the `MirBorrowckCtxt`. let mut outlives_suggestion = OutlivesSuggestionBuilder :: default ( ) ; for nll_error in nll_errors . into_iter ( ) { match nll_error { RegionErrorKind :: TypeTestError { type_test } => { // Try to convert the lower-bound region into something named we can print for the user. let lower_bound_region = self . to_error_region ( type_test . lower_bound ) ; let type_test_span = type_test . locations . span ( & self . body ) ; if let Some ( lower_bound_region ) = lower_bound_region { self . infcx . construct_generic_bound_failure ( type_test_span , None , type_test . generic_kind , lower_bound_region , ) . buffer ( & mut self . errors_buffer ) ; } else { // FIXME. We should handle this case better. It // indicates that we have e.g., some region variable // whose value is like `'a+'b` where `'a` and `'b` are // distinct unrelated univesal regions that are not // known to outlive one another. It'd be nice to have // some examples where this arises to decide how best // to report it; we could probably handle it by // iterating over the universal regions and reporting // an error that multiple bounds are required. self . infcx . tcx . sess . struct_span_err ( type_test_span , & format ! ( " " type_test generic_kind ) , ) . buffer ( & mut self . errors_buffer ) ; } } RegionErrorKind :: UnexpectedHiddenRegion { span , hidden_ty , member_region } => { let named_ty = self . regioncx . name_regions ( self . infcx . tcx , hidden_ty ) ; let named_region = self . regioncx . name_regions ( self . infcx . tcx , member_region ) ; unexpected_hidden_region_diagnostic ( self . infcx . tcx , span , named_ty , named_region , ) . buffer ( & mut self . errors_buffer ) ; } RegionErrorKind :: BoundUniversalRegionError { longer_fr , placeholder , error_element , } => { let error_vid = self . regioncx . region_from_element ( longer_fr , & error_element ) ; // Find the code to blame for the fact that `longer_fr` outlives `error_fr`. let ( _ , cause ) = self . regioncx . find_outlives_blame_span ( & self . body , longer_fr , NllRegionVariableOrigin :: Placeholder ( placeholder ) , error_vid , ) ; let universe = placeholder . universe ; let universe_info = self . regioncx . universe_info ( universe ) ; universe_info . report_error ( self , placeholder , error_element , cause ) ; } RegionErrorKind :: RegionError { fr_origin , longer_fr , shorter_fr , is_reported } => { if is_reported { self . report_region_error ( longer_fr , fr_origin , shorter_fr , & mut outlives_suggestion , ) ; } else { // We only report the first error, so as not to overwhelm the user. See // `RegRegionErrorKind` docs. // // FIXME: currently we do nothing with these, but perhaps we can do better? // FIXME: try collecting these constraints on the outlives suggestion // builder. Does it make the suggestions any better? debug ! ( " " longer_fr shorter_fr ) ; } } } } // Emit one outlives suggestions for each MIR def we borrowck outlives_suggestion . add_suggestion ( self ) ; }
Produces nice borrowck error diagnostics for all the errors collected in `nll_errors`.
Produces nice borrowck error diagnostics for all the errors collected in ` nll_errors ` .
&mut self
nll_errors
RegionErrors<'tcx>