diff options
| author | kennytm <kennytm@gmail.com> | 2018-03-16 01:49:49 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-03-16 05:35:12 +0800 |
| commit | 5a7aa6cae543f9507d916624d2e54b7f53ee9616 (patch) | |
| tree | 9c5f320861902a6cd964887bdd2c87bc23d1c65e /src/libsyntax | |
| parent | bf270bb66ac392e0a1a220583e5e61c8a9d8b4a3 (diff) | |
| parent | 16d424f1471988ed4f7601b8eca42c72a23ca38e (diff) | |
| download | rust-5a7aa6cae543f9507d916624d2e54b7f53ee9616.tar.gz rust-5a7aa6cae543f9507d916624d2e54b7f53ee9616.zip | |
Rollup merge of #49007 - estebank:follow-up-47574, r=oli-obk
Some tweaks to "type parameters from outer function" diagnostic Follow up to #47574.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index c340f1b8c8a..951f8a871ca 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -622,13 +622,21 @@ impl CodeMap { sp } - /// Extend the given `Span` to just after the previous occurrence of `pat`. Return the same span - /// if no character could be found or if an error occurred while retrieving the code snippet. - pub fn span_extend_to_prev_str(&self, sp: Span, pat: &str) -> Span { - if let Ok(prev_source) = self.span_to_prev_source(sp) { - let prev_source = prev_source.rsplit(pat).nth(0).unwrap_or("").trim_left(); - if !prev_source.is_empty() && !prev_source.contains('\n') { - return sp.with_lo(BytePos(sp.lo().0 - prev_source.len() as u32)); + /// Extend the given `Span` to just after the previous occurrence of `pat` when surrounded by + /// whitespace. Return the same span if no character could be found or if an error occurred + /// while retrieving the code snippet. + pub fn span_extend_to_prev_str(&self, sp: Span, pat: &str, accept_newlines: bool) -> Span { + // assure that the pattern is delimited, to avoid the following + // fn my_fn() + // ^^^^ returned span without the check + // ---------- correct span + for ws in &[" ", "\t", "\n"] { + let pat = pat.to_owned() + ws; + if let Ok(prev_source) = self.span_to_prev_source(sp) { + let prev_source = prev_source.rsplit(&pat).nth(0).unwrap_or("").trim_left(); + if !prev_source.is_empty() && (!prev_source.contains('\n') || accept_newlines) { + return sp.with_lo(BytePos(sp.lo().0 - prev_source.len() as u32)); + } } } |
