mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-29 19:17:12 +00:00 
			
		
		
		
	Implement region negation to minicore and add a flag fmt_before_1_89_0
				
					
				
			This commit is contained in:
		
							parent
							
								
									56de2113f1
								
							
						
					
					
						commit
						c13859903c
					
				
					 2 changed files with 49 additions and 8 deletions
				
			
		|  | @ -412,44 +412,70 @@ impl MiniCore { | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         let mut active_regions = Vec::new(); |         let mut active_regions = Vec::new(); | ||||||
|  |         let mut inactive_regions = Vec::new(); | ||||||
|         let mut seen_regions = Vec::new(); |         let mut seen_regions = Vec::new(); | ||||||
|         for line in lines { |         for line in lines { | ||||||
|             let trimmed = line.trim(); |             let trimmed = line.trim(); | ||||||
|             if let Some(region) = trimmed.strip_prefix("// region:") { |             if let Some(region) = trimmed.strip_prefix("// region:") { | ||||||
|                 active_regions.push(region); |                 if let Some(region) = region.strip_prefix('!') { | ||||||
|                 continue; |                     inactive_regions.push(region); | ||||||
|  |                     continue; | ||||||
|  |                 } else { | ||||||
|  |                     active_regions.push(region); | ||||||
|  |                     continue; | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|             if let Some(region) = trimmed.strip_prefix("// endregion:") { |             if let Some(region) = trimmed.strip_prefix("// endregion:") { | ||||||
|                 let prev = active_regions.pop().unwrap(); |                 let (prev, region) = if let Some(region) = region.strip_prefix('!') { | ||||||
|  |                     (inactive_regions.pop().unwrap(), region) | ||||||
|  |                 } else { | ||||||
|  |                     (active_regions.pop().unwrap(), region) | ||||||
|  |                 }; | ||||||
|                 assert_eq!(prev, region, "unbalanced region pairs"); |                 assert_eq!(prev, region, "unbalanced region pairs"); | ||||||
|                 continue; |                 continue; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             let mut line_region = false; |             let mut active_line_region = false; | ||||||
|             if let Some(idx) = trimmed.find("// :") { |             let mut inactive_line_region = false; | ||||||
|                 line_region = true; |             if let Some(idx) = trimmed.find("// :!") { | ||||||
|  |                 inactive_line_region = true; | ||||||
|  |                 inactive_regions.push(&trimmed[idx + "// :!".len()..]); | ||||||
|  |             } else if let Some(idx) = trimmed.find("// :") { | ||||||
|  |                 active_line_region = true; | ||||||
|                 active_regions.push(&trimmed[idx + "// :".len()..]); |                 active_regions.push(&trimmed[idx + "// :".len()..]); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             let mut keep = true; |             let mut keep = true; | ||||||
|             for ®ion in &active_regions { |             for ®ion in active_regions.iter() { | ||||||
|                 assert!(!region.starts_with(' '), "region marker starts with a space: {region:?}"); |                 assert!(!region.starts_with(' '), "region marker starts with a space: {region:?}"); | ||||||
|                 self.assert_valid_flag(region); |                 self.assert_valid_flag(region); | ||||||
|                 seen_regions.push(region); |                 seen_regions.push(region); | ||||||
|                 keep &= self.has_flag(region); |                 keep &= self.has_flag(region); | ||||||
|             } |             } | ||||||
|  |             for ®ion in inactive_regions.iter() { | ||||||
|  |                 assert!(!region.starts_with(' '), "region marker starts with a space: {region:?}"); | ||||||
|  |                 self.assert_valid_flag(region); | ||||||
|  |                 seen_regions.push(region); | ||||||
|  |                 keep &= !self.has_flag(region); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             if keep { |             if keep { | ||||||
|                 buf.push_str(line); |                 buf.push_str(line); | ||||||
|             } |             } | ||||||
|             if line_region { |             if active_line_region { | ||||||
|                 active_regions.pop().unwrap(); |                 active_regions.pop().unwrap(); | ||||||
|             } |             } | ||||||
|  |             if inactive_line_region { | ||||||
|  |                 inactive_regions.pop().unwrap(); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if !active_regions.is_empty() { |         if !active_regions.is_empty() { | ||||||
|             panic!("unclosed regions: {active_regions:?} Add an `endregion` comment"); |             panic!("unclosed regions: {active_regions:?} Add an `endregion` comment"); | ||||||
|         } |         } | ||||||
|  |         if !inactive_regions.is_empty() { | ||||||
|  |             panic!("unclosed regions: {inactive_regions:?} Add an `endregion` comment"); | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         for flag in &self.valid_flags { |         for flag in &self.valid_flags { | ||||||
|             if !seen_regions.iter().any(|it| it == flag) { |             if !seen_regions.iter().any(|it| it == flag) { | ||||||
|  |  | ||||||
|  | @ -31,6 +31,7 @@ | ||||||
| //!     eq: sized
 | //!     eq: sized
 | ||||||
| //!     error: fmt
 | //!     error: fmt
 | ||||||
| //!     fmt: option, result, transmute, coerce_unsized, copy, clone, derive
 | //!     fmt: option, result, transmute, coerce_unsized, copy, clone, derive
 | ||||||
|  | //!     fmt_before_1_89_0: fmt
 | ||||||
| //!     fn: tuple
 | //!     fn: tuple
 | ||||||
| //!     from: sized, result
 | //!     from: sized, result
 | ||||||
| //!     future: pin
 | //!     future: pin
 | ||||||
|  | @ -1175,6 +1176,7 @@ pub mod fmt { | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         // region:fmt_before_1_89_0
 | ||||||
|         #[lang = "format_unsafe_arg"] |         #[lang = "format_unsafe_arg"] | ||||||
|         pub struct UnsafeArg { |         pub struct UnsafeArg { | ||||||
|             _private: (), |             _private: (), | ||||||
|  | @ -1185,6 +1187,7 @@ pub mod fmt { | ||||||
|                 UnsafeArg { _private: () } |                 UnsafeArg { _private: () } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         // endregion:fmt_before_1_89_0
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[derive(Copy, Clone)] |     #[derive(Copy, Clone)] | ||||||
|  | @ -1204,6 +1207,7 @@ pub mod fmt { | ||||||
|             Arguments { pieces, fmt: None, args: &[] } |             Arguments { pieces, fmt: None, args: &[] } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         // region:fmt_before_1_89_0
 | ||||||
|         pub fn new_v1_formatted( |         pub fn new_v1_formatted( | ||||||
|             pieces: &'a [&'static str], |             pieces: &'a [&'static str], | ||||||
|             args: &'a [rt::Argument<'a>], |             args: &'a [rt::Argument<'a>], | ||||||
|  | @ -1212,6 +1216,17 @@ pub mod fmt { | ||||||
|         ) -> Arguments<'a> { |         ) -> Arguments<'a> { | ||||||
|             Arguments { pieces, fmt: Some(fmt), args } |             Arguments { pieces, fmt: Some(fmt), args } | ||||||
|         } |         } | ||||||
|  |         // endregion:fmt_before_1_89_0
 | ||||||
|  | 
 | ||||||
|  |         // region:!fmt_before_1_89_0
 | ||||||
|  |         pub unsafe fn new_v1_formatted( | ||||||
|  |             pieces: &'a [&'static str], | ||||||
|  |             args: &'a [rt::Argument<'a>], | ||||||
|  |             fmt: &'a [rt::Placeholder], | ||||||
|  |         ) -> Arguments<'a> { | ||||||
|  |             Arguments { pieces, fmt: Some(fmt), args } | ||||||
|  |         } | ||||||
|  |         // endregion:!fmt_before_1_89_0
 | ||||||
| 
 | 
 | ||||||
|         pub const fn as_str(&self) -> Option<&'static str> { |         pub const fn as_str(&self) -> Option<&'static str> { | ||||||
|             match (self.pieces, self.args) { |             match (self.pieces, self.args) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Shoyu Vanilla
						Shoyu Vanilla