|
1 |
| -use crate::infer::error_reporting::{note_and_explain_free_region, note_and_explain_region}; |
| 1 | +use crate::infer::error_reporting::unexpected_hidden_region_diagnostic; |
2 | 2 | use crate::infer::{self, InferCtxt, InferOk, TypeVariableOrigin, TypeVariableOriginKind};
|
3 | 3 | use crate::traits::{self, PredicateObligation};
|
4 |
| -use rustc::middle::region; |
5 | 4 | use rustc::session::config::nightly_options;
|
6 | 5 | use rustc::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder, TypeVisitor};
|
7 | 6 | use rustc::ty::free_region_map::FreeRegionRelations;
|
8 | 7 | use rustc::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
|
9 | 8 | use rustc::ty::{self, GenericParamDefKind, Ty, TyCtxt};
|
10 | 9 | use rustc_data_structures::fx::FxHashMap;
|
11 | 10 | use rustc_data_structures::sync::Lrc;
|
12 |
| -use rustc_errors::{struct_span_err, DiagnosticBuilder}; |
13 | 11 | use rustc_hir as hir;
|
14 | 12 | use rustc_hir::def_id::{DefId, DefIdMap};
|
15 | 13 | use rustc_hir::Node;
|
@@ -618,86 +616,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
618 | 616 | }
|
619 | 617 | }
|
620 | 618 |
|
621 |
| -pub fn unexpected_hidden_region_diagnostic( |
622 |
| - tcx: TyCtxt<'tcx>, |
623 |
| - region_scope_tree: Option<®ion::ScopeTree>, |
624 |
| - span: Span, |
625 |
| - hidden_ty: Ty<'tcx>, |
626 |
| - hidden_region: ty::Region<'tcx>, |
627 |
| -) -> DiagnosticBuilder<'tcx> { |
628 |
| - let mut err = struct_span_err!( |
629 |
| - tcx.sess, |
630 |
| - span, |
631 |
| - E0700, |
632 |
| - "hidden type for `impl Trait` captures lifetime that does not appear in bounds", |
633 |
| - ); |
634 |
| - |
635 |
| - // Explain the region we are capturing. |
636 |
| - if let ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic | ty::ReEmpty(_) = hidden_region { |
637 |
| - // Assuming regionck succeeded (*), we ought to always be |
638 |
| - // capturing *some* region from the fn header, and hence it |
639 |
| - // ought to be free. So under normal circumstances, we will go |
640 |
| - // down this path which gives a decent human readable |
641 |
| - // explanation. |
642 |
| - // |
643 |
| - // (*) if not, the `tainted_by_errors` flag would be set to |
644 |
| - // true in any case, so we wouldn't be here at all. |
645 |
| - note_and_explain_free_region( |
646 |
| - tcx, |
647 |
| - &mut err, |
648 |
| - &format!("hidden type `{}` captures ", hidden_ty), |
649 |
| - hidden_region, |
650 |
| - "", |
651 |
| - ); |
652 |
| - } else { |
653 |
| - // Ugh. This is a painful case: the hidden region is not one |
654 |
| - // that we can easily summarize or explain. This can happen |
655 |
| - // in a case like |
656 |
| - // `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`: |
657 |
| - // |
658 |
| - // ``` |
659 |
| - // fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> { |
660 |
| - // if condition() { a } else { b } |
661 |
| - // } |
662 |
| - // ``` |
663 |
| - // |
664 |
| - // Here the captured lifetime is the intersection of `'a` and |
665 |
| - // `'b`, which we can't quite express. |
666 |
| - |
667 |
| - if let Some(region_scope_tree) = region_scope_tree { |
668 |
| - // If the `region_scope_tree` is available, this is being |
669 |
| - // invoked from the "region inferencer error". We can at |
670 |
| - // least report a really cryptic error for now. |
671 |
| - note_and_explain_region( |
672 |
| - tcx, |
673 |
| - region_scope_tree, |
674 |
| - &mut err, |
675 |
| - &format!("hidden type `{}` captures ", hidden_ty), |
676 |
| - hidden_region, |
677 |
| - "", |
678 |
| - ); |
679 |
| - } else { |
680 |
| - // If the `region_scope_tree` is *unavailable*, this is |
681 |
| - // being invoked by the code that comes *after* region |
682 |
| - // inferencing. This is a bug, as the region inferencer |
683 |
| - // ought to have noticed the failed constraint and invoked |
684 |
| - // error reporting, which in turn should have prevented us |
685 |
| - // from getting trying to infer the hidden type |
686 |
| - // completely. |
687 |
| - tcx.sess.delay_span_bug( |
688 |
| - span, |
689 |
| - &format!( |
690 |
| - "hidden type captures unexpected lifetime `{:?}` \ |
691 |
| - but no region inference failure", |
692 |
| - hidden_region, |
693 |
| - ), |
694 |
| - ); |
695 |
| - } |
696 |
| - } |
697 |
| - |
698 |
| - err |
699 |
| -} |
700 |
| - |
701 | 619 | // Visitor that requires that (almost) all regions in the type visited outlive
|
702 | 620 | // `least_region`. We cannot use `push_outlives_components` because regions in
|
703 | 621 | // closure signatures are not included in their outlives components. We need to
|
|
0 commit comments