提交 28e27566 编写于 作者: D Dan Aloni

librustc_typeck: use diag item instead of string compare

上级 d3df8512
...@@ -1043,6 +1043,7 @@ ...@@ -1043,6 +1043,7 @@
stop_after_dataflow, stop_after_dataflow,
str, str,
str_alloc, str_alloc,
string_type,
stringify, stringify,
struct_field_attributes, struct_field_attributes,
struct_inherit, struct_inherit,
......
...@@ -562,7 +562,11 @@ fn check_str_addition( ...@@ -562,7 +562,11 @@ fn check_str_addition(
on the left and may require reallocation. This \ on the left and may require reallocation. This \
requires ownership of the string on the left"; 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) { match (&lhs_ty.kind, &rhs_ty.kind) {
(&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str (&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册