]> git.lizzy.rs Git - rust.git/commitdiff
Remove dead ScopeTree code
authorMatthew Jasper <mjjasper1@gmail.com>
Tue, 19 May 2020 20:26:18 +0000 (21:26 +0100)
committerMatthew Jasper <mjjasper1@gmail.com>
Fri, 22 May 2020 17:03:08 +0000 (18:03 +0100)
12 files changed:
src/librustc_infer/infer/error_reporting/mod.rs
src/librustc_infer/infer/error_reporting/note.rs
src/librustc_infer/infer/free_regions.rs
src/librustc_infer/infer/mod.rs
src/librustc_middle/middle/region.rs
src/librustc_mir/borrow_check/diagnostics/region_errors.rs
src/librustc_trait_selection/opaque_types.rs
src/librustc_trait_selection/traits/mod.rs
src/librustc_typeck/check/closure.rs
src/librustc_typeck/check/dropck.rs
src/librustc_typeck/coherence/builtin.rs
src/librustc_typeck/impl_wf_check/min_specialization.rs

index 66781e88c118af694533874987ee9337bb53ee04..cc479aa17ce95e94735d73cbac12d0dabc453766 100644 (file)
@@ -61,7 +61,6 @@
 use rustc_hir as hir;
 use rustc_hir::def_id::DefId;
 use rustc_hir::Node;
-use rustc_middle::middle::region;
 use rustc_middle::ty::error::TypeError;
 use rustc_middle::ty::{
     self,
@@ -81,7 +80,6 @@
 
 pub(super) fn note_and_explain_region(
     tcx: TyCtxt<'tcx>,
-    region_scope_tree: &region::ScopeTree,
     err: &mut DiagnosticBuilder<'_>,
     prefix: &str,
     region: ty::Region<'tcx>,
@@ -239,7 +237,6 @@ fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option
 
 pub fn unexpected_hidden_region_diagnostic(
     tcx: TyCtxt<'tcx>,
-    region_scope_tree: Option<&region::ScopeTree>,
     span: Span,
     hidden_ty: Ty<'tcx>,
     hidden_region: ty::Region<'tcx>,
@@ -264,78 +261,53 @@ pub fn unexpected_hidden_region_diagnostic(
             err.span_note(span, &message);
         }
         ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic | ty::ReEmpty(_) => {
-        // Assuming regionck succeeded (*), we ought to always be
-        // capturing *some* region from the fn header, and hence it
-        // ought to be free. So under normal circumstances, we will go
-        // down this path which gives a decent human readable
-        // explanation.
-        //
-        // (*) if not, the `tainted_by_errors` field would be set to
-        // `Some(ErrorReported)` in any case, so we wouldn't be here at all.
-        note_and_explain_free_region(
-            tcx,
-            &mut err,
-            &format!("hidden type `{}` captures ", hidden_ty),
-            hidden_region,
-            "",
-        );
+            // Assuming regionck succeeded (*), we ought to always be
+            // capturing *some* region from the fn header, and hence it
+            // ought to be free. So under normal circumstances, we will go
+            // down this path which gives a decent human readable
+            // explanation.
+            //
+            // (*) if not, the `tainted_by_errors` field would be set to
+            // `Some(ErrorReported)` in any case, so we wouldn't be here at all.
+            note_and_explain_free_region(
+                tcx,
+                &mut err,
+                &format!("hidden type `{}` captures ", hidden_ty),
+                hidden_region,
+                "",
+            );
         }
         _ => {
-        // Ugh. This is a painful case: the hidden region is not one
-        // that we can easily summarize or explain. This can happen
-        // in a case like
-        // `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
-        //
-        // ```
-        // fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
-        //   if condition() { a } else { b }
-        // }
-        // ```
-        //
-        // Here the captured lifetime is the intersection of `'a` and
-        // `'b`, which we can't quite express.
-
-        if let Some(region_scope_tree) = region_scope_tree {
-            // If the `region_scope_tree` is available, this is being
-            // invoked from the "region inferencer error". We can at
-            // least report a really cryptic error for now.
+            // Ugh. This is a painful case: the hidden region is not one
+            // that we can easily summarize or explain. This can happen
+            // in a case like
+            // `src/test/ui/multiple-lifetimes/ordinary-bounds-unsuited.rs`:
+            //
+            // ```
+            // fn upper_bounds<'a, 'b>(a: Ordinary<'a>, b: Ordinary<'b>) -> impl Trait<'a, 'b> {
+            //   if condition() { a } else { b }
+            // }
+            // ```
+            //
+            // Here the captured lifetime is the intersection of `'a` and
+            // `'b`, which we can't quite express.
+
+            // We can at least report a really cryptic error for now.
             note_and_explain_region(
                 tcx,
-                region_scope_tree,
                 &mut err,
                 &format!("hidden type `{}` captures ", hidden_ty),
                 hidden_region,
                 "",
             );
-        } else {
-            // If the `region_scope_tree` is *unavailable*, this is
-            // being invoked by the code that comes *after* region
-            // inferencing. This is a bug, as the region inferencer
-            // ought to have noticed the failed constraint and invoked
-            // error reporting, which in turn should have prevented us
-            // from getting trying to infer the hidden type
-            // completely.
-            tcx.sess.delay_span_bug(
-                span,
-                &format!(
-                    "hidden type captures unexpected lifetime `{:?}` \
-                     but no region inference failure",
-                    hidden_region,
-                ),
-            );
         }
     }
-    }
 
     err
 }
 
 impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
-    pub fn report_region_errors(
-        &self,
-        region_scope_tree: &region::ScopeTree,
-        errors: &Vec<RegionResolutionError<'tcx>>,
-    ) {
+    pub fn report_region_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>) {
         debug!("report_region_errors(): {} errors to start", errors.len());
 
         // try to pre-process the errors, which will group some of them
@@ -358,17 +330,14 @@ pub fn report_region_errors(
                     // general bit of code that displays the error information
                     RegionResolutionError::ConcreteFailure(origin, sub, sup) => {
                         if sub.is_placeholder() || sup.is_placeholder() {
-                            self.report_placeholder_failure(region_scope_tree, origin, sub, sup)
-                                .emit();
+                            self.report_placeholder_failure(origin, sub, sup).emit();
                         } else {
-                            self.report_concrete_failure(region_scope_tree, origin, sub, sup)
-                                .emit();
+                            self.report_concrete_failure(origin, sub, sup).emit();
                         }
                     }
 
                     RegionResolutionError::GenericBoundFailure(origin, param_ty, sub) => {
                         self.report_generic_bound_failure(
-                            region_scope_tree,
                             origin.span(),
                             Some(origin),
                             param_ty,
@@ -385,29 +354,12 @@ pub fn report_region_errors(
                         sup_r,
                     ) => {
                         if sub_r.is_placeholder() {
-                            self.report_placeholder_failure(
-                                region_scope_tree,
-                                sub_origin,
-                                sub_r,
-                                sup_r,
-                            )
-                            .emit();
+                            self.report_placeholder_failure(sub_origin, sub_r, sup_r).emit();
                         } else if sup_r.is_placeholder() {
-                            self.report_placeholder_failure(
-                                region_scope_tree,
-                                sup_origin,
-                                sub_r,
-                                sup_r,
-                            )
-                            .emit();
+                            self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
                         } else {
                             self.report_sub_sup_conflict(
-                                region_scope_tree,
-                                var_origin,
-                                sub_origin,
-                                sub_r,
-                                sup_origin,
-                                sup_r,
+                                var_origin, sub_origin, sub_r, sup_origin, sup_r,
                             );
                         }
                     }
@@ -428,13 +380,7 @@ pub fn report_region_errors(
                         // value.
                         let sub_r = self.tcx.mk_region(ty::ReEmpty(var_universe));
 
-                        self.report_placeholder_failure(
-                            region_scope_tree,
-                            sup_origin,
-                            sub_r,
-                            sup_r,
-                        )
-                        .emit();
+                        self.report_placeholder_failure(sup_origin, sub_r, sup_r).emit();
                     }
 
                     RegionResolutionError::MemberConstraintFailure {
@@ -445,7 +391,6 @@ pub fn report_region_errors(
                         let hidden_ty = self.resolve_vars_if_possible(&hidden_ty);
                         unexpected_hidden_region_diagnostic(
                             self.tcx,
-                            Some(region_scope_tree),
                             span,
                             hidden_ty,
                             member_region,
@@ -1722,19 +1667,16 @@ fn expected_found_str<T: fmt::Display + TypeFoldable<'tcx>>(
 
     pub fn report_generic_bound_failure(
         &self,
-        region_scope_tree: &region::ScopeTree,
         span: Span,
         origin: Option<SubregionOrigin<'tcx>>,
         bound_kind: GenericKind<'tcx>,
         sub: Region<'tcx>,
     ) {
-        self.construct_generic_bound_failure(region_scope_tree, span, origin, bound_kind, sub)
-            .emit();
+        self.construct_generic_bound_failure(span, origin, bound_kind, sub).emit();
     }
 
     pub fn construct_generic_bound_failure(
         &self,
-        region_scope_tree: &region::ScopeTree,
         span: Span,
         origin: Option<SubregionOrigin<'tcx>>,
         bound_kind: GenericKind<'tcx>,
@@ -1886,7 +1828,6 @@ fn binding_suggestion<'tcx, S: fmt::Display>(
                 ));
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
                     &mut err,
                     &format!("{} must be valid for ", labeled_user_string),
                     sub,
@@ -1904,7 +1845,6 @@ fn binding_suggestion<'tcx, S: fmt::Display>(
 
     fn report_sub_sup_conflict(
         &self,
-        region_scope_tree: &region::ScopeTree,
         var_origin: RegionVariableOrigin,
         sub_origin: SubregionOrigin<'tcx>,
         sub_region: Region<'tcx>,
@@ -1915,7 +1855,6 @@ fn report_sub_sup_conflict(
 
         note_and_explain_region(
             self.tcx,
-            region_scope_tree,
             &mut err,
             "first, the lifetime cannot outlive ",
             sup_region,
@@ -1941,7 +1880,6 @@ fn report_sub_sup_conflict(
                 if sub_expected == sup_expected && sub_found == sup_found {
                     note_and_explain_region(
                         self.tcx,
-                        region_scope_tree,
                         &mut err,
                         "...but the lifetime must also be valid for ",
                         sub_region,
@@ -1963,7 +1901,6 @@ fn report_sub_sup_conflict(
 
         note_and_explain_region(
             self.tcx,
-            region_scope_tree,
             &mut err,
             "but, the lifetime must be valid for ",
             sub_region,
index a4e51fe0b1c00b9cc38ca5f0953a3c37494a9402..8fbb89da5af416d5da50dd35ac2186393031794f 100644 (file)
@@ -1,7 +1,6 @@
 use crate::infer::error_reporting::{note_and_explain_region, ObligationCauseExt};
 use crate::infer::{self, InferCtxt, SubregionOrigin};
 use rustc_errors::{struct_span_err, DiagnosticBuilder};
-use rustc_middle::middle::region;
 use rustc_middle::ty::error::TypeError;
 use rustc_middle::ty::{self, Region};
 
@@ -91,7 +90,6 @@ pub(super) fn note_region_origin(
 
     pub(super) fn report_concrete_failure(
         &self,
-        region_scope_tree: &region::ScopeTree,
         origin: SubregionOrigin<'tcx>,
         sub: Region<'tcx>,
         sup: Region<'tcx>,
@@ -100,10 +98,9 @@ pub(super) fn report_concrete_failure(
             infer::Subtype(box trace) => {
                 let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
                 let mut err = self.report_and_explain_type_error(trace, &terr);
-                note_and_explain_region(self.tcx, region_scope_tree, &mut err, "", sup, "...");
+                note_and_explain_region(self.tcx, &mut err, "", sup, "...");
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
                     &mut err,
                     "...does not necessarily outlive ",
                     sub,
@@ -121,7 +118,6 @@ pub(super) fn report_concrete_failure(
                 );
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
                     &mut err,
                     "...the reference is valid for ",
                     sub,
@@ -129,7 +125,6 @@ pub(super) fn report_concrete_failure(
                 );
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
                     &mut err,
                     "...but the borrowed content is only valid for ",
                     sup,
@@ -149,7 +144,6 @@ pub(super) fn report_concrete_failure(
                 );
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
                     &mut err,
                     "...the borrowed pointer is valid for ",
                     sub,
@@ -157,7 +151,6 @@ pub(super) fn report_concrete_failure(
                 );
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
                     &mut err,
                     &format!("...but `{}` is only valid for ", var_name),
                     sup,
@@ -173,17 +166,9 @@ pub(super) fn report_concrete_failure(
                     "lifetime of the source pointer does not outlive \
                                                 lifetime bound of the object type"
                 );
+                note_and_explain_region(self.tcx, &mut err, "object type is valid for ", sub, "");
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
-                    &mut err,
-                    "object type is valid for ",
-                    sub,
-                    "",
-                );
-                note_and_explain_region(
-                    self.tcx,
-                    region_scope_tree,
                     &mut err,
                     "source pointer is only valid for ",
                     sup,
@@ -201,22 +186,10 @@ pub(super) fn report_concrete_failure(
                     self.ty_to_string(ty)
                 );
                 match *sub {
-                    ty::ReStatic => note_and_explain_region(
-                        self.tcx,
-                        region_scope_tree,
-                        &mut err,
-                        "type must satisfy ",
-                        sub,
-                        "",
-                    ),
-                    _ => note_and_explain_region(
-                        self.tcx,
-                        region_scope_tree,
-                        &mut err,
-                        "type must outlive ",
-                        sub,
-                        "",
-                    ),
+                    ty::ReStatic => {
+                        note_and_explain_region(self.tcx, &mut err, "type must satisfy ", sub, "")
+                    }
+                    _ => note_and_explain_region(self.tcx, &mut err, "type must outlive ", sub, ""),
                 }
                 err
             }
@@ -225,7 +198,6 @@ pub(super) fn report_concrete_failure(
                     struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
                     &mut err,
                     "lifetime parameter instantiated with ",
                     sup,
@@ -233,7 +205,6 @@ pub(super) fn report_concrete_failure(
                 );
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
                     &mut err,
                     "but lifetime parameter must outlive ",
                     sub,
@@ -251,7 +222,6 @@ pub(super) fn report_concrete_failure(
                 );
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
                     &mut err,
                     "the return value is only valid for ",
                     sup,
@@ -267,22 +237,8 @@ pub(super) fn report_concrete_failure(
                     "a value of type `{}` is borrowed for too long",
                     self.ty_to_string(ty)
                 );
-                note_and_explain_region(
-                    self.tcx,
-                    region_scope_tree,
-                    &mut err,
-                    "the type is valid for ",
-                    sub,
-                    "",
-                );
-                note_and_explain_region(
-                    self.tcx,
-                    region_scope_tree,
-                    &mut err,
-                    "but the borrow lasts for ",
-                    sup,
-                    "",
-                );
+                note_and_explain_region(self.tcx, &mut err, "the type is valid for ", sub, "");
+                note_and_explain_region(self.tcx, &mut err, "but the borrow lasts for ", sup, "");
                 err
             }
             infer::ReferenceOutlivesReferent(ty, span) => {
@@ -293,17 +249,9 @@ pub(super) fn report_concrete_failure(
                     "in type `{}`, reference has a longer lifetime than the data it references",
                     self.ty_to_string(ty)
                 );
+                note_and_explain_region(self.tcx, &mut err, "the pointer is valid for ", sub, "");
                 note_and_explain_region(
                     self.tcx,
-                    region_scope_tree,
-                    &mut err,
-                    "the pointer is valid for ",
-                    sub,
-                    "",
-                );
-                note_and_explain_region(
-                    self.tcx,
-                    region_scope_tree,
                     &mut err,
                     "but the referenced data is only valid for ",
                     sup,
@@ -328,7 +276,6 @@ pub(super) fn report_concrete_failure(
 
     pub(super) fn report_placeholder_failure(
         &self,
-        region_scope_tree: &region::ScopeTree,
         placeholder_origin: SubregionOrigin<'tcx>,
         sub: Region<'tcx>,
         sup: Region<'tcx>,
@@ -340,7 +287,7 @@ pub(super) fn report_placeholder_failure(
                 self.report_and_explain_type_error(trace, &terr)
             }
 
-            _ => self.report_concrete_failure(region_scope_tree, placeholder_origin, sub, sup),
+            _ => self.report_concrete_failure(placeholder_origin, sub, sup),
         }
     }
 }
index e31c524c19710886a5925441713e928cffb60b46..d975038b010b9dabdd320349117a621a5fc8ad49 100644 (file)
@@ -5,7 +5,6 @@
 
 use rustc_data_structures::transitive_relation::TransitiveRelation;
 use rustc_hir::def_id::DefId;
-use rustc_middle::middle::region;
 use rustc_middle::ty::{self, Lift, Region, TyCtxt};
 
 /// Combines a `region::ScopeTree` (which governs relationships between
@@ -21,21 +20,13 @@ pub struct RegionRelations<'a, 'tcx> {
     /// The context used to fetch the region maps.
     pub context: DefId,
 
-    /// The region maps for the given context.
-    pub region_scope_tree: &'a region::ScopeTree,
-
     /// Free-region relationships.
     pub free_regions: &'a FreeRegionMap<'tcx>,
 }
 
 impl<'a, 'tcx> RegionRelations<'a, 'tcx> {
-    pub fn new(
-        tcx: TyCtxt<'tcx>,
-        context: DefId,
-        region_scope_tree: &'a region::ScopeTree,
-        free_regions: &'a FreeRegionMap<'tcx>,
-    ) -> Self {
-        Self { tcx, context, region_scope_tree, free_regions }
+    pub fn new(tcx: TyCtxt<'tcx>, context: DefId, free_regions: &'a FreeRegionMap<'tcx>) -> Self {
+        Self { tcx, context, free_regions }
     }
 
     pub fn lub_free_regions(&self, r_a: Region<'tcx>, r_b: Region<'tcx>) -> Region<'tcx> {
index fdd0c5b2ff368825cee5f9eaedc8c26844e31db5..30af7d06744d78f3a20181ed72e29f643c3e613e 100644 (file)
@@ -20,7 +20,6 @@
 use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
 use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
 use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
-use rustc_middle::middle::region;
 use rustc_middle::mir;
 use rustc_middle::mir::interpret::ConstEvalResult;
 use rustc_middle::traits::select;
@@ -1213,7 +1212,6 @@ pub fn set_tainted_by_errors(&self) {
     pub fn resolve_regions_and_report_errors(
         &self,
         region_context: DefId,
-        region_map: &region::ScopeTree,
         outlives_env: &OutlivesEnvironment<'tcx>,
         mode: RegionckMode,
     ) {
@@ -1233,12 +1231,8 @@ pub fn resolve_regions_and_report_errors(
                 .into_infos_and_data()
         };
 
-        let region_rels = &RegionRelations::new(
-            self.tcx,
-            region_context,
-            region_map,
-            outlives_env.free_region_map(),
-        );
+        let region_rels =
+            &RegionRelations::new(self.tcx, region_context, outlives_env.free_region_map());
 
         let (lexical_region_resolutions, errors) =
             lexical_region_resolve::resolve(region_rels, var_infos, data, mode);
@@ -1252,7 +1246,7 @@ pub fn resolve_regions_and_report_errors(
             // this infcx was in use.  This is totally hokey but
             // otherwise we have a hard time separating legit region
             // errors from silly ones.
-            self.report_region_errors(region_map, &errors);
+            self.report_region_errors(&errors);
         }
     }
 
index f02d8fe8ad6018278a050cbefcb487c5b4ed942a..943a065a8b5e8ef0fed990a8e4bd799bb8fd2eee 100644 (file)
@@ -7,7 +7,7 @@
 //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/borrow_check.html
 
 use crate::ich::{NodeIdHashingMode, StableHashingContext};
-use crate::ty::{self, DefIdTree, TyCtxt};
+use crate::ty::TyCtxt;
 use rustc_hir as hir;
 use rustc_hir::Node;
 
@@ -333,7 +333,7 @@ pub struct YieldData {
     pub source: hir::YieldSource,
 }
 
-impl<'tcx> ScopeTree {
+impl ScopeTree {
     pub fn record_scope_parent(&mut self, child: Scope, parent: Option<(Scope, ScopeDepth)>) {
         debug!("{:?}.parent = {:?}", child, parent);
 
@@ -348,24 +348,6 @@ pub fn record_scope_parent(&mut self, child: Scope, parent: Option<(Scope, Scope
         }
     }
 
-    pub fn each_encl_scope<E>(&self, mut e: E)
-    where
-        E: FnMut(Scope, Scope),
-    {
-        for (&child, &parent) in &self.parent_map {
-            e(child, parent.0)
-        }
-    }
-
-    pub fn each_var_scope<E>(&self, mut e: E)
-    where
-        E: FnMut(&hir::ItemLocalId, Scope),
-    {
-        for (child, &parent) in self.var_map.iter() {
-            e(child, parent)
-        }
-    }
-
     pub fn opt_destruction_scope(&self, n: hir::ItemLocalId) -> Option<Scope> {
         self.destruction_scopes.get(&n).cloned()
     }
@@ -406,12 +388,6 @@ pub fn opt_encl_scope(&self, id: Scope) -> Option<Scope> {
         self.parent_map.get(&id).cloned().map(|(p, _)| p)
     }
 
-    /// Returns the narrowest scope that encloses `id`, if any.
-    #[allow(dead_code)] // used in cfg
-    pub fn encl_scope(&self, id: Scope) -> Scope {
-        self.opt_encl_scope(id).unwrap()
-    }
-
     /// Returns the lifetime of the local variable `var_id`
     pub fn var_scope(&self, var_id: hir::ItemLocalId) -> Scope {
         self.var_map
@@ -448,17 +424,6 @@ pub fn temporary_scope(&self, expr_id: hir::ItemLocalId) -> Option<Scope> {
         None
     }
 
-    /// Returns the lifetime of the variable `id`.
-    pub fn var_region(&self, id: hir::ItemLocalId) -> ty::RegionKind {
-        let scope = ty::ReScope(self.var_scope(id));
-        debug!("var_region({:?}) = {:?}", id, scope);
-        scope
-    }
-
-    pub fn scopes_intersect(&self, scope1: Scope, scope2: Scope) -> bool {
-        self.is_subscope_of(scope1, scope2) || self.is_subscope_of(scope2, scope1)
-    }
-
     /// Returns `true` if `subscope` is equal to or is lexically nested inside `superscope`, and
     /// `false` otherwise.
     pub fn is_subscope_of(&self, subscope: Scope, superscope: Scope) -> bool {
@@ -479,127 +444,6 @@ pub fn is_subscope_of(&self, subscope: Scope, superscope: Scope) -> bool {
         true
     }
 
-    /// Returns the ID of the innermost containing body.
-    pub fn containing_body(&self, mut scope: Scope) -> Option<hir::ItemLocalId> {
-        loop {
-            if let ScopeData::CallSite = scope.data {
-                return Some(scope.item_local_id());
-            }
-
-            scope = self.opt_encl_scope(scope)?;
-        }
-    }
-
-    /// Finds the nearest common ancestor of two scopes. That is, finds the
-    /// smallest scope which is greater than or equal to both `scope_a` and
-    /// `scope_b`.
-    pub fn nearest_common_ancestor(&self, scope_a: Scope, scope_b: Scope) -> Scope {
-        if scope_a == scope_b {
-            return scope_a;
-        }
-
-        let mut a = scope_a;
-        let mut b = scope_b;
-
-        // Get the depth of each scope's parent. If either scope has no parent,
-        // it must be the root, which means we can stop immediately because the
-        // root must be the nearest common ancestor. (In practice, this is
-        // moderately common.)
-        let (parent_a, parent_a_depth) = match self.parent_map.get(&a) {
-            Some(pd) => *pd,
-            None => return a,
-        };
-        let (parent_b, parent_b_depth) = match self.parent_map.get(&b) {
-            Some(pd) => *pd,
-            None => return b,
-        };
-
-        if parent_a_depth > parent_b_depth {
-            // `a` is lower than `b`. Move `a` up until it's at the same depth
-            // as `b`. The first move up is trivial because we already found
-            // `parent_a` above; the loop does the remaining N-1 moves.
-            a = parent_a;
-            for _ in 0..(parent_a_depth - parent_b_depth - 1) {
-                a = self.parent_map.get(&a).unwrap().0;
-            }
-        } else if parent_b_depth > parent_a_depth {
-            // `b` is lower than `a`.
-            b = parent_b;
-            for _ in 0..(parent_b_depth - parent_a_depth - 1) {
-                b = self.parent_map.get(&b).unwrap().0;
-            }
-        } else {
-            // Both scopes are at the same depth, and we know they're not equal
-            // because that case was tested for at the top of this function. So
-            // we can trivially move them both up one level now.
-            assert!(parent_a_depth != 0);
-            a = parent_a;
-            b = parent_b;
-        }
-
-        // Now both scopes are at the same level. We move upwards in lockstep
-        // until they match. In practice, this loop is almost always executed
-        // zero times because `a` is almost always a direct ancestor of `b` or
-        // vice versa.
-        while a != b {
-            a = self.parent_map.get(&a).unwrap().0;
-            b = self.parent_map.get(&b).unwrap().0;
-        }
-
-        a
-    }
-
-    /// Assuming that the provided region was defined within this `ScopeTree`,
-    /// returns the outermost `Scope` that the region outlives.
-    pub fn early_free_scope(&self, tcx: TyCtxt<'tcx>, br: &ty::EarlyBoundRegion) -> Scope {
-        let param_owner = tcx.parent(br.def_id).unwrap();
-
-        let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local());
-        let scope = tcx
-            .hir()
-            .maybe_body_owned_by(param_owner_id)
-            .map(|body_id| tcx.hir().body(body_id).value.hir_id.local_id)
-            .unwrap_or_else(|| {
-                // The lifetime was defined on node that doesn't own a body,
-                // which in practice can only mean a trait or an impl, that
-                // is the parent of a method, and that is enforced below.
-                if Some(param_owner_id) != self.root_parent {
-                    tcx.sess.delay_span_bug(
-                        DUMMY_SP,
-                        &format!(
-                            "free_scope: {:?} not recognized by the \
-                              region scope tree for {:?} / {:?}",
-                            param_owner,
-                            self.root_parent.map(|id| tcx.hir().local_def_id(id)),
-                            self.root_body.map(|hir_id| hir_id.owner)
-                        ),
-                    );
-                }
-
-                // The trait/impl lifetime is in scope for the method's body.
-                self.root_body.unwrap().local_id
-            });
-
-        Scope { id: scope, data: ScopeData::CallSite }
-    }
-
-    /// Assuming that the provided region was defined within this `ScopeTree`,
-    /// returns the outermost `Scope` that the region outlives.
-    pub fn free_scope(&self, tcx: TyCtxt<'tcx>, fr: &ty::FreeRegion) -> Scope {
-        let param_owner = match fr.bound_region {
-            ty::BoundRegion::BrNamed(def_id, _) => tcx.parent(def_id).unwrap(),
-            _ => fr.scope,
-        };
-
-        // Ensure that the named late-bound lifetimes were defined
-        // on the same function that they ended up being freed in.
-        assert_eq!(param_owner, fr.scope);
-
-        let param_owner_id = tcx.hir().as_local_hir_id(param_owner.expect_local());
-        let body_id = tcx.hir().body_owned_by(param_owner_id);
-        Scope { id: tcx.hir().body(body_id).value.hir_id.local_id, data: ScopeData::CallSite }
-    }
-
     /// Checks whether the given scope contains a `yield`. If so,
     /// returns `Some((span, expr_count))` with the span of a yield we found and
     /// the number of expressions and patterns appearing before the `yield` in the body + 1.
index ebc8021a3c577b5d23f1b70cd0509fbc8db72649..e19fab89eabfee105ac0b47c59a5c91e95e52f89 100644 (file)
@@ -162,10 +162,8 @@ pub(in crate::borrow_check) fn report_region_errors(&mut self, nll_errors: Regio
                     let type_test_span = type_test.locations.span(&self.body);
 
                     if let Some(lower_bound_region) = lower_bound_region {
-                        let region_scope_tree = &self.infcx.tcx.region_scope_tree(self.mir_def_id);
                         self.infcx
                             .construct_generic_bound_failure(
-                                region_scope_tree,
                                 type_test_span,
                                 None,
                                 type_test.generic_kind,
@@ -194,12 +192,10 @@ pub(in crate::borrow_check) fn report_region_errors(&mut self, nll_errors: Regio
                 }
 
                 RegionErrorKind::UnexpectedHiddenRegion { span, hidden_ty, member_region } => {
-                    let region_scope_tree = &self.infcx.tcx.region_scope_tree(self.mir_def_id);
                     let named_ty = self.regioncx.name_regions(self.infcx.tcx, hidden_ty);
                     let named_region = self.regioncx.name_regions(self.infcx.tcx, member_region);
                     unexpected_hidden_region_diagnostic(
                         self.infcx.tcx,
-                        Some(region_scope_tree),
                         span,
                         named_ty,
                         named_region,
index d14ae40b45a0b22aaa6f4e82998861a3d23a831d..484677ded249f9b079fff5ee4e3e329786dad050 100644 (file)
@@ -835,7 +835,6 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
                 if let Some(hidden_ty) = self.hidden_ty.take() {
                     unexpected_hidden_region_diagnostic(
                         self.tcx,
-                        None,
                         self.tcx.def_span(self.opaque_type_def_id),
                         hidden_ty,
                         r,
index 3daa9109aafe8141f02e4051716d551610f89a78..d8e99dc10af2a25140172a39ee65ddc72ee319c8 100644 (file)
@@ -28,7 +28,6 @@
 use rustc_errors::ErrorReported;
 use rustc_hir as hir;
 use rustc_hir::def_id::DefId;
-use rustc_middle::middle::region;
 use rustc_middle::ty::fold::TypeFoldable;
 use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
 use rustc_middle::ty::{
@@ -237,15 +236,12 @@ fn do_normalize_predicates<'tcx>(
 
         debug!("do_normalize_predictes: normalized predicates = {:?}", predicates);
 
-        let region_scope_tree = region::ScopeTree::default();
-
         // We can use the `elaborated_env` here; the region code only
         // cares about declarations like `'a: 'b`.
         let outlives_env = OutlivesEnvironment::new(elaborated_env);
 
         infcx.resolve_regions_and_report_errors(
             region_context,
-            &region_scope_tree,
             &outlives_env,
             RegionckMode::default(),
         );
index 1b7fde69830f04efedf9be6a9ff91c446dae1eac..8fa901d8a984a6969cd368c09a195bf029a95ba2 100644 (file)
@@ -3,7 +3,6 @@
 use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
 
 use crate::astconv::AstConv;
-use crate::middle::region;
 use rustc_hir as hir;
 use rustc_hir::def_id::DefId;
 use rustc_hir::lang_items::{FutureTraitLangItem, GeneratorTraitLangItem};
@@ -17,7 +16,6 @@
 use rustc_target::spec::abi::Abi;
 use rustc_trait_selection::traits::error_reporting::ArgKind;
 use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
-use rustc_trait_selection::traits::Obligation;
 use std::cmp;
 use std::iter;
 
index 594cdab852fdafcf07c6d97822fe070c11eafaee..24c319f26e71f25fb666a9ae43b5630c6de6b87a 100644 (file)
@@ -5,7 +5,6 @@
 use rustc_infer::infer::outlives::env::OutlivesEnvironment;
 use rustc_infer::infer::{InferOk, RegionckMode, TyCtxtInferExt};
 use rustc_infer::traits::TraitEngineExt as _;
-use rustc_middle::middle::region;
 use rustc_middle::ty::error::TypeError;
 use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
 use rustc_middle::ty::subst::{Subst, SubstsRef};
@@ -120,8 +119,6 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
             return Err(ErrorReported);
         }
 
-        let region_scope_tree = region::ScopeTree::default();
-
         // NB. It seems a bit... suspicious to use an empty param-env
         // here. The correct thing, I imagine, would be
         // `OutlivesEnvironment::new(impl_param_env)`, which would
@@ -134,7 +131,6 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
 
         infcx.resolve_regions_and_report_errors(
             drop_impl_did.to_def_id(),
-            &region_scope_tree,
             &outlives_env,
             RegionckMode::default(),
         );
index efa3cd9955b49610ad1537568bb145f130dbf4e5..c5dd314dc655881fa8f6ee2c82b98b9fb96cfe1e 100644 (file)
@@ -11,7 +11,6 @@
 use rustc_infer::infer;
 use rustc_infer::infer::outlives::env::OutlivesEnvironment;
 use rustc_infer::infer::{RegionckMode, TyCtxtInferExt};
-use rustc_middle::middle::region;
 use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
 use rustc_middle::ty::TypeFoldable;
 use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -293,11 +292,9 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
                     }
 
                     // Finally, resolve all regions.
-                    let region_scope_tree = region::ScopeTree::default();
                     let outlives_env = OutlivesEnvironment::new(param_env);
                     infcx.resolve_regions_and_report_errors(
                         impl_did.to_def_id(),
-                        &region_scope_tree,
                         &outlives_env,
                         RegionckMode::default(),
                     );
@@ -552,14 +549,8 @@ pub fn coerce_unsized_info(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUnsizedI
         }
 
         // Finally, resolve all regions.
-        let region_scope_tree = region::ScopeTree::default();
         let outlives_env = OutlivesEnvironment::new(param_env);
-        infcx.resolve_regions_and_report_errors(
-            impl_did,
-            &region_scope_tree,
-            &outlives_env,
-            RegionckMode::default(),
-        );
+        infcx.resolve_regions_and_report_errors(impl_did, &outlives_env, RegionckMode::default());
 
         CoerceUnsizedInfo { custom_kind: kind }
     })
index d30dc1b7a475e4aac235c99c62eb65e95ab1e05e..08404bea56138638aecf4131aa3b94de2f2fded6 100644 (file)
@@ -73,7 +73,6 @@
 use rustc_infer::infer::outlives::env::OutlivesEnvironment;
 use rustc_infer::infer::{InferCtxt, RegionckMode, TyCtxtInferExt};
 use rustc_infer::traits::specialization_graph::Node;
-use rustc_middle::middle::region::ScopeTree;
 use rustc_middle::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
 use rustc_middle::ty::trait_def::TraitSpecializationKind;
 use rustc_middle::ty::{self, InstantiatedPredicates, TyCtxt, TypeFoldable};
@@ -165,12 +164,7 @@ fn get_impl_substs<'tcx>(
 
     // Conservatively use an empty `ParamEnv`.
     let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty());
-    infcx.resolve_regions_and_report_errors(
-        impl1_def_id,
-        &ScopeTree::default(),
-        &outlives_env,
-        RegionckMode::default(),
-    );
+    infcx.resolve_regions_and_report_errors(impl1_def_id, &outlives_env, RegionckMode::default());
     let impl2_substs = match infcx.fully_resolve(&impl2_substs) {
         Ok(s) => s,
         Err(_) => {