Skip to content

Commit

Permalink
librustc_typeck: use diag item instead of string compare
Browse files Browse the repository at this point in the history
  • Loading branch information
da-x committed Jul 18, 2020
1 parent d3df851 commit 28e2756
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/librustc_span/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ symbols! {
stop_after_dataflow,
str,
str_alloc,
string_type,
stringify,
struct_field_attributes,
struct_inherit,
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_typeck/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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
Expand Down

0 comments on commit 28e2756

Please sign in to comment.