@@ -239,8 +239,7 @@ pub trait ErrorReporting<'tcx> {
239
239
fn report_generic_bound_failure ( & self ,
240
240
origin : SubregionOrigin < ' tcx > ,
241
241
kind : GenericKind < ' tcx > ,
242
- sub : Region ,
243
- sups : Vec < Region > ) ;
242
+ sub : Region ) ;
244
243
245
244
fn report_sub_sup_conflict ( & self ,
246
245
var_origin : RegionVariableOrigin ,
@@ -292,8 +291,8 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
292
291
self . report_concrete_failure ( origin, sub, sup) ;
293
292
}
294
293
295
- GenericBoundFailure ( kind, param_ty, sub, sups ) => {
296
- self . report_generic_bound_failure ( kind, param_ty, sub, sups ) ;
294
+ GenericBoundFailure ( kind, param_ty, sub) => {
295
+ self . report_generic_bound_failure ( kind, param_ty, sub) ;
297
296
}
298
297
299
298
SubSupConflict ( var_origin,
@@ -527,14 +526,18 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
527
526
fn report_generic_bound_failure ( & self ,
528
527
origin : SubregionOrigin < ' tcx > ,
529
528
bound_kind : GenericKind < ' tcx > ,
530
- sub : Region ,
531
- _sups : Vec < Region > )
529
+ sub : Region )
532
530
{
533
531
// FIXME: it would be better to report the first error message
534
532
// with the span of the parameter itself, rather than the span
535
533
// where the error was detected. But that span is not readily
536
534
// accessible.
537
535
536
+ let is_warning = match origin {
537
+ infer:: RFC1214Subregion ( _) => true ,
538
+ _ => false ,
539
+ } ;
540
+
538
541
let labeled_user_string = match bound_kind {
539
542
GenericKind :: Param ( ref p) =>
540
543
format ! ( "the parameter type `{}`" , p) ,
@@ -545,7 +548,8 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
545
548
match sub {
546
549
ty:: ReFree ( ty:: FreeRegion { bound_region : ty:: BrNamed ( ..) , ..} ) => {
547
550
// Does the required lifetime have a nice name we can print?
548
- span_err ! ( self . tcx. sess, origin. span( ) , E0309 ,
551
+ span_err_or_warn ! (
552
+ is_warning, self . tcx. sess, origin. span( ) , E0309 ,
549
553
"{} may not live long enough" , labeled_user_string) ;
550
554
self . tcx . sess . fileline_help (
551
555
origin. span ( ) ,
@@ -557,7 +561,8 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
557
561
558
562
ty:: ReStatic => {
559
563
// Does the required lifetime have a nice name we can print?
560
- span_err ! ( self . tcx. sess, origin. span( ) , E0310 ,
564
+ span_err_or_warn ! (
565
+ is_warning, self . tcx. sess, origin. span( ) , E0310 ,
561
566
"{} may not live long enough" , labeled_user_string) ;
562
567
self . tcx . sess . fileline_help (
563
568
origin. span ( ) ,
@@ -568,9 +573,10 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
568
573
569
574
_ => {
570
575
// If not, be less specific.
571
- span_err ! ( self . tcx. sess, origin. span( ) , E0311 ,
572
- "{} may not live long enough" ,
573
- labeled_user_string) ;
576
+ span_err_or_warn ! (
577
+ is_warning, self . tcx. sess, origin. span( ) , E0311 ,
578
+ "{} may not live long enough" ,
579
+ labeled_user_string) ;
574
580
self . tcx . sess . fileline_help (
575
581
origin. span ( ) ,
576
582
& format ! (
@@ -583,6 +589,10 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
583
589
}
584
590
}
585
591
592
+ if is_warning {
593
+ self . tcx . sess . note_rfc_1214 ( origin. span ( ) ) ;
594
+ }
595
+
586
596
self . note_region_origin ( & origin) ;
587
597
}
588
598
@@ -591,6 +601,13 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
591
601
sub : Region ,
592
602
sup : Region ) {
593
603
match origin {
604
+ infer:: RFC1214Subregion ( ref suborigin) => {
605
+ // Ideally, this would be a warning, but it doesn't
606
+ // seem to come up in practice, since the changes from
607
+ // RFC1214 mostly trigger errors in type definitions
608
+ // that don't wind up coming down this path.
609
+ self . report_concrete_failure ( ( * * suborigin) . clone ( ) , sub, sup) ;
610
+ }
594
611
infer:: Subtype ( trace) => {
595
612
let terr = TypeError :: RegionsDoesNotOutlive ( sup, sub) ;
596
613
self . report_and_explain_type_error ( trace, & terr) ;
@@ -819,6 +836,23 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
819
836
sup,
820
837
"" ) ;
821
838
}
839
+ infer:: ParameterInScope ( _, span) => {
840
+ self . tcx . sess . span_err (
841
+ span,
842
+ & format ! ( "type/lifetime parameter not in scope here" ) ) ;
843
+ self . tcx . note_and_explain_region (
844
+ "the parameter is only valid for " ,
845
+ sub,
846
+ "" ) ;
847
+ }
848
+ infer:: DataBorrowed ( ty, span) => {
849
+ self . tcx . sess . span_err (
850
+ span,
851
+ & format ! ( "a value of type `{}` is borrowed for too long" ,
852
+ self . ty_to_string( ty) ) ) ;
853
+ self . tcx . note_and_explain_region ( "the type is valid for " , sub, "" ) ;
854
+ self . tcx . note_and_explain_region ( "but the borrow lasts for " , sup, "" ) ;
855
+ }
822
856
infer:: ReferenceOutlivesReferent ( ty, span) => {
823
857
self . tcx . sess . span_err (
824
858
span,
@@ -1567,6 +1601,9 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
1567
1601
1568
1602
fn note_region_origin ( & self , origin : & SubregionOrigin < ' tcx > ) {
1569
1603
match * origin {
1604
+ infer:: RFC1214Subregion ( ref suborigin) => {
1605
+ self . note_region_origin ( suborigin) ;
1606
+ }
1570
1607
infer:: Subtype ( ref trace) => {
1571
1608
let desc = match trace. origin {
1572
1609
infer:: Misc ( _) => {
@@ -1714,6 +1751,17 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
1714
1751
span,
1715
1752
"...so that variable is valid at time of its declaration" ) ;
1716
1753
}
1754
+ infer:: ParameterInScope ( _, span) => {
1755
+ self . tcx . sess . span_note (
1756
+ span,
1757
+ & format ! ( "...so that a type/lifetime parameter is in scope here" ) ) ;
1758
+ }
1759
+ infer:: DataBorrowed ( ty, span) => {
1760
+ self . tcx . sess . span_note (
1761
+ span,
1762
+ & format ! ( "...so that the type `{}` is not borrowed for too long" ,
1763
+ self . ty_to_string( ty) ) ) ;
1764
+ }
1717
1765
infer:: ReferenceOutlivesReferent ( ty, span) => {
1718
1766
self . tcx . sess . span_note (
1719
1767
span,
0 commit comments