]> git.lizzy.rs Git - rust.git/commitdiff
review comments
authorEsteban Küber <esteban@kuber.com.ar>
Fri, 17 May 2019 03:05:00 +0000 (20:05 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Fri, 17 May 2019 04:09:39 +0000 (21:09 -0700)
src/librustc_typeck/check/op.rs
src/test/ui/issues/issue-47377.stderr
src/test/ui/issues/issue-47380.stderr
src/test/ui/span/issue-39018.stderr
src/test/ui/str/str-concat-on-double-ref.stderr

index 619900b6ad903f3ab22e1c881bc8982594e9cfb4..26a5bdfef7d66b511f6da9c8fb8c2547ca3f95f9 100644 (file)
@@ -527,19 +527,20 @@ fn check_str_addition(
                    appends the string on the right to the string \
                    on the left and may require reallocation. This \
                    requires ownership of the string on the left";
-        debug!("check_str_addition: {:?} + {:?}", lhs_ty, rhs_ty);
+
+        let is_std_string = |ty| &format!("{:?}", ty) == "std::string::String";
+
         match (&lhs_ty.sty, &rhs_ty.sty) {
             (&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str
-            if (l_ty.sty == Str || &format!("{:?}", l_ty) == "std::string::String") && (
-                    r_ty.sty == Str ||
-                    &format!("{:?}", r_ty) == "std::string::String" ||
-                    &format!("{:?}", rhs_ty) == "&&str"
-                ) =>
+                if (l_ty.sty == Str || is_std_string(l_ty)) && (
+                        r_ty.sty == Str || is_std_string(r_ty) ||
+                        &format!("{:?}", rhs_ty) == "&&str"
+                    ) =>
             {
                 if !is_assign { // Do not supply this message if `&str += &str`
                     err.span_label(
                         op.span,
-                        "`+` can't be used to concatenate two `&str` strings",
+                        "`+` cannot be used to concatenate two `&str` strings",
                     );
                     match source_map.span_to_snippet(lhs_expr.span) {
                         Ok(lstring) => {
@@ -566,12 +567,11 @@ fn check_str_addition(
                 true
             }
             (&Ref(_, l_ty, _), &Adt(..)) // Handle `&str` & `&String` + `String`
-            if (l_ty.sty == Str || &format!("{:?}", l_ty) == "std::string::String") &&
-                &format!("{:?}", rhs_ty) == "std::string::String" =>
+                if (l_ty.sty == Str || is_std_string(l_ty)) && is_std_string(rhs_ty) =>
             {
                 err.span_label(
                     op.span,
-                    "`+` can't be used to concatenate a `&str` with a `String`",
+                    "`+` cannot be used to concatenate a `&str` with a `String`",
                 );
                 match (
                     source_map.span_to_snippet(lhs_expr.span),
index 88466131e3144db988a478ad59b6dafd21d7b8b9..7d11a8c8021283fc54c8c3c89e5ca281a5bbe6f7 100644 (file)
@@ -4,7 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
 LL |      let _a = b + ", World!";
    |               - ^ ---------- &str
    |               | |
-   |               | `+` can't be used to concatenate two `&str` strings
+   |               | `+` cannot be used to concatenate two `&str` strings
    |               &str
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
index d69101eab4c46e2f5bd4e9e0aeb4b67eb55aa6c9..89a154c5109d80e0c4b02c28c77a0ff514205827 100644 (file)
@@ -4,7 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
 LL |     println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!";
    |                                      - ^ ---------- &str
    |                                      | |
-   |                                      | `+` can't be used to concatenate two `&str` strings
+   |                                      | `+` cannot be used to concatenate two `&str` strings
    |                                      &str
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
index b174e95c8a1d45c9a8497ef33c8b77028af6d1b3..cdb9c1168d8e7a2f2a5518c7b522b067075c702b 100644 (file)
@@ -4,7 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
 LL |     let x = "Hello " + "World!";
    |             -------- ^ -------- &str
    |             |        |
-   |             |        `+` can't be used to concatenate two `&str` strings
+   |             |        `+` cannot be used to concatenate two `&str` strings
    |             &str
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
@@ -27,7 +27,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
 LL |     let x = "Hello " + "World!".to_owned();
    |             -------- ^ ------------------- std::string::String
    |             |        |
-   |             |        `+` can't be used to concatenate a `&str` with a `String`
+   |             |        `+` cannot be used to concatenate a `&str` with a `String`
    |             &str
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
@@ -40,7 +40,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
 LL |     let _ = &a + &b;
    |             -- ^ -- &std::string::String
    |             |  |
-   |             |  `+` can't be used to concatenate two `&str` strings
+   |             |  `+` cannot be used to concatenate two `&str` strings
    |             &std::string::String
 help: String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
@@ -53,7 +53,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
 LL |     let _ = &a + b;
    |             -- ^ - std::string::String
    |             |  |
-   |             |  `+` can't be used to concatenate a `&str` with a `String`
+   |             |  `+` cannot be used to concatenate a `&str` with a `String`
    |             &std::string::String
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
@@ -78,7 +78,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
 LL |     let _ = e + b;
    |             - ^ - std::string::String
    |             | |
-   |             | `+` can't be used to concatenate a `&str` with a `String`
+   |             | `+` cannot be used to concatenate a `&str` with a `String`
    |             &std::string::String
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
@@ -91,7 +91,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
 LL |     let _ = e + &b;
    |             - ^ -- &std::string::String
    |             | |
-   |             | `+` can't be used to concatenate two `&str` strings
+   |             | `+` cannot be used to concatenate two `&str` strings
    |             &std::string::String
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
@@ -104,7 +104,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
 LL |     let _ = e + d;
    |             - ^ - &str
    |             | |
-   |             | `+` can't be used to concatenate two `&str` strings
+   |             | `+` cannot be used to concatenate two `&str` strings
    |             &std::string::String
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
@@ -117,7 +117,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
 LL |     let _ = e + &d;
    |             - ^ -- &&str
    |             | |
-   |             | `+` can't be used to concatenate two `&str` strings
+   |             | `+` cannot be used to concatenate two `&str` strings
    |             &std::string::String
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
@@ -150,7 +150,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
 LL |     let _ = c + &d;
    |             - ^ -- &&str
    |             | |
-   |             | `+` can't be used to concatenate two `&str` strings
+   |             | `+` cannot be used to concatenate two `&str` strings
    |             &str
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
@@ -163,7 +163,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
 LL |     let _ = c + d;
    |             - ^ - &str
    |             | |
-   |             | `+` can't be used to concatenate two `&str` strings
+   |             | `+` cannot be used to concatenate two `&str` strings
    |             &str
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |
index 17d9475b9c07db2f5aca9cac7956feee13dee934..3e53cdc4d98ca36c8d9ad606d833cf772704847b 100644 (file)
@@ -4,7 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
 LL |     let c = a + b;
    |             - ^ - &str
    |             | |
-   |             | `+` can't be used to concatenate two `&str` strings
+   |             | `+` cannot be used to concatenate two `&str` strings
    |             &std::string::String
 help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
    |