]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/check/expectation.rs
Rollup merge of #101014 - isikkema:fix-zmeta-stats-file-encoder-no-read-perms, r...
[rust.git] / compiler / rustc_typeck / src / check / expectation.rs
index 9e1a70b7dfb929382497d1cdcbb5c15da3195694..e9e810344776b963d52a0eeb85fbd6ecbcc8c376 100644 (file)
@@ -1,6 +1,5 @@
 use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
 use rustc_middle::ty::{self, Ty};
-use rustc_span::DUMMY_SP;
 use rustc_span::{self, Span};
 
 use super::Expectation::*;
@@ -44,7 +43,7 @@ impl<'a, 'tcx> Expectation<'tcx> {
     // when checking the 'then' block which are incompatible with the
     // 'else' branch.
     pub(super) fn adjust_for_branches(&self, fcx: &FnCtxt<'a, 'tcx>) -> Expectation<'tcx> {
-        match self.strip_opaque(fcx) {
+        match *self {
             ExpectHasType(ety) => {
                 let ety = fcx.shallow_resolve(ety);
                 if !ety.is_ty_var() { ExpectHasType(ety) } else { NoExpectation }
@@ -105,35 +104,14 @@ pub(super) fn to_option(self, fcx: &FnCtxt<'a, 'tcx>) -> Option<Ty<'tcx>> {
     /// for the program to type-check). `only_has_type` will return
     /// such a constraint, if it exists.
     pub(super) fn only_has_type(self, fcx: &FnCtxt<'a, 'tcx>) -> Option<Ty<'tcx>> {
-        match self.strip_opaque(fcx) {
-            ExpectHasType(ty) => Some(ty),
+        match self {
+            ExpectHasType(ty) => Some(fcx.resolve_vars_if_possible(ty)),
             NoExpectation | ExpectCastableToType(_) | ExpectRvalueLikeUnsized(_) | IsLast(_) => {
                 None
             }
         }
     }
 
-    /// We must not treat opaque types as expected types in their defining scope, as that
-    /// will break `fn foo() -> impl Trait { if cond { a } else { b } }` if `a` and `b` are
-    /// only "equal" if they coerce to a common target, like two different function items
-    /// coercing to a function pointer if they have the same signature.
-    fn strip_opaque(self, fcx: &FnCtxt<'a, 'tcx>) -> Self {
-        match self {
-            ExpectHasType(ty) => {
-                let ty = fcx.resolve_vars_if_possible(ty);
-                match *ty.kind() {
-                    ty::Opaque(def_id, _)
-                        if fcx.infcx.opaque_type_origin(def_id, DUMMY_SP).is_some() =>
-                    {
-                        NoExpectation
-                    }
-                    _ => self,
-                }
-            }
-            _ => self,
-        }
-    }
-
     /// Like `only_has_type`, but instead of returning `None` if no
     /// hard constraint exists, creates a fresh type variable.
     pub(super) fn coercion_target_type(self, fcx: &FnCtxt<'a, 'tcx>, span: Span) -> Ty<'tcx> {