diff options
| author | bors <bors@rust-lang.org> | 2014-12-08 02:32:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-12-08 02:32:31 +0000 |
| commit | 83a44c7fa676b4e5e546ce3d4624e585f9a1e899 (patch) | |
| tree | 36d7db1d2567d86816d4ac6a1ec86276974dbc65 /src/libsyntax/parse | |
| parent | 8bca470c5acf13aa20022a2c462a89f72de721fc (diff) | |
| parent | 1fea900de7f11d665086141806246842c03b9fc5 (diff) | |
| download | rust-83a44c7fa676b4e5e546ce3d4624e585f9a1e899.tar.gz rust-83a44c7fa676b4e5e546ce3d4624e585f9a1e899.zip | |
auto merge of #19378 : japaric/rust/no-as-slice, r=alexcrichton
Now that we have an overloaded comparison (`==`) operator, and that `Vec`/`String` deref to `[T]`/`str` on method calls, many `as_slice()`/`as_mut_slice()`/`to_string()` calls have become redundant. This patch removes them. These were the most common patterns: - `assert_eq(test_output.as_slice(), "ground truth")` -> `assert_eq(test_output, "ground truth")` - `assert_eq(test_output, "ground truth".to_string())` -> `assert_eq(test_output, "ground truth")` - `vec.as_mut_slice().sort()` -> `vec.sort()` - `vec.as_slice().slice(from, to)` -> `vec.slice(from_to)` --- Note that e.g. `a_string.push_str(b_string.as_slice())` has been left untouched in this PR, since we first need to settle down whether we want to favor the `&*b_string` or the `b_string[]` notation. This is rebased on top of #19167 cc @alexcrichton @aturon
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 37 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 2 |
3 files changed, 21 insertions, 23 deletions
diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index b62d2d744c9..aeec6ee13fd 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -66,21 +66,20 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { let mut j = lines.len(); // first line of all-stars should be omitted if lines.len() > 0 && - lines[0].as_slice().chars().all(|c| c == '*') { + lines[0].chars().all(|c| c == '*') { i += 1; } - while i < j && lines[i].as_slice().trim().is_empty() { + while i < j && lines[i].trim().is_empty() { i += 1; } // like the first, a last line of all stars should be omitted if j > i && lines[j - 1] - .as_slice() .chars() .skip(1) .all(|c| c == '*') { j -= 1; } - while j > i && lines[j - 1].as_slice().trim().is_empty() { + while j > i && lines[j - 1].trim().is_empty() { j -= 1; } return lines.slice(i, j).iter().map(|x| (*x).clone()).collect(); @@ -92,7 +91,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { let mut can_trim = true; let mut first = true; for line in lines.iter() { - for (j, c) in line.as_slice().chars().enumerate() { + for (j, c) in line.chars().enumerate() { if j > i || !"* \t".contains_char(c) { can_trim = false; break; @@ -117,7 +116,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { if can_trim { lines.iter().map(|line| { - line.as_slice().slice(i + 1, line.len()).to_string() + line.slice(i + 1, line.len()).to_string() }).collect() } else { lines @@ -228,7 +227,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut Vec<String> , let s1 = match all_whitespace(s.as_slice(), col) { Some(col) => { if col < len { - s.as_slice().slice(col, len).to_string() + s.slice(col, len).to_string() } else { "".to_string() } @@ -265,7 +264,7 @@ fn read_block_comment(rdr: &mut StringReader, if is_block_doc_comment(curr_line.as_slice()) { return } - assert!(!curr_line.as_slice().contains_char('\n')); + assert!(!curr_line.contains_char('\n')); lines.push(curr_line); } else { let mut level: int = 1; @@ -390,41 +389,41 @@ mod test { #[test] fn test_block_doc_comment_1() { let comment = "/**\n * Test \n ** Test\n * Test\n*/"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped, " Test \n* Test\n Test".to_string()); + assert_eq!(stripped, " Test \n* Test\n Test"); } #[test] fn test_block_doc_comment_2() { let comment = "/**\n * Test\n * Test\n*/"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped, " Test\n Test".to_string()); + assert_eq!(stripped, " Test\n Test"); } #[test] fn test_block_doc_comment_3() { let comment = "/**\n let a: *int;\n *a = 5;\n*/"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped, " let a: *int;\n *a = 5;".to_string()); + assert_eq!(stripped, " let a: *int;\n *a = 5;"); } #[test] fn test_block_doc_comment_4() { let comment = "/*******************\n test\n *********************/"; let stripped = strip_doc_comment_decoration(comment); - assert_eq!(stripped, " test".to_string()); + assert_eq!(stripped, " test"); } #[test] fn test_line_doc_comment() { let stripped = strip_doc_comment_decoration("/// test"); - assert_eq!(stripped, " test".to_string()); + assert_eq!(stripped, " test"); let stripped = strip_doc_comment_decoration("///! test"); - assert_eq!(stripped, " test".to_string()); + assert_eq!(stripped, " test"); let stripped = strip_doc_comment_decoration("// test"); - assert_eq!(stripped, " test".to_string()); + assert_eq!(stripped, " test"); let stripped = strip_doc_comment_decoration("// test"); - assert_eq!(stripped, " test".to_string()); + assert_eq!(stripped, " test"); let stripped = strip_doc_comment_decoration("///test"); - assert_eq!(stripped, "test".to_string()); + assert_eq!(stripped, "test"); let stripped = strip_doc_comment_decoration("///!test"); - assert_eq!(stripped, "test".to_string()); + assert_eq!(stripped, "test"); let stripped = strip_doc_comment_decoration("//test"); - assert_eq!(stripped, "test".to_string()); + assert_eq!(stripped, "test"); } } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index b282db5ba2b..ab2c15d54c5 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -265,7 +265,7 @@ impl<'a> StringReader<'a> { /// Calls `f` with a string slice of the source text spanning from `start` /// up to but excluding `end`. fn with_str_from_to<T>(&self, start: BytePos, end: BytePos, f: |s: &str| -> T) -> T { - f(self.filemap.src.as_slice().slice( + f(self.filemap.src.slice( self.byte_offset(start).to_uint(), self.byte_offset(end).to_uint())) } @@ -321,7 +321,6 @@ impl<'a> StringReader<'a> { let last_char = self.curr.unwrap(); let next = self.filemap .src - .as_slice() .char_range_at(current_byte_offset); let byte_offset_diff = next.next - current_byte_offset; self.pos = self.pos + Pos::from_uint(byte_offset_diff); @@ -343,7 +342,7 @@ impl<'a> StringReader<'a> { pub fn nextch(&self) -> Option<char> { let offset = self.byte_offset(self.pos).to_uint(); if offset < self.filemap.src.len() { - Some(self.filemap.src.as_slice().char_at(offset)) + Some(self.filemap.src.char_at(offset)) } else { None } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 8d0c2de048a..951fe11a470 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -954,7 +954,7 @@ mod test { }\ ]\ }\ -]".to_string() +]" ); } |
