|
1 | 1 | use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; |
2 | 2 | use rustc_middle::ty::{self, Ty}; |
3 | | -use rustc_span::DUMMY_SP; |
4 | 3 | use rustc_span::{self, Span}; |
5 | 4 |
|
6 | 5 | use super::Expectation::*; |
@@ -44,7 +43,7 @@ impl<'a, 'tcx> Expectation<'tcx> { |
44 | 43 | // when checking the 'then' block which are incompatible with the |
45 | 44 | // 'else' branch. |
46 | 45 | pub(super) fn adjust_for_branches(&self, fcx: &FnCtxt<'a, 'tcx>) -> Expectation<'tcx> { |
47 | | - match self.strip_opaque(fcx) { |
| 46 | + match *self { |
48 | 47 | ExpectHasType(ety) => { |
49 | 48 | let ety = fcx.shallow_resolve(ety); |
50 | 49 | if !ety.is_ty_var() { ExpectHasType(ety) } else { NoExpectation } |
@@ -105,35 +104,14 @@ impl<'a, 'tcx> Expectation<'tcx> { |
105 | 104 | /// for the program to type-check). `only_has_type` will return |
106 | 105 | /// such a constraint, if it exists. |
107 | 106 | pub(super) fn only_has_type(self, fcx: &FnCtxt<'a, 'tcx>) -> Option<Ty<'tcx>> { |
108 | | - match self.strip_opaque(fcx) { |
109 | | - ExpectHasType(ty) => Some(ty), |
| 107 | + match self { |
| 108 | + ExpectHasType(ty) => Some(fcx.resolve_vars_if_possible(ty)), |
110 | 109 | NoExpectation | ExpectCastableToType(_) | ExpectRvalueLikeUnsized(_) | IsLast(_) => { |
111 | 110 | None |
112 | 111 | } |
113 | 112 | } |
114 | 113 | } |
115 | 114 |
|
116 | | - /// We must not treat opaque types as expected types in their defining scope, as that |
117 | | - /// will break `fn foo() -> impl Trait { if cond { a } else { b } }` if `a` and `b` are |
118 | | - /// only "equal" if they coerce to a common target, like two different function items |
119 | | - /// coercing to a function pointer if they have the same signature. |
120 | | - fn strip_opaque(self, fcx: &FnCtxt<'a, 'tcx>) -> Self { |
121 | | - match self { |
122 | | - ExpectHasType(ty) => { |
123 | | - let ty = fcx.resolve_vars_if_possible(ty); |
124 | | - match *ty.kind() { |
125 | | - ty::Opaque(def_id, _) |
126 | | - if fcx.infcx.opaque_type_origin(def_id, DUMMY_SP).is_some() => |
127 | | - { |
128 | | - NoExpectation |
129 | | - } |
130 | | - _ => self, |
131 | | - } |
132 | | - } |
133 | | - _ => self, |
134 | | - } |
135 | | - } |
136 | | - |
137 | 115 | /// Like `only_has_type`, but instead of returning `None` if no |
138 | 116 | /// hard constraint exists, creates a fresh type variable. |
139 | 117 | pub(super) fn coercion_target_type(self, fcx: &FnCtxt<'a, 'tcx>, span: Span) -> Ty<'tcx> { |
|
0 commit comments