Skip to content

Commit 0aeac96

Browse files
committed
Added tests for Add<char> & AddAssign<char> for String.
Made previous code tidy friendly.
1 parent 05fd1c7 commit 0aeac96

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

src/liballoc/string.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,8 @@ impl Add<&&String> for String {
20722072
/// // `a` is moved and can no longer be used here.
20732073
/// ```
20742074
///
2075-
/// If you want to keep using the initial `String`, you can clone it and append to the clone instead:
2075+
/// If you want to keep using the initial `String`, you can clone it and append to the
2076+
/// clone instead:
20762077
///
20772078
/// ```
20782079
/// let a = String::from("hello world! ");

src/liballoc/tests/string.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,15 @@ fn test_add_assign() {
195195
assert_eq!(s.as_str(), "");
196196
s += "abc";
197197
assert_eq!(s.as_str(), "abc");
198-
s += "ประเทศไทย中华Việt Nam";
199-
assert_eq!(s.as_str(), "abcประเทศไทย中华Việt Nam");
198+
s += "ประเทศไทย中华Việt Nam ";
199+
assert_eq!(s.as_str(), "abcประเทศไทย中华Việt Nam ");
200+
201+
let s2 = "OPS ".to_string();
202+
s += &s2;
203+
assert_eq!(s.as_str(), "abcประเทศไทย中华Việt Nam OPS ");
204+
205+
s += '👋';
206+
assert_eq!(s.as_str(), "abcประเทศไทย中华Việt Nam 👋");
200207
}
201208

202209
#[test]
@@ -304,9 +311,10 @@ fn test_str_clear() {
304311
fn test_str_add() {
305312
let a = String::from("12345");
306313
let b = a + "2";
307-
let b = b + "2";
308-
assert_eq!(b.len(), 7);
309-
assert_eq!(b, "1234522");
314+
let b = b + "2 ";
315+
let b = b + '👋';
316+
assert_eq!(b.len(), 12);
317+
assert_eq!(b, "1234522 👋");
310318
}
311319

312320
#[test]

src/libsyntax/parse/parser/expr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,8 @@ impl<'a> Parser<'a> {
10841084
if let token::Literal(token::Lit { kind: token::Integer, symbol, suffix })
10851085
= next_token.kind {
10861086
if self.token.span.hi() == next_token.span.lo() {
1087-
// FIXME: Should just be `&symbol.as_str()` but can't as of now due to Deref coercion
1087+
// FIXME: Should just be `&symbol.as_str()` but can't as of now due to
1088+
// Deref coercion.
10881089
// Issue: https://github.com/rust-lang/rust/issues/51916
10891090
let s = String::from("0.") + &symbol.as_str().get_str();
10901091
let kind = TokenKind::lit(token::Float, Symbol::intern(&s), suffix);

src/libsyntax_pos/symbol.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,8 @@ impl !Sync for SymbolStr {}
11291129
/// - `&*ss` is a `&str`;
11301130
/// - `&ss as &str` is a `&str`, which means that `&ss` can be passed to a
11311131
/// function expecting a `&str`.
1132-
///
1133-
/// FIXME: This has no meaning anymore since the addition of implementations
1134-
/// of `Add<char> for String`, `Add<&&str> for String`, and `Add<&&String> for String`.
1132+
///
1133+
/// FIXME: This has no meaning anymore since the addition of `impl Add<char> for String`.
11351134
/// Due to the outstanding Deref coercion issue this Deref implementation gets ignored.
11361135
/// Issue: https://github.com/rust-lang/rust/issues/51916
11371136
impl std::ops::Deref for SymbolStr {

0 commit comments

Comments
 (0)