mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 13:13:18 +00:00 
			
		
		
		
	Merge pull request #18929 from ChayimFriedman2/i-acknowledge-defeat
fix: Fix another bug when reaching macro expansion limit caused a stack overflow
This commit is contained in:
		
						commit
						96d5b177cf
					
				@ -291,4 +291,30 @@ mod prim_never {}
 | 
			
		||||
"#,
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn no_stack_overflow_for_missing_binding() {
 | 
			
		||||
        check_diagnostics(
 | 
			
		||||
            r#"
 | 
			
		||||
#[macro_export]
 | 
			
		||||
macro_rules! boom {
 | 
			
		||||
    (
 | 
			
		||||
        $($code:literal),+,
 | 
			
		||||
        $(param: $param:expr,)?
 | 
			
		||||
    ) => {{
 | 
			
		||||
        let _ = $crate::boom!(@param $($param)*);
 | 
			
		||||
    }};
 | 
			
		||||
    (@param) => { () };
 | 
			
		||||
    (@param $param:expr) => { $param };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn it_works() {
 | 
			
		||||
    // NOTE: there is an error, but RA crashes before showing it
 | 
			
		||||
    boom!("RAND", param: c7.clone());
 | 
			
		||||
               // ^^^^^ error: expected literal
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
        "#,
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -448,6 +448,7 @@ fn expand_repeat(
 | 
			
		||||
    let mut counter = 0;
 | 
			
		||||
    let mut err = None;
 | 
			
		||||
 | 
			
		||||
    let initial_restore_point = builder.restore_point();
 | 
			
		||||
    let mut restore_point = builder.restore_point();
 | 
			
		||||
    loop {
 | 
			
		||||
        let ExpandResult { value: (), err: e } =
 | 
			
		||||
@ -465,6 +466,10 @@ fn expand_repeat(
 | 
			
		||||
 | 
			
		||||
        counter += 1;
 | 
			
		||||
        if counter == limit {
 | 
			
		||||
            // FIXME: This is a bug here, we get here when we shouldn't, see https://github.com/rust-lang/rust-analyzer/issues/18910.
 | 
			
		||||
            // If we don't restore we emit a lot of nodes which causes a stack overflow down the road. For now just ignore them,
 | 
			
		||||
            // there is always an error here anyway.
 | 
			
		||||
            builder.restore(initial_restore_point);
 | 
			
		||||
            err = Some(ExpandError::new(ctx.call_site, ExpandErrorKind::LimitExceeded));
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user