review comments
This commit is contained in:
parent
2cb91816f2
commit
ee0bf5e6aa
@ -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) => {
|
||||
@ -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),
|
||||
|
@ -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
|
||||
|
|
||||
|
@ -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
|
||||
|
|
||||
|
@ -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
|
||||
|
|
||||
|
@ -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
|
||||
|
|
||||
|
Loading…
x
Reference in New Issue
Block a user