diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2018-01-04 23:09:02 -0800 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2018-01-06 11:17:29 -0800 |
| commit | 3cfea33432f223b934bddc207224d90e6a39c280 (patch) | |
| tree | b8ba603356f0d233603c5a7bcfa26031488e75c1 /src/libsyntax/parse | |
| parent | 72176cf96cb79a0ebf62972b76dbe68c933bef4d (diff) | |
| download | rust-3cfea33432f223b934bddc207224d90e6a39c280.tar.gz rust-3cfea33432f223b934bddc207224d90e6a39c280.zip | |
wherein careful doc-decoration arithmetic proves quite the ICE-breaker
This `horizontal_trim` function strips the leading whitespace from doc-comments that have a left-asterisk-margin: /** * You know what I mean— * * comments like this! */ The index of the column of asterisks is `i`, and if trimming is deemed possible, we slice each line from `i+1` to the end of the line. But if, in particular, `i` was 0 _and_ there was an empty line (as in the example given in the reporting issue), we ended up panicking trying to slice an empty string from 0+1 (== 1). Let's tighten our check to say that we can't trim when `i` is even the same as the length of the line, not just when it's greater. (Any such cases would panic trying to slice `line` from `line.len()+1`.) Resolves #47197.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 23449ee69ab..49362f07799 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -101,7 +101,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { break; } } - if i > line.len() { + if i >= line.len() { can_trim = false; } if !can_trim { |
