Skip to content

Commit 5274e29

Browse files
committed
refactor report_generic_bound_failure to be usable by NLL code
1 parent 54b3a11 commit 5274e29

File tree

1 file changed

+22
-13
lines changed
  • src/librustc/infer/error_reporting

1 file changed

+22
-13
lines changed

src/librustc/infer/error_reporting/mod.rs

+22-13
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
304304
self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
305305
}
306306

307-
RegionResolutionError::GenericBoundFailure(kind, param_ty, sub) => {
308-
self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
307+
RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => {
308+
self.report_generic_bound_failure(
309+
region_scope_tree,
310+
origin.span(),
311+
Some(origin),
312+
param_ty,
313+
sub,
314+
);
309315
}
310316

311317
RegionResolutionError::SubSupConflict(var_origin,
@@ -901,11 +907,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
901907
DiagnosticStyledString::highlighted(format!("{}", exp_found.found))))
902908
}
903909

904-
fn report_generic_bound_failure(&self,
905-
region_scope_tree: &region::ScopeTree,
906-
origin: SubregionOrigin<'tcx>,
907-
bound_kind: GenericKind<'tcx>,
908-
sub: Region<'tcx>)
910+
pub fn report_generic_bound_failure(&self,
911+
region_scope_tree: &region::ScopeTree,
912+
span: Span,
913+
origin: Option<SubregionOrigin<'tcx>>,
914+
bound_kind: GenericKind<'tcx>,
915+
sub: Region<'tcx>)
909916
{
910917
// Attempt to obtain the span of the parameter so we can
911918
// suggest adding an explicit lifetime bound to it.
@@ -953,9 +960,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
953960
format!("the associated type `{}`", p),
954961
};
955962

956-
if let SubregionOrigin::CompareImplMethodObligation {
963+
if let Some(SubregionOrigin::CompareImplMethodObligation {
957964
span, item_name, impl_item_def_id, trait_item_def_id,
958-
} = origin {
965+
}) = origin {
959966
self.report_extra_impl_obligation(span,
960967
item_name,
961968
impl_item_def_id,
@@ -990,7 +997,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
990997
ty::ReFree(ty::FreeRegion {bound_region: ty::BrNamed(..), ..}) => {
991998
// Does the required lifetime have a nice name we can print?
992999
let mut err = struct_span_err!(self.tcx.sess,
993-
origin.span(),
1000+
span,
9941001
E0309,
9951002
"{} may not live long enough",
9961003
labeled_user_string);
@@ -1001,7 +1008,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10011008
ty::ReStatic => {
10021009
// Does the required lifetime have a nice name we can print?
10031010
let mut err = struct_span_err!(self.tcx.sess,
1004-
origin.span(),
1011+
span,
10051012
E0310,
10061013
"{} may not live long enough",
10071014
labeled_user_string);
@@ -1012,7 +1019,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10121019
_ => {
10131020
// If not, be less specific.
10141021
let mut err = struct_span_err!(self.tcx.sess,
1015-
origin.span(),
1022+
span,
10161023
E0311,
10171024
"{} may not live long enough",
10181025
labeled_user_string);
@@ -1028,7 +1035,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10281035
}
10291036
};
10301037

1031-
self.note_region_origin(&mut err, &origin);
1038+
if let Some(origin) = origin {
1039+
self.note_region_origin(&mut err, &origin);
1040+
}
10321041
err.emit();
10331042
}
10341043

0 commit comments

Comments
 (0)