Skip to content

Commit 7981aa6

Browse files
committed
doc: Fix extraneous as_slice()'s in docstrings
1 parent 061d843 commit 7981aa6

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

src/doc/style/errors/ergonomics.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ fn write_info(info: &Info) -> Result<(), IoError> {
2222
let mut file = File::open_mode(&Path::new("my_best_friends.txt"),
2323
Open, Write);
2424
// Early return on error
25-
try!(file.write_line(format!("name: {}", info.name).as_slice()));
26-
try!(file.write_line(format!("age: {}", info.age).as_slice()));
27-
try!(file.write_line(format!("rating: {}", info.rating).as_slice()));
25+
try!(file.write_line(&format!("name: {}", info.name)));
26+
try!(file.write_line(&format!("age: {}", info.age)));
27+
try!(file.write_line(&format!("rating: {}", info.rating)));
2828
return Ok(());
2929
}
3030
```
@@ -44,15 +44,15 @@ fn write_info(info: &Info) -> Result<(), IoError> {
4444
let mut file = File::open_mode(&Path::new("my_best_friends.txt"),
4545
Open, Write);
4646
// Early return on error
47-
match file.write_line(format!("name: {}", info.name).as_slice()) {
47+
match file.write_line(&format!("name: {}", info.name)) {
4848
Ok(_) => (),
4949
Err(e) => return Err(e)
5050
}
51-
match file.write_line(format!("age: {}", info.age).as_slice()) {
51+
match file.write_line(&format!("age: {}", info.age)) {
5252
Ok(_) => (),
5353
Err(e) => return Err(e)
5454
}
55-
return file.write_line(format!("rating: {}", info.rating).as_slice());
55+
return file.write_line(&format!("rating: {}", info.rating));
5656
}
5757
```
5858

src/libcollections/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
//! // for details, and the function `pad` can be used to pad strings.
199199
//! let decimals = f.precision().unwrap_or(3);
200200
//! let string = f64::to_str_exact(magnitude, decimals);
201-
//! f.pad_integral(true, "", string.as_slice())
201+
//! f.pad_integral(true, "", &string)
202202
//! }
203203
//! }
204204
//!

src/libcollections/string.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl String {
139139
/// ```rust
140140
/// let input = b"Hello \xF0\x90\x80World";
141141
/// let output = String::from_utf8_lossy(input);
142-
/// assert_eq!(output.as_slice(), "Hello \u{FFFD}World");
142+
/// assert_eq!(output, "Hello \u{FFFD}World");
143143
/// ```
144144
#[stable(feature = "rust1", since = "1.0.0")]
145145
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> Cow<'a, str> {
@@ -355,7 +355,7 @@ impl String {
355355
/// ```
356356
/// let mut s = String::from_str("foo");
357357
/// s.push_str("bar");
358-
/// assert_eq!(s.as_slice(), "foobar");
358+
/// assert_eq!(s, "foobar");
359359
/// ```
360360
#[inline]
361361
#[stable(feature = "rust1", since = "1.0.0")]
@@ -450,7 +450,7 @@ impl String {
450450
/// s.push('1');
451451
/// s.push('2');
452452
/// s.push('3');
453-
/// assert_eq!(s.as_slice(), "abc123");
453+
/// assert_eq!(s, "abc123");
454454
/// ```
455455
#[inline]
456456
#[stable(feature = "rust1", since = "1.0.0")]
@@ -503,7 +503,7 @@ impl String {
503503
/// ```
504504
/// let mut s = String::from_str("hello");
505505
/// s.truncate(2);
506-
/// assert_eq!(s.as_slice(), "he");
506+
/// assert_eq!(s, "he");
507507
/// ```
508508
#[inline]
509509
#[stable(feature = "rust1", since = "1.0.0")]
@@ -622,7 +622,7 @@ impl String {
622622
/// assert!(vec == &[104, 101, 108, 108, 111]);
623623
/// vec.reverse();
624624
/// }
625-
/// assert_eq!(s.as_slice(), "olleh");
625+
/// assert_eq!(s, "olleh");
626626
/// ```
627627
#[inline]
628628
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/result.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@
178178
//! fn write_info(info: &Info) -> Result<(), IoError> {
179179
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
180180
//! // Early return on error
181-
//! if let Err(e) = file.write_line(format!("name: {}", info.name).as_slice()) {
181+
//! if let Err(e) = file.write_line(&format!("name: {}", info.name)) {
182182
//! return Err(e)
183183
//! }
184-
//! if let Err(e) = file.write_line(format!("age: {}", info.age).as_slice()) {
184+
//! if let Err(e) = file.write_line(&format!("age: {}", info.age)) {
185185
//! return Err(e)
186186
//! }
187-
//! return file.write_line(format!("rating: {}", info.rating).as_slice());
187+
//! return file.write_line(&format!("rating: {}", info.rating));
188188
//! }
189189
//! ```
190190
//!
@@ -202,9 +202,9 @@
202202
//! fn write_info(info: &Info) -> Result<(), IoError> {
203203
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
204204
//! // Early return on error
205-
//! try!(file.write_line(format!("name: {}", info.name).as_slice()));
206-
//! try!(file.write_line(format!("age: {}", info.age).as_slice()));
207-
//! try!(file.write_line(format!("rating: {}", info.rating).as_slice()));
205+
//! try!(file.write_line(&format!("name: {}", info.name)));
206+
//! try!(file.write_line(&format!("age: {}", info.age)));
207+
//! try!(file.write_line(&format!("rating: {}", info.rating)));
208208
//! return Ok(());
209209
//! }
210210
//! ```

src/libgetopts/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
//!
4747
//! fn print_usage(program: &str, opts: &[OptGroup]) {
4848
//! let brief = format!("Usage: {} [options]", program);
49-
//! print!("{}", usage(brief.as_slice(), opts));
49+
//! print!("{}", usage(brief, opts));
5050
//! }
5151
//!
5252
//! fn main() {
@@ -63,17 +63,17 @@
6363
//! Err(f) => { panic!(f.to_string()) }
6464
//! };
6565
//! if matches.opt_present("h") {
66-
//! print_usage(program.as_slice(), opts);
66+
//! print_usage(program, opts);
6767
//! return;
6868
//! }
6969
//! let output = matches.opt_str("o");
7070
//! let input = if !matches.free.is_empty() {
7171
//! matches.free[0].clone()
7272
//! } else {
73-
//! print_usage(program.as_slice(), opts);
73+
//! print_usage(program, opts);
7474
//! return;
7575
//! };
76-
//! do_work(input.as_slice(), output);
76+
//! do_work(input, output);
7777
//! }
7878
//! ```
7979

src/librustc_bitflags/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
/// let mut flags = FLAG_A | FLAG_B;
8787
/// flags.clear();
8888
/// assert!(flags.is_empty());
89-
/// assert_eq!(format!("{:?}", flags).as_slice(), "hi!");
89+
/// assert_eq!(format!("{:?}", flags), "hi!");
9090
/// }
9191
/// ```
9292
///

src/libserialize/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
//! let json_str: String = json_obj.to_string();
189189
//!
190190
//! // Deserialize like before
191-
//! let decoded: TestStruct = json::decode(json_str.as_slice()).unwrap();
191+
//! let decoded: TestStruct = json::decode(json_str)).unwrap();
192192
//! }
193193
//! ```
194194

0 commit comments

Comments
 (0)