]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #74471 - da-x:string-type-diagnostic-item, r=petrochenkov
authorbors <bors@rust-lang.org>
Tue, 28 Jul 2020 20:00:37 +0000 (20:00 +0000)
committerbors <bors@rust-lang.org>
Tue, 28 Jul 2020 20:00:37 +0000 (20:00 +0000)
librustc_typeck: use diag item instead of string compare

src/librustc_span/symbol.rs
src/librustc_typeck/check/op.rs

index dadf040304d4683b81d22cad0295ae3650dc12f6..98776a0478237495e80c53b76f93c7225ee39d8a 100644 (file)
         stop_after_dataflow,
         str,
         str_alloc,
+        string_type,
         stringify,
         struct_field_attributes,
         struct_inherit,
index 41aac3569d115f8e2e364eeb393e61db8f41add5..fd516c88ec61aac2896f340e66d4baee1236c065 100644 (file)
@@ -562,7 +562,11 @@ fn check_str_addition(
                    on the left and may require reallocation. This \
                    requires ownership of the string on the left";
 
-        let is_std_string = |ty| &format!("{:?}", ty) == "std::string::String";
+        let string_type = self.tcx.get_diagnostic_item(sym::string_type);
+        let is_std_string = |ty: Ty<'tcx>| match ty.ty_adt_def() {
+            Some(ty_def) => Some(ty_def.did) == string_type,
+            None => false,
+        };
 
         match (&lhs_ty.kind, &rhs_ty.kind) {
             (&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str