about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2021-07-15 09:48:14 -0300
committerSantiago Pastorino <spastorino@gmail.com>2021-07-18 09:30:11 -0300
commita002f4513b822aa0f5e694ac37701e41de275232 (patch)
treea7c54bae98386aaa818c0d2feafc06d7c040d1ac
parenta0e1291c2db0b76b6cfc31bc14466e5f620b9126 (diff)
downloadrust-a002f4513b822aa0f5e694ac37701e41de275232.tar.gz
rust-a002f4513b822aa0f5e694ac37701e41de275232.zip
Remove `sub_types_or_anon`
-rw-r--r--compiler/rustc_mir/src/borrow_check/type_check/mod.rs32
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-85113.rs23
-rw-r--r--src/test/ui/type-alias-impl-trait/issue-85113.stderr60
3 files changed, 2 insertions, 113 deletions
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 `&'<empty> 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 `&'<empty> 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 `&'<empty> 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 `&'<empty> 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`.