From a002f4513b822aa0f5e694ac37701e41de275232 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 15 Jul 2021 09:48:14 -0300 Subject: [PATCH] Remove `sub_types_or_anon` --- .../src/borrow_check/type_check/mod.rs | 32 +--------- .../ui/type-alias-impl-trait/issue-85113.rs | 23 ------- .../type-alias-impl-trait/issue-85113.stderr | 60 ------------------- 3 files changed, 2 insertions(+), 113 deletions(-) delete mode 100644 src/test/ui/type-alias-impl-trait/issue-85113.rs delete mode 100644 src/test/ui/type-alias-impl-trait/issue-85113.stderr diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs index d6c3ba61731..cbcf050c9b8 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_mir/src/borrow_check/type_check/mod.rs @@ -1130,32 +1130,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.relate_types(sub, ty::Variance::Covariant, sup, locations, category) } - /// Try to relate `sub <: sup`; if this fails, instantiate opaque - /// variables in `sub` with their inferred definitions and try - /// again. This is used for opaque types in places (e.g., `let x: - /// impl Foo = ..`). - fn sub_types_or_anon( - &mut self, - sub: Ty<'tcx>, - sup: Ty<'tcx>, - locations: Locations, - category: ConstraintCategory, - ) -> Fallible<()> { - if let Err(terr) = self.sub_types(sub, sup, locations, category) { - if let ty::Opaque(..) = sup.kind() { - // When you have `let x: impl Foo = ...` in a closure, - // the resulting inferend values are stored with the - // def-id of the base function. - let parent_def_id = - self.tcx().closure_base_def_id(self.body.source.def_id()).expect_local(); - return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category); - } else { - return Err(terr); - } - } - Ok(()) - } - fn eq_types( &mut self, a: Ty<'tcx>, @@ -1490,7 +1464,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let rv_ty = rv.ty(body, tcx); let rv_ty = self.normalize(rv_ty, location); if let Err(terr) = - self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category) + self.sub_types(rv_ty, place_ty, location.to_locations(), category) { span_mirbug!( self, @@ -1777,9 +1751,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let locations = term_location.to_locations(); - if let Err(terr) = - self.sub_types_or_anon(sig.output(), dest_ty, locations, category) - { + if let Err(terr) = self.sub_types(sig.output(), dest_ty, locations, category) { span_mirbug!( self, term, diff --git a/src/test/ui/type-alias-impl-trait/issue-85113.rs b/src/test/ui/type-alias-impl-trait/issue-85113.rs deleted file mode 100644 index 0c37399df8d..00000000000 --- a/src/test/ui/type-alias-impl-trait/issue-85113.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![feature(min_type_alias_impl_trait)] -#![feature(impl_trait_in_bindings)] -#![allow(incomplete_features)] - -type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; -//~^ ERROR: hidden type for `impl Trait` captures lifetime that does not appear in bounds -//~| ERROR: the type `&' str` does not fulfill the required lifetime -//~| ERROR: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements - -trait Output<'a> {} - -impl<'a> Output<'a> for &'a str {} - -fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> { - //~^ ERROR: concrete type differs from previous defining opaque type use - let out: OpaqueOutputImpl<'a> = arg; - arg -} - -fn main() { - let s = String::from("wassup"); - cool_fn(&s); -} diff --git a/src/test/ui/type-alias-impl-trait/issue-85113.stderr b/src/test/ui/type-alias-impl-trait/issue-85113.stderr deleted file mode 100644 index 233c996340d..00000000000 --- a/src/test/ui/type-alias-impl-trait/issue-85113.stderr +++ /dev/null @@ -1,60 +0,0 @@ -error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds - --> $DIR/issue-85113.rs:5:29 - | -LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; - | ^^^^^^^^^^^^^^^^^^^^ - | -note: hidden type `&' str` captures lifetime smaller than the function body - --> $DIR/issue-85113.rs:5:29 - | -LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; - | ^^^^^^^^^^^^^^^^^^^^ - -error: concrete type differs from previous defining opaque type use - --> $DIR/issue-85113.rs:14:1 - | -LL | fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&' str`, got `&'a str` - | -note: previous use here - --> $DIR/issue-85113.rs:14:1 - | -LL | fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0477]: the type `&' str` does not fulfill the required lifetime - --> $DIR/issue-85113.rs:5:29 - | -LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; - | ^^^^^^^^^^^^^^^^^^^^ - | -note: type must outlive the lifetime `'a` as defined on the item at 5:23 - --> $DIR/issue-85113.rs:5:23 - | -LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; - | ^^ - -error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements - --> $DIR/issue-85113.rs:5:29 - | -LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; - | ^^^^^^^^^^^^^^^^^^^^ - | - = note: first, the lifetime cannot outlive the empty lifetime... -note: ...but the lifetime must also be valid for the lifetime `'a` as defined on the item at 5:23... - --> $DIR/issue-85113.rs:5:23 - | -LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; - | ^^ -note: ...so that the types are compatible - --> $DIR/issue-85113.rs:5:29 - | -LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; - | ^^^^^^^^^^^^^^^^^^^^ - = note: expected `Output<'a>` - found `Output<'_>` - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0477, E0495, E0700. -For more information about an error, try `rustc --explain E0477`.