X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_typeck%2Fsrc%2Fcheck%2Ffallback.rs;h=15788f410f1951bf92733bd0ad8bfdc8df2fdb49;hb=7907385999b4a83d37ed31d334f3ed9ca02983a1;hp=7214cdf3312a78998c9374b15ae800f7cc6ca265;hpb=1ca8d0bf8c154b0f602fadac8c38f14df5dea77a;p=rust.git diff --git a/compiler/rustc_typeck/src/check/fallback.rs b/compiler/rustc_typeck/src/check/fallback.rs index 7214cdf3312..15788f410f1 100644 --- a/compiler/rustc_typeck/src/check/fallback.rs +++ b/compiler/rustc_typeck/src/check/fallback.rs @@ -24,7 +24,7 @@ pub(super) fn type_inference_fallback(&self) -> bool { self.fulfillment_cx.borrow_mut().pending_obligations() ); - // Check if we have any unsolved varibales. If not, no need for fallback. + // Check if we have any unsolved variables. If not, no need for fallback. let unsolved_variables = self.unsolved_variables(); if unsolved_variables.is_empty() { return false; @@ -66,16 +66,6 @@ pub(super) fn type_inference_fallback(&self) -> bool { // refer to opaque types. self.select_obligations_where_possible(fallback_has_occurred, |_| {}); - // We now run fallback again, but this time we allow it to replace - // unconstrained opaque type variables, in addition to performing - // other kinds of fallback. - for ty in &self.unsolved_variables() { - fallback_has_occurred |= self.fallback_opaque_type_vars(*ty); - } - - // See if we can make any more progress. - self.select_obligations_where_possible(fallback_has_occurred, |_| {}); - fallback_has_occurred } @@ -136,59 +126,6 @@ fn fallback_if_possible( true } - /// Second round of fallback: Unconstrained type variables created - /// from the instantiation of an opaque type fall back to the - /// opaque type itself. This is a somewhat incomplete attempt to - /// manage "identity passthrough" for `impl Trait` types. - /// - /// For example, in this code: - /// - ///``` - /// type MyType = impl Copy; - /// fn defining_use() -> MyType { true } - /// fn other_use() -> MyType { defining_use() } - /// ``` - /// - /// `defining_use` will constrain the instantiated inference - /// variable to `bool`, while `other_use` will constrain - /// the instantiated inference variable to `MyType`. - /// - /// When we process opaque types during writeback, we - /// will handle cases like `other_use`, and not count - /// them as defining usages - /// - /// However, we also need to handle cases like this: - /// - /// ```rust - /// pub type Foo = impl Copy; - /// fn produce() -> Option { - /// None - /// } - /// ``` - /// - /// In the above snippet, the inference variable created by - /// instantiating `Option` will be completely unconstrained. - /// We treat this as a non-defining use by making the inference - /// variable fall back to the opaque type itself. - fn fallback_opaque_type_vars(&self, ty: Ty<'tcx>) -> bool { - let span = self - .infcx - .type_var_origin(ty) - .map(|origin| origin.span) - .unwrap_or(rustc_span::DUMMY_SP); - let oty = self.inner.borrow().opaque_types_vars.get(&ty).copied(); - if let Some(opaque_ty) = oty { - debug!( - "fallback_opaque_type_vars(ty={:?}): falling back to opaque type {:?}", - ty, opaque_ty - ); - self.demand_eqtype(span, ty, opaque_ty); - true - } else { - return false; - } - } - /// The "diverging fallback" system is rather complicated. This is /// a result of our need to balance 'do the right thing' with /// backwards compatibility. @@ -207,6 +144,7 @@ fn fallback_opaque_type_vars(&self, ty: Ty<'tcx>) -> bool { /// code. The most common case is something like this: /// /// ```rust + /// # fn foo() -> i32 { 4 } /// match foo() { /// 22 => Default::default(), // call this type `?D` /// _ => return, // return has type `!` @@ -231,7 +169,7 @@ fn fallback_opaque_type_vars(&self, ty: Ty<'tcx>) -> bool { /// fallback to use based on whether there is a coercion pattern /// like this: /// - /// ``` + /// ```ignore (not-rust) /// ?Diverging -> ?V /// ?NonDiverging -> ?V /// ?V != ?NonDiverging