about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorKivooeo <Kivooeo123@gmail.com>2025-04-23 15:58:50 +0500
committerKivooeo <Kivooeo123@gmail.com>2025-04-24 03:20:19 +0500
commitc9deaf6aaa8e389e11e39abb9aca77e6340d176e (patch)
treefe7cf8ead3db254ec39e5968d7580850dbb334e1 /compiler
parentb8005bff3248cfc6e327faf4fa631ac49bb49ba9 (diff)
downloadrust-c9deaf6aaa8e389e11e39abb9aca77e6340d176e.tar.gz
rust-c9deaf6aaa8e389e11e39abb9aca77e6340d176e.zip
fix for issue 135412
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_hir_typeck/src/cast.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs
index b19d9efe2c6..caf36ba47bd 100644
--- a/compiler/rustc_hir_typeck/src/cast.rs
+++ b/compiler/rustc_hir_typeck/src/cast.rs
@@ -501,12 +501,25 @@ impl<'a, 'tcx> CastCheck<'tcx> {
                             .must_apply_modulo_regions()
                         {
                             label = false;
-                            err.span_suggestion(
-                                self.span,
-                                "consider using the `From` trait instead",
-                                format!("{}::from({})", self.cast_ty, snippet),
-                                Applicability::MaybeIncorrect,
-                            );
+                            if let ty::Adt(def, args) = self.cast_ty.kind() {
+                                err.span_suggestion_verbose(
+                                    self.span,
+                                    "consider using the `From` trait instead",
+                                    format!(
+                                        "{}::from({})",
+                                        fcx.tcx.value_path_str_with_args(def.did(), args),
+                                        snippet
+                                    ),
+                                    Applicability::MaybeIncorrect,
+                                );
+                            } else {
+                                err.span_suggestion(
+                                    self.span,
+                                    "consider using the `From` trait instead",
+                                    format!("{}::from({})", self.cast_ty, snippet),
+                                    Applicability::MaybeIncorrect,
+                                );
+                            };
                         }
                     }