Skip to content

Commit 3cfea33

Browse files
committed
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.
1 parent 72176cf commit 3cfea33

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/libsyntax/parse/lexer/comments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String {
101101
break;
102102
}
103103
}
104-
if i > line.len() {
104+
if i >= line.len() {
105105
can_trim = false;
106106
}
107107
if !can_trim {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// @has issue_47197_blank_line_in_doc_block/fn.whose_woods_these_are_i_think_i_know.html
12+
13+
/**
14+
* snow
15+
16+
* ice
17+
*/
18+
pub fn whose_woods_these_are_i_think_i_know() {}

0 commit comments

Comments
 (0)