Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed May 17, 2019
1 parent 2cb9181 commit ee0bf5e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
20 changes: 10 additions & 10 deletions src/librustc_typeck/check/op.rs
Expand Up @@ -527,19 +527,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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) => {
Expand All @@ -566,12 +567,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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),
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-47377.stderr
Expand Up @@ -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
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-47380.stderr
Expand Up @@ -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
|
Expand Down
20 changes: 10 additions & 10 deletions src/test/ui/span/issue-39018.stderr
Expand Up @@ -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
|
Expand All @@ -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
|
Expand All @@ -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
|
Expand All @@ -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
|
Expand All @@ -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
|
Expand All @@ -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
|
Expand All @@ -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
|
Expand All @@ -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
|
Expand Down Expand Up @@ -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
|
Expand All @@ -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
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/str/str-concat-on-double-ref.stderr
Expand Up @@ -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
|
Expand Down

0 comments on commit ee0bf5e

Please sign in to comment.