diff options
| author | bors <bors@rust-lang.org> | 2022-10-23 11:33:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-10-23 11:33:18 +0000 |
| commit | 9be2f35a4c1ed1b04aa4a6945b64763f599259ff (patch) | |
| tree | 0fcc4f7182b13a4711e19ecf0262767633c6b862 /compiler/rustc_span/src/source_map.rs | |
| parent | e64f1110c062f61746f222059439529a43ccf6dc (diff) | |
| parent | d35a24a0c203e7230d128230d28d8fbababebe8d (diff) | |
| download | rust-9be2f35a4c1ed1b04aa4a6945b64763f599259ff.tar.gz rust-9be2f35a4c1ed1b04aa4a6945b64763f599259ff.zip | |
Auto merge of #103431 - Dylan-DPC:rollup-oozfo89, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #101293 (Recover when unclosed char literal is parsed as a lifetime in some positions) - #101908 (Suggest let for assignment, and some code refactor) - #103192 (rustdoc: Eliminate uses of `EarlyDocLinkResolver::all_traits`) - #103226 (Check `needs_infer` before `needs_drop` during HIR generator analysis) - #103249 (resolve: Revert "Set effective visibilities for imports more precisely") - #103305 (Move some tests to more reasonable places) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_span/src/source_map.rs')
| -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 { |
