File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
src/tools/rust-analyzer/crates
ide-diagnostics/src/handlers Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -291,4 +291,30 @@ mod prim_never {}
291
291
"# ,
292
292
) ;
293
293
}
294
+
295
+ #[ test]
296
+ fn no_stack_overflow_for_missing_binding ( ) {
297
+ check_diagnostics (
298
+ r#"
299
+ #[macro_export]
300
+ macro_rules! boom {
301
+ (
302
+ $($code:literal),+,
303
+ $(param: $param:expr,)?
304
+ ) => {{
305
+ let _ = $crate::boom!(@param $($param)*);
306
+ }};
307
+ (@param) => { () };
308
+ (@param $param:expr) => { $param };
309
+ }
310
+
311
+ fn it_works() {
312
+ // NOTE: there is an error, but RA crashes before showing it
313
+ boom!("RAND", param: c7.clone());
314
+ // ^^^^^ error: expected literal
315
+ }
316
+
317
+ "# ,
318
+ ) ;
319
+ }
294
320
}
Original file line number Diff line number Diff line change @@ -448,6 +448,7 @@ fn expand_repeat(
448
448
let mut counter = 0 ;
449
449
let mut err = None ;
450
450
451
+ let initial_restore_point = builder. restore_point ( ) ;
451
452
let mut restore_point = builder. restore_point ( ) ;
452
453
loop {
453
454
let ExpandResult { value : ( ) , err : e } =
@@ -465,6 +466,10 @@ fn expand_repeat(
465
466
466
467
counter += 1 ;
467
468
if counter == limit {
469
+ // FIXME: This is a bug here, we get here when we shouldn't, see https://github.com/rust-lang/rust-analyzer/issues/18910.
470
+ // If we don't restore we emit a lot of nodes which causes a stack overflow down the road. For now just ignore them,
471
+ // there is always an error here anyway.
472
+ builder. restore ( initial_restore_point) ;
468
473
err = Some ( ExpandError :: new ( ctx. call_site , ExpandErrorKind :: LimitExceeded ) ) ;
469
474
break ;
470
475
}
You can’t perform that action at this time.
0 commit comments