File tree 3 files changed +44
-4
lines changed
compiler/rustc_hir_analysis/src/outlives
3 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -24,8 +24,8 @@ pub(super) fn infer_predicates(
24
24
25
25
// If new predicates were added then we need to re-calculate
26
26
// all crates since there could be new implied predicates.
27
- loop {
28
- let mut predicates_added = false ;
27
+ for i in 0 .. {
28
+ let mut predicates_added: Option < Vec < _ > > = None ;
29
29
30
30
// Visit all the crates and infer predicates
31
31
for id in tcx. hir_free_items ( ) {
@@ -83,13 +83,34 @@ pub(super) fn infer_predicates(
83
83
. get ( & item_did. to_def_id ( ) )
84
84
. map_or ( 0 , |p| p. as_ref ( ) . skip_binder ( ) . len ( ) ) ;
85
85
if item_required_predicates. len ( ) > item_predicates_len {
86
- predicates_added = true ;
86
+ predicates_added. get_or_insert_default ( ) . push ( item_did ) ;
87
87
global_inferred_outlives
88
88
. insert ( item_did. to_def_id ( ) , ty:: EarlyBinder :: bind ( item_required_predicates) ) ;
89
89
}
90
90
}
91
91
92
- if !predicates_added {
92
+ if let Some ( ids) = predicates_added {
93
+ if !tcx. recursion_limit ( ) . value_within_limit ( i) {
94
+ let msg = if let & [ id] = & ids[ ..] {
95
+ format ! (
96
+ "overflow computing implied lifetime bounds for `{}`" ,
97
+ tcx. def_path_str( id) ,
98
+ )
99
+ } else {
100
+ "overflow computing implied lifetime bounds" . to_string ( )
101
+ } ;
102
+ tcx. dcx ( )
103
+ . struct_span_err (
104
+ ids. iter ( ) . map ( |id| tcx. def_span ( * id) ) . collect :: < Vec < _ > > ( ) ,
105
+ msg,
106
+ )
107
+ . emit ( ) ;
108
+ for id in ids {
109
+ global_inferred_outlives. shift_remove ( & id. to_def_id ( ) ) ;
110
+ }
111
+ break ;
112
+ }
113
+ } else {
93
114
break ;
94
115
}
95
116
}
Original file line number Diff line number Diff line change
1
+ trait Tailed < ' a > : ' a {
2
+ type Tail : Tailed < ' a > ;
3
+ }
4
+
5
+ struct List < ' a , T : Tailed < ' a > > {
6
+ //~^ ERROR overflow computing implied lifetime bounds for `List`
7
+ next : Box < List < ' a , T :: Tail > > ,
8
+ node : & ' a T ,
9
+ }
10
+
11
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: overflow computing implied lifetime bounds for `List`
2
+ --> $DIR/overflow.rs:5:1
3
+ |
4
+ LL | struct List<'a, T: Tailed<'a>> {
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
+
7
+ error: aborting due to 1 previous error
8
+
You can’t perform that action at this time.
0 commit comments