]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/check/cast.rs
Auto merge of #85971 - FabianWolff:issue-85586, r=davidtwco
[rust.git] / compiler / rustc_typeck / src / check / cast.rs
index 304dba0384866214d0237f9b9e59e3e0f7163efd..181972e3e7bade679d581f9d78135f6b3e1b4bfb 100644 (file)
@@ -45,6 +45,7 @@
 use rustc_session::Session;
 use rustc_span::symbol::sym;
 use rustc_span::Span;
+use rustc_trait_selection::infer::InferCtxtExt;
 use rustc_trait_selection::traits;
 use rustc_trait_selection::traits::error_reporting::report_object_safety_error;
 
@@ -440,16 +441,10 @@ fn report_cast_error(&self, fcx: &FnCtxt<'a, 'tcx>, e: CastError) {
                             let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty);
                             let expr_ty = fcx.tcx.erase_regions(expr_ty);
                             let ty_params = fcx.tcx.mk_substs_trait(expr_ty, &[]);
-                            // Check for infer types because cases like `Option<{integer}>` would
-                            // panic otherwise.
-                            if !expr_ty.has_infer_types()
-                                && !ty.has_infer_types()
-                                && fcx.tcx.type_implements_trait((
-                                    from_trait,
-                                    ty,
-                                    ty_params,
-                                    fcx.param_env,
-                                ))
+                            if fcx
+                                .infcx
+                                .type_implements_trait(from_trait, ty, ty_params, fcx.param_env)
+                                .must_apply_modulo_regions()
                             {
                                 label = false;
                                 err.span_suggestion(