]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #53588 - tristanburgess:52985_diagnostics_no_concrete_type_behind_exist...
authorbors <bors@rust-lang.org>
Thu, 23 Aug 2018 20:34:12 +0000 (20:34 +0000)
committerbors <bors@rust-lang.org>
Thu, 23 Aug 2018 20:34:12 +0000 (20:34 +0000)
52985 diagnostics no concrete type behind existential type

@oli-obk FYI. See below for new cycle error generated.

```rust
error[E0391]: cycle detected when processing `Foo`
 --> /dev/staging/existential_type_no_concrete_type_nouse_potential.rs:3:1
  |
3 | existential type Foo: Copy;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: ...which requires processing `bar`...
 --> /dev/staging/existential_type_no_concrete_type_nouse_potential.rs:6:23
  |
6 |   fn bar(x: Foo) -> Foo {
  |  _______________________^
7 | |     x
8 | | }
  | |_^
  = note: ...which again requires processing `Foo`, completing the cycle

error: aborting due to previous error

For more information about this error, try `rustc --explain E0391`.
```

1  2 
src/librustc/traits/query/normalize.rs

index f8b3933e2a153c554115d32c8c39380abb71460a,821d3229fdc66e3ed2e0510db02862a9f50e4420..8b4954cc501dd3aeac50a0cd7e22ca4f7eba32ac
@@@ -15,7 -15,7 +15,7 @@@
  use infer::at::At;
  use infer::{InferCtxt, InferOk};
  use mir::interpret::{ConstValue, GlobalId};
 -use rustc_data_structures::small_vec::SmallVec;
 +use smallvec::SmallVec;
  use traits::project::Normalized;
  use traits::{Obligation, ObligationCause, PredicateObligation, Reveal};
  use ty::fold::{TypeFoldable, TypeFolder};
@@@ -121,36 -121,14 +121,14 @@@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 
                          let concrete_ty = generic_ty.subst(self.tcx(), substs);
                          self.anon_depth += 1;
                          if concrete_ty == ty {
-                             // The type in question can only be inferred in terms of itself. This
-                             // is likely a user code issue, not a compiler issue. Thus, we will
-                             // induce a cycle error by calling the parent query again on the type.
-                             //
-                             // FIXME: Perhaps a better solution would be to have fold_ty()
-                             // itself be a query. Then, a type fold cycle would be detected
-                             // and reported more naturally as part of the query system, rather
-                             // than forcing it here.
-                             //
-                             // FIXME: Need a better span than just one pointing to the type def.
-                             // Should point to a defining use of the type that results in this
-                             // un-normalizable state.
-                             if let Some(param_env_lifted) =
-                                 self.tcx().lift_to_global(&self.param_env)
-                             {
-                                 if let Some(ty_lifted) = self.tcx().lift_to_global(&concrete_ty) {
-                                     let span = self.tcx().def_span(def_id);
-                                     self.tcx()
-                                         .global_tcx()
-                                         .at(span)
-                                         .normalize_ty_after_erasing_regions(
-                                             param_env_lifted.and(ty_lifted),
-                                         );
-                                     self.tcx().sess.abort_if_errors();
-                                 }
-                             }
-                             // If a cycle error can't be emitted, indicate a NoSolution error
-                             // and let the caller handle it.
-                             self.error = true;
-                             return concrete_ty;
+                             bug!(
+                                 "infinite recursion generic_ty: {:#?}, substs: {:#?}, \
+                                  concrete_ty: {:#?}, ty: {:#?}",
+                                 generic_ty,
+                                 substs,
+                                 concrete_ty,
+                                 ty
+                             );
                          }
                          let folded_ty = self.fold_ty(concrete_ty);
                          self.anon_depth -= 1;