Skip to content

Commit d573838

Browse files
committed
Avoid redundant to_string
1 parent a9528a2 commit d573838

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
288288
let mode = no_match_data.mode;
289289
let tcx = self.tcx;
290290
let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty);
291-
let (mut ty_str, ty_file) = tcx.short_ty_string(rcvr_ty);
292-
let mut short_ty_str = with_forced_trimmed_paths!(rcvr_ty.to_string());
291+
let ((mut ty_str, ty_file), short_ty_str) = if trait_missing_method
292+
&& let ty::Dynamic(predicates, _, _) = rcvr_ty.kind() {
293+
((predicates.to_string(), None), with_forced_trimmed_paths!(predicates.to_string()))
294+
} else {
295+
(tcx.short_ty_string(rcvr_ty), with_forced_trimmed_paths!(rcvr_ty.to_string()))
296+
};
293297
let is_method = mode == Mode::MethodCall;
294298
let unsatisfied_predicates = &no_match_data.unsatisfied_predicates;
295299
let similar_candidate = no_match_data.similar_candidate;
@@ -328,11 +332,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
328332
}
329333
span = item_name.span;
330334

331-
if trait_missing_method && let ty::Dynamic(predicates, _, _) = rcvr_ty.kind() {
332-
ty_str = predicates.to_string();
333-
short_ty_str = with_forced_trimmed_paths!(predicates.to_string());
334-
}
335-
336335
// Don't show generic arguments when the method can't be found in any implementation (#81576).
337336
let mut ty_str_reported = ty_str.clone();
338337
if let ty::Adt(_, generics) = rcvr_ty.kind() {

0 commit comments

Comments
 (0)