Skip to content

Commit a088f21

Browse files
committed
removed replacen
1 parent 8722d82 commit a088f21

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

compiler/rustc_hir_typeck/src/cast.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,15 @@ impl<'a, 'tcx> CastCheck<'tcx> {
501501
.must_apply_modulo_regions()
502502
{
503503
label = false;
504-
if !self.cast_ty.is_primitive() {
505-
let type_to_cast = self.cast_ty.to_string().replacen('<', "::<", 1);
504+
if let ty::Adt(def, args) = self.cast_ty.kind() {
506505
err.span_suggestion_verbose(
507506
self.span,
508507
"consider using the `From` trait instead",
509-
format!("{}::from({})", type_to_cast, snippet),
508+
format!(
509+
"{}::from({})",
510+
fcx.tcx.value_path_str_with_args(def.did(), args),
511+
snippet
512+
),
510513
Applicability::MaybeIncorrect,
511514
);
512515
} else {
@@ -516,7 +519,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
516519
format!("{}::from({})", self.cast_ty, snippet),
517520
Applicability::MaybeIncorrect,
518521
);
519-
}
522+
};
520523
}
521524
}
522525

tests/ui/issues/issue-16048.stderr

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,9 @@ error[E0605]: non-primitive cast: `Foo<'a>` as `T`
1111
--> $DIR/issue-16048.rs:24:16
1212
|
1313
LL | return *self as T;
14-
| ^^^^^^^^^^
14+
| ^^^^^^^^^^ help: consider using the `From` trait instead: `T::from(*self)`
1515
|
1616
= note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
17-
help: consider using the `From` trait instead
18-
|
19-
LL - return *self as T;
20-
LL + return T::from(*self);
21-
|
2217

2318
error: aborting due to 2 previous errors
2419

0 commit comments

Comments
 (0)