mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 20:09:01 +00:00 
			
		
		
		
	Missing errors
This commit is contained in:
		
							parent
							
								
									1b52a6680f
								
							
						
					
					
						commit
						11717ca5d4
					
				
					 2 changed files with 26 additions and 11 deletions
				
			
		|  | @ -134,12 +134,14 @@ pub(super) fn let_stmt(p: &mut Parser<'_>, with_semi: Semicolon) { | ||||||
|         // test_err let_else_right_curly_brace
 |         // test_err let_else_right_curly_brace
 | ||||||
|         // fn func() { let Some(_) = {Some(1)} else { panic!("h") };}
 |         // fn func() { let Some(_) = {Some(1)} else { panic!("h") };}
 | ||||||
|         if let Some(expr) = expr_after_eq { |         if let Some(expr) = expr_after_eq { | ||||||
|             if BlockLike::is_blocklike(expr.kind()) { |             if let Some(token) = expr.last_token(p) { | ||||||
|  |                 if token == T!['}'] { | ||||||
|                     p.error( |                     p.error( | ||||||
|                     "right curly brace `}` before `else` in a `let...else` statement not allowed", |                         "right curly brace `}` before `else` in a `let...else` statement not allowed" | ||||||
|                     ) |                     ) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         // test let_else
 |         // test let_else
 | ||||||
|         // fn f() { let Some(x) = opt else { return }; }
 |         // fn f() { let Some(x) = opt else { return }; }
 | ||||||
|  |  | ||||||
|  | @ -318,7 +318,8 @@ impl Marker { | ||||||
|             _ => unreachable!(), |             _ => unreachable!(), | ||||||
|         } |         } | ||||||
|         p.push_event(Event::Finish); |         p.push_event(Event::Finish); | ||||||
|         CompletedMarker::new(self.pos, kind) |         let end_pos = p.events.len() as u32; | ||||||
|  |         CompletedMarker::new(self.pos, end_pos, kind) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Abandons the syntax tree node. All its children
 |     /// Abandons the syntax tree node. All its children
 | ||||||
|  | @ -336,13 +337,14 @@ impl Marker { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub(crate) struct CompletedMarker { | pub(crate) struct CompletedMarker { | ||||||
|     pos: u32, |     start_pos: u32, | ||||||
|  |     end_pos: u32, | ||||||
|     kind: SyntaxKind, |     kind: SyntaxKind, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl CompletedMarker { | impl CompletedMarker { | ||||||
|     fn new(pos: u32, kind: SyntaxKind) -> Self { |     fn new(start_pos: u32, end_pos: u32, kind: SyntaxKind) -> Self { | ||||||
|         CompletedMarker { pos, kind } |         CompletedMarker { start_pos, end_pos, kind } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// This method allows to create a new node which starts
 |     /// This method allows to create a new node which starts
 | ||||||
|  | @ -360,10 +362,10 @@ impl CompletedMarker { | ||||||
|     /// distance to `NEWSTART` into forward_parent(=2 in this case);
 |     /// distance to `NEWSTART` into forward_parent(=2 in this case);
 | ||||||
|     pub(crate) fn precede(self, p: &mut Parser<'_>) -> Marker { |     pub(crate) fn precede(self, p: &mut Parser<'_>) -> Marker { | ||||||
|         let new_pos = p.start(); |         let new_pos = p.start(); | ||||||
|         let idx = self.pos as usize; |         let idx = self.start_pos as usize; | ||||||
|         match &mut p.events[idx] { |         match &mut p.events[idx] { | ||||||
|             Event::Start { forward_parent, .. } => { |             Event::Start { forward_parent, .. } => { | ||||||
|                 *forward_parent = Some(new_pos.pos - self.pos); |                 *forward_parent = Some(new_pos.pos - self.start_pos); | ||||||
|             } |             } | ||||||
|             _ => unreachable!(), |             _ => unreachable!(), | ||||||
|         } |         } | ||||||
|  | @ -376,7 +378,7 @@ impl CompletedMarker { | ||||||
|         let idx = m.pos as usize; |         let idx = m.pos as usize; | ||||||
|         match &mut p.events[idx] { |         match &mut p.events[idx] { | ||||||
|             Event::Start { forward_parent, .. } => { |             Event::Start { forward_parent, .. } => { | ||||||
|                 *forward_parent = Some(self.pos - m.pos); |                 *forward_parent = Some(self.start_pos - m.pos); | ||||||
|             } |             } | ||||||
|             _ => unreachable!(), |             _ => unreachable!(), | ||||||
|         } |         } | ||||||
|  | @ -386,4 +388,15 @@ impl CompletedMarker { | ||||||
|     pub(crate) fn kind(&self) -> SyntaxKind { |     pub(crate) fn kind(&self) -> SyntaxKind { | ||||||
|         self.kind |         self.kind | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     pub(crate) fn last_token(&self, p: &Parser<'_>) -> Option<SyntaxKind> { | ||||||
|  |         let end_pos = self.end_pos as usize; | ||||||
|  |         if end_pos > p.events.len() { | ||||||
|  |             return None; | ||||||
|  |         } | ||||||
|  |         p.events[..end_pos].iter().rev().find_map(|event| match event { | ||||||
|  |             Event::Token { kind, .. } => Some(*kind), | ||||||
|  |             _ => None, | ||||||
|  |         }) | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 jnyfah
						jnyfah