Skip to content

Commit ee0bf5e

Browse files
committed
review comments
1 parent 2cb9181 commit ee0bf5e

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

src/librustc_typeck/check/op.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -527,19 +527,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
527527
appends the string on the right to the string \
528528
on the left and may require reallocation. This \
529529
requires ownership of the string on the left";
530-
debug!("check_str_addition: {:?} + {:?}", lhs_ty, rhs_ty);
530+
531+
let is_std_string = |ty| &format!("{:?}", ty) == "std::string::String";
532+
531533
match (&lhs_ty.sty, &rhs_ty.sty) {
532534
(&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str
533-
if (l_ty.sty == Str || &format!("{:?}", l_ty) == "std::string::String") && (
534-
r_ty.sty == Str ||
535-
&format!("{:?}", r_ty) == "std::string::String" ||
536-
&format!("{:?}", rhs_ty) == "&&str"
537-
) =>
535+
if (l_ty.sty == Str || is_std_string(l_ty)) && (
536+
r_ty.sty == Str || is_std_string(r_ty) ||
537+
&format!("{:?}", rhs_ty) == "&&str"
538+
) =>
538539
{
539540
if !is_assign { // Do not supply this message if `&str += &str`
540541
err.span_label(
541542
op.span,
542-
"`+` can't be used to concatenate two `&str` strings",
543+
"`+` cannot be used to concatenate two `&str` strings",
543544
);
544545
match source_map.span_to_snippet(lhs_expr.span) {
545546
Ok(lstring) => {
@@ -566,12 +567,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
566567
true
567568
}
568569
(&Ref(_, l_ty, _), &Adt(..)) // Handle `&str` & `&String` + `String`
569-
if (l_ty.sty == Str || &format!("{:?}", l_ty) == "std::string::String") &&
570-
&format!("{:?}", rhs_ty) == "std::string::String" =>
570+
if (l_ty.sty == Str || is_std_string(l_ty)) && is_std_string(rhs_ty) =>
571571
{
572572
err.span_label(
573573
op.span,
574-
"`+` can't be used to concatenate a `&str` with a `String`",
574+
"`+` cannot be used to concatenate a `&str` with a `String`",
575575
);
576576
match (
577577
source_map.span_to_snippet(lhs_expr.span),

src/test/ui/issues/issue-47377.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
44
LL | let _a = b + ", World!";
55
| - ^ ---------- &str
66
| | |
7-
| | `+` can't be used to concatenate two `&str` strings
7+
| | `+` cannot be used to concatenate two `&str` strings
88
| &str
99
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
1010
|

src/test/ui/issues/issue-47380.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
44
LL | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!";
55
| - ^ ---------- &str
66
| | |
7-
| | `+` can't be used to concatenate two `&str` strings
7+
| | `+` cannot be used to concatenate two `&str` strings
88
| &str
99
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
1010
|

src/test/ui/span/issue-39018.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
44
LL | let x = "Hello " + "World!";
55
| -------- ^ -------- &str
66
| | |
7-
| | `+` can't be used to concatenate two `&str` strings
7+
| | `+` cannot be used to concatenate two `&str` strings
88
| &str
99
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
1010
|
@@ -27,7 +27,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
2727
LL | let x = "Hello " + "World!".to_owned();
2828
| -------- ^ ------------------- std::string::String
2929
| | |
30-
| | `+` can't be used to concatenate a `&str` with a `String`
30+
| | `+` cannot be used to concatenate a `&str` with a `String`
3131
| &str
3232
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
3333
|
@@ -40,7 +40,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
4040
LL | let _ = &a + &b;
4141
| -- ^ -- &std::string::String
4242
| | |
43-
| | `+` can't be used to concatenate two `&str` strings
43+
| | `+` cannot be used to concatenate two `&str` strings
4444
| &std::string::String
4545
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
4646
|
@@ -53,7 +53,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
5353
LL | let _ = &a + b;
5454
| -- ^ - std::string::String
5555
| | |
56-
| | `+` can't be used to concatenate a `&str` with a `String`
56+
| | `+` cannot be used to concatenate a `&str` with a `String`
5757
| &std::string::String
5858
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
5959
|
@@ -78,7 +78,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
7878
LL | let _ = e + b;
7979
| - ^ - std::string::String
8080
| | |
81-
| | `+` can't be used to concatenate a `&str` with a `String`
81+
| | `+` cannot be used to concatenate a `&str` with a `String`
8282
| &std::string::String
8383
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
8484
|
@@ -91,7 +91,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
9191
LL | let _ = e + &b;
9292
| - ^ -- &std::string::String
9393
| | |
94-
| | `+` can't be used to concatenate two `&str` strings
94+
| | `+` cannot be used to concatenate two `&str` strings
9595
| &std::string::String
9696
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
9797
|
@@ -104,7 +104,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
104104
LL | let _ = e + d;
105105
| - ^ - &str
106106
| | |
107-
| | `+` can't be used to concatenate two `&str` strings
107+
| | `+` cannot be used to concatenate two `&str` strings
108108
| &std::string::String
109109
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
110110
|
@@ -117,7 +117,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
117117
LL | let _ = e + &d;
118118
| - ^ -- &&str
119119
| | |
120-
| | `+` can't be used to concatenate two `&str` strings
120+
| | `+` cannot be used to concatenate two `&str` strings
121121
| &std::string::String
122122
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
123123
|
@@ -150,7 +150,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
150150
LL | let _ = c + &d;
151151
| - ^ -- &&str
152152
| | |
153-
| | `+` can't be used to concatenate two `&str` strings
153+
| | `+` cannot be used to concatenate two `&str` strings
154154
| &str
155155
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
156156
|
@@ -163,7 +163,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&str`
163163
LL | let _ = c + d;
164164
| - ^ - &str
165165
| | |
166-
| | `+` can't be used to concatenate two `&str` strings
166+
| | `+` cannot be used to concatenate two `&str` strings
167167
| &str
168168
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
169169
|

src/test/ui/str/str-concat-on-double-ref.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0369]: binary operation `+` cannot be applied to type `&std::string::Stri
44
LL | let c = a + b;
55
| - ^ - &str
66
| | |
7-
| | `+` can't be used to concatenate two `&str` strings
7+
| | `+` cannot be used to concatenate two `&str` strings
88
| &std::string::String
99
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
1010
|

0 commit comments

Comments
 (0)