File tree 3 files changed +71
-1
lines changed
compiler/rustc_const_eval/src/const_eval
3 files changed +71
-1
lines changed Original file line number Diff line number Diff line change @@ -156,9 +156,37 @@ impl<'tcx> ConstEvalErr<'tcx> {
156
156
}
157
157
// Add spans for the stacktrace. Don't print a single-line backtrace though.
158
158
if self . stacktrace . len ( ) > 1 {
159
+ // Helper closure to print duplicated lines.
160
+ let mut flush_last_line = |last_frame, times| {
161
+ if let Some ( ( line, span) ) = last_frame {
162
+ err. span_label ( span, & line) ;
163
+ // Don't print [... additional calls ...] if the number of lines is small
164
+ if times < 3 {
165
+ for _ in 0 ..times {
166
+ err. span_label ( span, & line) ;
167
+ }
168
+ } else {
169
+ err. span_label (
170
+ span,
171
+ format ! ( "[... {} additional calls {} ...]" , times, & line) ,
172
+ ) ;
173
+ }
174
+ }
175
+ } ;
176
+
177
+ let mut last_frame = None ;
178
+ let mut times = 0 ;
159
179
for frame_info in & self . stacktrace {
160
- err. span_label ( frame_info. span , frame_info. to_string ( ) ) ;
180
+ let frame = ( frame_info. to_string ( ) , frame_info. span ) ;
181
+ if last_frame. as_ref ( ) == Some ( & frame) {
182
+ times += 1 ;
183
+ } else {
184
+ flush_last_line ( last_frame, times) ;
185
+ last_frame = Some ( frame) ;
186
+ times = 0 ;
187
+ }
161
188
}
189
+ flush_last_line ( last_frame, times) ;
162
190
}
163
191
// Let the caller finish the job.
164
192
emit ( err)
Original file line number Diff line number Diff line change
1
+ #![ allow( unused) ]
2
+
3
+ const fn f < T > ( x : T ) { //~ WARN function cannot return without recursing
4
+ f ( x) ;
5
+ //~^ ERROR any use of this value will cause an error
6
+ //~| WARN this was previously accepted by the compiler
7
+ }
8
+
9
+ const X : ( ) = f ( 1 ) ;
10
+
11
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ warning: function cannot return without recursing
2
+ --> $DIR/recursive.rs:3:1
3
+ |
4
+ LL | const fn f<T>(x: T) {
5
+ | ^^^^^^^^^^^^^^^^^^^ cannot return without recursing
6
+ LL | f(x);
7
+ | ---- recursive call site
8
+ |
9
+ = note: `#[warn(unconditional_recursion)]` on by default
10
+ = help: a `loop` may express intention better if this is on purpose
11
+
12
+ error: any use of this value will cause an error
13
+ --> $DIR/recursive.rs:4:5
14
+ |
15
+ LL | f(x);
16
+ | ^^^^
17
+ | |
18
+ | reached the configured maximum number of stack frames
19
+ | inside `f::<i32>` at $DIR/recursive.rs:4:5
20
+ | [... 126 additional calls inside `f::<i32>` at $DIR/recursive.rs:4:5 ...]
21
+ | inside `X` at $DIR/recursive.rs:9:15
22
+ ...
23
+ LL | const X: () = f(1);
24
+ | -------------------
25
+ |
26
+ = note: `#[deny(const_err)]` on by default
27
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
28
+ = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
29
+
30
+ error: aborting due to previous error; 1 warning emitted
31
+
You can’t perform that action at this time.
0 commit comments