Skip to content

Commit 2caf854

Browse files
committed
Auto merge of #74471 - da-x:string-type-diagnostic-item, r=petrochenkov
librustc_typeck: use diag item instead of string compare
2 parents 98efae8 + d077767 commit 2caf854

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/librustc_span/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ symbols! {
10431043
stop_after_dataflow,
10441044
str,
10451045
str_alloc,
1046+
string_type,
10461047
stringify,
10471048
struct_field_attributes,
10481049
struct_inherit,

src/librustc_typeck/check/op.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
562562
on the left and may require reallocation. This \
563563
requires ownership of the string on the left";
564564

565-
let is_std_string = |ty| &format!("{:?}", ty) == "std::string::String";
565+
let string_type = self.tcx.get_diagnostic_item(sym::string_type);
566+
let is_std_string = |ty: Ty<'tcx>| match ty.ty_adt_def() {
567+
Some(ty_def) => Some(ty_def.did) == string_type,
568+
None => false,
569+
};
566570

567571
match (&lhs_ty.kind, &rhs_ty.kind) {
568572
(&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str

0 commit comments

Comments
 (0)