Skip to content

Commit ec2b1c6

Browse files
committed
Revised comments and fixed a deref issue in libsyntax\parse\parser\expr.rs
1 parent 0aeac96 commit ec2b1c6

File tree

3 files changed

+10
-59
lines changed

3 files changed

+10
-59
lines changed

src/liballoc/string.rs

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,8 +1982,9 @@ impl Add<&str> for String {
19821982
}
19831983
}
19841984

1985+
// This had to be added to avoid breakage after adding `impl Add<char> for String`
19851986
#[allow(missing_docs)]
1986-
#[stable(feature = "add_string_and_dbl_ref_str", since = "1.41.0")]
1987+
#[stable(feature = "extra_add_string_and_dbl_ref_str", since = "1.41.0")]
19871988
impl Add<&&str> for String {
19881989
type Output = String;
19891990

@@ -1994,44 +1995,9 @@ impl Add<&&str> for String {
19941995
}
19951996
}
19961997

1997-
/// Implements the `+` operator for concatenating two `String`s.
1998-
///
1999-
/// This consumes the `String` on the left-hand side and re-uses its buffer (growing it if
2000-
/// necessary). This is done to avoid allocating a new `String` and copying the entire contents on
2001-
/// every operation, which would lead to `O(n^2)` running time when building an `n`-byte string by
2002-
/// repeated concatenation.
2003-
///
2004-
/// The string on the right-hand side is only borrowed; its contents are copied into the returned
2005-
/// `String`.
2006-
///
2007-
/// # Examples
2008-
///
2009-
/// Concatenating two `String`s takes the first by value and borrows the second:
2010-
///
2011-
/// ```
2012-
/// let a = String::from("hello");
2013-
/// let b = String::from(" world");
2014-
/// let c = a + &b;
2015-
/// // `a` is moved and can no longer be used here.
2016-
/// ```
2017-
///
2018-
/// If you want to keep using the first `String`, you can clone it and append to the clone instead:
2019-
///
2020-
/// ```
2021-
/// let a = String::from("hello");
2022-
/// let b = String::from(" world");
2023-
/// let c = a.clone() + &b;
2024-
/// // `a` is still valid here.
2025-
/// ```
2026-
///
2027-
/// Concatenating `&str` slices can be done by converting the first to a `String`:
2028-
///
2029-
/// ```
2030-
/// let a = "hello";
2031-
/// let b = " world";
2032-
/// let c = a.to_string() + b;
2033-
/// ```
2034-
#[stable(feature = "add_string_and_ref_string", since = "1.41.0")]
1998+
// This had to be added to avoid breakage after adding `impl Add<char> for String`
1999+
#[allow(missing_docs)]
2000+
#[stable(feature = "extra_add_string_and_ref_string", since = "1.41.0")]
20352001
impl Add<&String> for String {
20362002
type Output = String;
20372003

@@ -2042,8 +2008,9 @@ impl Add<&String> for String {
20422008
}
20432009
}
20442010

2011+
// This had to be added to avoid breakage after adding `impl Add<char> for String`
20452012
#[allow(missing_docs)]
2046-
#[stable(feature = "add_string_and_dbl_ref_string", since = "1.41.0")]
2013+
#[stable(feature = "extra_add_string_and_dbl_ref_string", since = "1.41.0")]
20472014
impl Add<&&String> for String {
20482015
type Output = String;
20492016

@@ -2114,7 +2081,7 @@ impl AddAssign<&str> for String {
21142081
/// Implements the `+=` operator for appending to a `String`.
21152082
///
21162083
/// This has the same behavior as the [`push_str`][String::push_str] method.
2117-
#[stable(feature = "stringaddassign_string", since = "1.41.0")]
2084+
#[stable(feature = "string_add_assign_string", since = "1.41.0")]
21182085
impl AddAssign<&String> for String {
21192086
#[inline]
21202087
fn add_assign(&mut self, other: &String) {
@@ -2125,7 +2092,7 @@ impl AddAssign<&String> for String {
21252092
/// Implements the `+=` operator for appending a `char` to a `String`.
21262093
///
21272094
/// This has the same behavior as the [`push`][String::push] method.
2128-
#[stable(feature = "stringaddassign_char", since = "1.41.0")]
2095+
#[stable(feature = "string_add_assign_char", since = "1.41.0")]
21292096
impl AddAssign<char> for String {
21302097
#[inline]
21312098
fn add_assign(&mut self, other: char) {

src/libsyntax/parse/parser/expr.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,10 +1084,7 @@ 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
1088-
// Deref coercion.
1089-
// Issue: https://github.com/rust-lang/rust/issues/51916
1090-
let s = String::from("0.") + &symbol.as_str().get_str();
1087+
let s = String::from("0.") + &*symbol.as_str();
10911088
let kind = TokenKind::lit(token::Float, Symbol::intern(&s), suffix);
10921089
return Some(Token::new(kind, self.token.span.to(next_token.span)));
10931090
}

src/libsyntax_pos/symbol.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,15 +1104,6 @@ pub struct SymbolStr {
11041104
string: &'static str,
11051105
}
11061106

1107-
/// FIXME: This is not needed once we are able to fix the Deref coercion issue.
1108-
/// Issue: https://github.com/rust-lang/rust/issues/51916
1109-
impl SymbolStr {
1110-
#[inline]
1111-
pub fn get_str(&self) -> &str {
1112-
self.string
1113-
}
1114-
}
1115-
11161107
// This impl allows a `SymbolStr` to be directly equated with a `String` or
11171108
// `&str`.
11181109
impl<T: std::ops::Deref<Target = str>> std::cmp::PartialEq<T> for SymbolStr {
@@ -1129,10 +1120,6 @@ impl !Sync for SymbolStr {}
11291120
/// - `&*ss` is a `&str`;
11301121
/// - `&ss as &str` is a `&str`, which means that `&ss` can be passed to a
11311122
/// function expecting a `&str`.
1132-
///
1133-
/// FIXME: This has no meaning anymore since the addition of `impl Add<char> for String`.
1134-
/// Due to the outstanding Deref coercion issue this Deref implementation gets ignored.
1135-
/// Issue: https://github.com/rust-lang/rust/issues/51916
11361123
impl std::ops::Deref for SymbolStr {
11371124
type Target = str;
11381125
#[inline]

0 commit comments

Comments
 (0)