From ec005ccf84e470a70f8bb8b5347ab8e793fb30a3 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 18 Jul 2018 23:17:22 +0200 Subject: [PATCH] Separate the construction of a generic bound failure from its emission. --- src/librustc/infer/error_reporting/mod.rs | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 1ec9c9489e9b..4ad60f2f85e2 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1086,6 +1086,23 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { bound_kind: GenericKind<'tcx>, sub: Region<'tcx>, ) { + self.construct_generic_bound_failure(region_scope_tree, + span, + origin, + bound_kind, + sub) + .emit() + } + + pub fn construct_generic_bound_failure( + &self, + region_scope_tree: ®ion::ScopeTree, + span: Span, + origin: Option>, + bound_kind: GenericKind<'tcx>, + sub: Region<'tcx>, + ) -> DiagnosticBuilder<'a> + { // Attempt to obtain the span of the parameter so we can // suggest adding an explicit lifetime bound to it. let type_param_span = match (self.in_progress_tables, bound_kind) { @@ -1139,14 +1156,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { trait_item_def_id, }) = origin { - self.report_extra_impl_obligation( + return self.report_extra_impl_obligation( span, item_name, impl_item_def_id, trait_item_def_id, &format!("`{}: {}`", bound_kind, sub), - ).emit(); - return; + ); } fn binding_suggestion<'tcx, S: fmt::Display>( @@ -1229,7 +1245,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { if let Some(origin) = origin { self.note_region_origin(&mut err, &origin); } - err.emit(); + err } fn report_sub_sup_conflict(