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 {}
291291"# ,
292292 ) ;
293293 }
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+ }
294320}
Original file line number Diff line number Diff line change @@ -448,6 +448,7 @@ fn expand_repeat(
448448 let mut counter = 0 ;
449449 let mut err = None ;
450450
451+ let initial_restore_point = builder. restore_point ( ) ;
451452 let mut restore_point = builder. restore_point ( ) ;
452453 loop {
453454 let ExpandResult { value : ( ) , err : e } =
@@ -465,6 +466,10 @@ fn expand_repeat(
465466
466467 counter += 1 ;
467468 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) ;
468473 err = Some ( ExpandError :: new ( ctx. call_site , ExpandErrorKind :: LimitExceeded ) ) ;
469474 break ;
470475 }
You can’t perform that action at this time.
0 commit comments