Skip to content

Commit 2a62b91

Browse files
authored
Update explanation of deref coercion
1 parent b298a58 commit 2a62b91

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/liballoc/string.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ use boxed::Box;
163163
/// [`&str`]s as arguments unless they need a `String` for some specific
164164
/// reason.
165165
///
166-
/// In certain cases Rust doesn't have enough information to make this conversion,
167-
/// known as deref coercion. For example, in this case a string slice implements
168-
/// a trait and the function takes anything that implements the trait, Rust would
169-
/// need to make two implicit conversions which Rust doesn't know how to do. The
170-
/// following example will not compile for that reason.
166+
/// In certain cases Rust doesn't have enough information to make this
167+
/// conversion, known as deref coercion. In the following example a string
168+
/// slice `&'a str` implements the trait `TraitExample`, and the function
169+
/// `example_func` takes anything that implements the trait. In this case Rust
170+
/// would need to make two implicit conversions, which Rust doesn't have the
171+
/// means to do. For that reason, the following example will not compile.
171172
///
172173
/// ```compile_fail,E0277
173174
/// trait TraitExample {}
@@ -182,9 +183,10 @@ use boxed::Box;
182183
/// }
183184
/// ```
184185
///
185-
/// What would work in this case is changing the line `example_func(&example_string);`
186-
/// to `example_func(example_string.to_str());`. This works because we're doing the
187-
/// conversion explicitly, rather than relying on the implicit conversion.
186+
/// What would work in this case is changing the line
187+
/// `example_func(&example_string);` to
188+
/// `example_func(example_string.to_str());`. This works because we're doing
189+
/// the conversion explicitly, rather than relying on the implicit conversion.
188190
///
189191
/// # Representation
190192
///

0 commit comments

Comments
 (0)