diff --git a/src/doc/book b/src/doc/book index e79dd62aa6339..28fa3d15b0bc6 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit e79dd62aa63396714278d484d91d48826737f47f +Subproject commit 28fa3d15b0bc67ea5e79eeff2198e4277fc61baf diff --git a/src/doc/edition-guide b/src/doc/edition-guide index f553fb26c60c4..e58bc4ca104e8 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit f553fb26c60c4623ea88a1cfe731eafe0643ce34 +Subproject commit e58bc4ca104e890ac56af846877c874c432a64b5 diff --git a/src/doc/nomicon b/src/doc/nomicon index 58e36e0e08dec..5004ad30d69f9 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit 58e36e0e08dec5a379ac568827c058e25990d6cd +Subproject commit 5004ad30d69f93553ceef74439fea2159d1f769e diff --git a/src/doc/reference b/src/doc/reference index 45558c464fb45..4b21b646669e0 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 45558c464fb458affbcdcb34323946da45c8a117 +Subproject commit 4b21b646669e0af49fae7cae301898dc4bfaa1f0 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index dcee312c66267..f3197ddf2abab 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit dcee312c66267eb5a2f6f1561354003950e29105 +Subproject commit f3197ddf2abab9abdbc029def8164f4a748b0d91 diff --git a/src/doc/rustc-guide b/src/doc/rustc-guide index 934380b7cfcea..941968db2fd9c 160000 --- a/src/doc/rustc-guide +++ b/src/doc/rustc-guide @@ -1 +1 @@ -Subproject commit 934380b7cfceaaa4e1b9bb0de4a372f32725520b +Subproject commit 941968db2fd9c85788a4f971c8e425d46b4cb734 diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index f7dff4c21f7c4..f806e5ca31f46 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1982,6 +1982,91 @@ impl Add<&str> for String { } } +// This had to be added to avoid breakage after adding `impl Add for String` +#[allow(missing_docs)] +#[stable(feature = "extra_add_string_and_dbl_ref_str", since = "1.41.0")] +impl Add<&&str> for String { + type Output = String; + + #[inline] + fn add(mut self, other: &&str) -> String { + self.push_str(other); + self + } +} + +// This had to be added to avoid breakage after adding `impl Add for String` +#[allow(missing_docs)] +#[stable(feature = "extra_add_string_and_ref_string", since = "1.41.0")] +impl Add<&String> for String { + type Output = String; + + #[inline] + fn add(mut self, other: &String) -> String { + self.push_str(other); + self + } +} + +// This had to be added to avoid breakage after adding `impl Add for String` +#[allow(missing_docs)] +#[stable(feature = "extra_add_string_and_dbl_ref_string", since = "1.41.0")] +impl Add<&&String> for String { + type Output = String; + + #[inline] + fn add(mut self, other: &&String) -> String { + self.push_str(other); + self + } +} + +/// Implements the `+` operator for concatenating a string and a char together. +/// +/// This consumes the `String` on the left-hand side and re-uses its buffer (growing it if +/// necessary). This is done to avoid allocating a new `String` and copying the entire contents on +/// every operation, which would lead to `O(n^2)` running time when building an `n`-byte string by +/// repeated concatenation. +/// +/// # Examples +/// +/// Concatenating a `String` with a `char` takes the `String` by value and copies the `char`: +/// +/// ``` +/// let a = String::from("hello world! "); +/// let b = '👋'; +/// let c = a + b; +/// // `a` is moved and can no longer be used here. +/// ``` +/// +/// If you want to keep using the initial `String`, you can clone it and append to the +/// clone instead: +/// +/// ``` +/// let a = String::from("hello world! "); +/// let b = '👋'; +/// let c = a.clone() + b; +/// // `a` is still valid here. +/// ``` +/// +/// Concatenating `char` to a `&str` slice can be done by converting the `&str` to a `String`: +/// +/// ``` +/// let a = "hello world! "; +/// let b = '👋'; +/// let c = a.to_string() + b; +/// ``` +#[stable(feature = "add_string_and_char", since = "1.41.0")] +impl Add for String { + type Output = String; + + #[inline] + fn add(mut self, other: char) -> String { + self.push(other); + self + } +} + /// Implements the `+=` operator for appending to a `String`. /// /// This has the same behavior as the [`push_str`][String::push_str] method. @@ -1993,6 +2078,28 @@ impl AddAssign<&str> for String { } } +/// Implements the `+=` operator for appending to a `String`. +/// +/// This has the same behavior as the [`push_str`][String::push_str] method. +#[stable(feature = "string_add_assign_string", since = "1.41.0")] +impl AddAssign<&String> for String { + #[inline] + fn add_assign(&mut self, other: &String) { + self.push_str(other); + } +} + +/// Implements the `+=` operator for appending a `char` to a `String`. +/// +/// This has the same behavior as the [`push`][String::push] method. +#[stable(feature = "string_add_assign_char", since = "1.41.0")] +impl AddAssign for String { + #[inline] + fn add_assign(&mut self, other: char) { + self.push(other); + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl ops::Index> for String { type Output = str; diff --git a/src/liballoc/tests/string.rs b/src/liballoc/tests/string.rs index 55edf56345b59..81f66d9e67f49 100644 --- a/src/liballoc/tests/string.rs +++ b/src/liballoc/tests/string.rs @@ -195,8 +195,10 @@ fn test_add_assign() { assert_eq!(s.as_str(), ""); s += "abc"; assert_eq!(s.as_str(), "abc"); - s += "ประเทศไทย中华Việt Nam"; - assert_eq!(s.as_str(), "abcประเทศไทย中华Việt Nam"); + s += "ประเทศไทย中华Việt Nam "; + assert_eq!(s.as_str(), "abcประเทศไทย中华Việt Nam "); + s += '👋'; + assert_eq!(s.as_str(), "abcประเทศไทย中华Việt Nam 👋") } #[test] @@ -304,9 +306,10 @@ fn test_str_clear() { fn test_str_add() { let a = String::from("12345"); let b = a + "2"; - let b = b + "2"; - assert_eq!(b.len(), 7); - assert_eq!(b, "1234522"); + let b = b + "2 "; + let b = b + '👋'; + assert_eq!(b.len(), 12); + assert_eq!(b, "1234522 👋"); } #[test] diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index a56a7bf1802c7..1f0f3f2020117 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -1110,7 +1110,7 @@ impl<'a> Parser<'a> { if let token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) = next_token.kind { if self.token.span.hi() == next_token.span.lo() { - let s = String::from("0.") + &symbol.as_str(); + let s = String::from("0.") + &*symbol.as_str(); let kind = TokenKind::lit(token::Float, Symbol::intern(&s), suffix); return Some(Token::new(kind, self.token.span.to(next_token.span))); } diff --git a/src/llvm-project b/src/llvm-project index cf9304d6d0c6a..14a3b123074e0 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit cf9304d6d0c6a66c27a1664dd55d8bcc8be0bf09 +Subproject commit 14a3b123074e066d64a99886941473058e52197d diff --git a/src/tools/cargo b/src/tools/cargo index 8280633db680d..5da4b4d479638 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 8280633db680dec5bfe1de25156d1a1d53e6d190 +Subproject commit 5da4b4d47963868d9878480197581ccbbdaece74 diff --git a/src/tools/clippy b/src/tools/clippy index b4f1769734b62..c8e3cfbdd9978 160000 --- a/src/tools/clippy +++ b/src/tools/clippy @@ -1 +1 @@ -Subproject commit b4f1769734b6204fc6bece8556b7b80a7683271e +Subproject commit c8e3cfbdd997839c771ca32c7ac860fe95149a04 diff --git a/src/tools/miri b/src/tools/miri index 67a63f89d8c0e..d4e4fe71e6a95 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit 67a63f89d8c0e5b22fb52cc33274283819f41792 +Subproject commit d4e4fe71e6a9568f5d081d99f1c621c5a4ddd7db