diff options
| author | yukang <moorekang@gmail.com> | 2022-09-17 06:46:46 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2022-10-20 22:54:02 +0800 |
| commit | eb68e27e4c77af3e8fe3883cdf682592e910f3df (patch) | |
| tree | b0e131c4a19ca7d71ae3a1584b7e65aeb278328a /compiler/rustc_span/src | |
| parent | dcb376115066d111dbf5f13d5ac2a2dbe8c12add (diff) | |
| download | rust-eb68e27e4c77af3e8fe3883cdf682592e910f3df.tar.gz rust-eb68e27e4c77af3e8fe3883cdf682592e910f3df.zip | |
fix rust-lang#101880: suggest let for assignment, and some code refactor
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index 506ce6955d3..f9566eeee94 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -877,6 +877,26 @@ impl SourceMap { Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt(), None) } + /// Returns a new span to check next none-whitespace character or some specified expected character + /// If `expect` is none, the first span of non-whitespace character is returned. + /// If `expect` presented, the first span of the character `expect` is returned + /// Otherwise, the span reached to limit is returned. + pub fn span_look_ahead(&self, span: Span, expect: Option<&str>, limit: Option<usize>) -> Span { + let mut sp = span; + for _ in 0..limit.unwrap_or(100 as usize) { + sp = self.next_point(sp); + if let Ok(ref snippet) = self.span_to_snippet(sp) { + if expect.map_or(false, |es| snippet == es) { + break; + } + if expect.is_none() && snippet.chars().any(|c| !c.is_whitespace()) { + break; + } + } + } + sp + } + /// Finds the width of the character, either before or after the end of provided span, /// depending on the `forwards` parameter. fn find_width_of_character_at_span(&self, sp: Span, forwards: bool) -> u32 { |
