@@ -72,13 +72,12 @@ use super::region_inference::SameRegions;
7272use hir:: map as hir_map;
7373use hir;
7474
75- use lint;
7675use hir:: def_id:: DefId ;
7776use infer;
7877use middle:: region;
7978use traits:: { ObligationCause , ObligationCauseCode } ;
8079use ty:: { self , TyCtxt , TypeFoldable } ;
81- use ty:: { Region , ReFree } ;
80+ use ty:: { Region , ReFree , Issue32330 } ;
8281use ty:: error:: TypeError ;
8382
8483use std:: fmt;
@@ -610,6 +609,39 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
610609 self . tcx . note_and_explain_type_err ( diag, terr, span) ;
611610 }
612611
612+ pub fn note_issue_32330 ( & self ,
613+ diag : & mut DiagnosticBuilder < ' tcx > ,
614+ terr : & TypeError < ' tcx > )
615+ {
616+ debug ! ( "note_issue_32330: terr={:?}" , terr) ;
617+ match * terr {
618+ TypeError :: RegionsInsufficientlyPolymorphic ( _, & Region :: ReVar ( vid) ) |
619+ TypeError :: RegionsOverlyPolymorphic ( _, & Region :: ReVar ( vid) ) => {
620+ match self . region_vars . var_origin ( vid) {
621+ RegionVariableOrigin :: EarlyBoundRegion ( _, _, Some ( Issue32330 {
622+ fn_def_id,
623+ region_name
624+ } ) ) => {
625+ diag. note (
626+ & format ! ( "lifetime parameter `{0}` declared on fn `{1}` \
627+ appears only in the return type, \
628+ but here is required to be higher-ranked, \
629+ which means that `{0}` must appear in both \
630+ argument and return types",
631+ region_name,
632+ self . tcx. item_path_str( fn_def_id) ) ) ;
633+ diag. note (
634+ & format ! ( "this error is the result of a recent bug fix; \
635+ for more information, see issue #33685 \
636+ <https://github.com/rust-lang/rust/issues/33685>") ) ;
637+ }
638+ _ => { }
639+ }
640+ }
641+ _ => { }
642+ }
643+ }
644+
613645 pub fn report_and_explain_type_error ( & self ,
614646 trace : TypeTrace < ' tcx > ,
615647 terr : & TypeError < ' tcx > )
@@ -629,6 +661,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
629661 }
630662 } ;
631663 self . note_type_err ( & mut diag, & trace. cause , None , Some ( trace. values ) , terr) ;
664+ self . note_issue_32330 ( & mut diag, terr) ;
632665 diag
633666 }
634667
@@ -1053,27 +1086,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10531086 err. emit ( ) ;
10541087 }
10551088 }
1056-
1057- pub fn issue_32330_warnings ( & self , span : Span , issue32330s : & [ ty:: Issue32330 ] ) {
1058- for issue32330 in issue32330s {
1059- match * issue32330 {
1060- ty:: Issue32330 :: WontChange => { }
1061- ty:: Issue32330 :: WillChange { fn_def_id, region_name } => {
1062- self . tcx . sess . add_lint (
1063- lint:: builtin:: HR_LIFETIME_IN_ASSOC_TYPE ,
1064- ast:: CRATE_NODE_ID ,
1065- span,
1066- format ! ( "lifetime parameter `{0}` declared on fn `{1}` \
1067- appears only in the return type, \
1068- but here is required to be higher-ranked, \
1069- which means that `{0}` must appear in both \
1070- argument and return types",
1071- region_name,
1072- self . tcx. item_path_str( fn_def_id) ) ) ;
1073- }
1074- }
1075- }
1076- }
10771089}
10781090
10791091impl < ' a , ' gcx , ' tcx > InferCtxt < ' a , ' gcx , ' tcx > {
@@ -1104,7 +1116,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11041116 format ! ( " for lifetime parameter {}in trait containing associated type `{}`" ,
11051117 br_string( br) , type_name)
11061118 }
1107- infer:: EarlyBoundRegion ( _, name) => {
1119+ infer:: EarlyBoundRegion ( _, name, _ ) => {
11081120 format ! ( " for lifetime parameter `{}`" ,
11091121 name)
11101122 }
0 commit comments