about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlqd <remy.rakic+github@gmail.com>2019-01-25 18:22:44 +0100
committerRémy Rakic <remy.rakic@gmail.com>2019-01-27 10:52:40 +0100
commitc1437c944c280ff9d761c45912167f1023d0e24c (patch)
treec10884ae1720d288ba8b09cc20d99394da4b4d09
parent1484d0d123860dbd79804e9996f3fa5b6f4a6d58 (diff)
downloadrust-c1437c944c280ff9d761c45912167f1023d0e24c.tar.gz
rust-c1437c944c280ff9d761c45912167f1023d0e24c.zip
Make NiceRegionError use the `InferCtxt` instead of its `TyCtxt`
Some errors (e.g placeholder errors) have unresolved type vars so this will allow to use `resolve_type_vars_if_possible` when needed.
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs6
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs8
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/mod.rs18
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs10
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs4
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs20
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs10
-rw-r--r--src/librustc/infer/error_reporting/nice_region_error/util.rs14
-rw-r--r--src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs2
9 files changed, 48 insertions, 44 deletions
diff --git a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs
index bfb5b61d0aa..8be49b27924 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/different_lifetimes.rs
@@ -46,9 +46,9 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         let (span, sub, sup) = self.get_regions();
 
         // Determine whether the sub and sup consist of both anonymous (elided) regions.
-        let anon_reg_sup = self.tcx.is_suitable_region(sup)?;
+        let anon_reg_sup = self.tcx().is_suitable_region(sup)?;
 
-        let anon_reg_sub = self.tcx.is_suitable_region(sub)?;
+        let anon_reg_sub = self.tcx().is_suitable_region(sub)?;
         let scope_def_id_sup = anon_reg_sup.def_id;
         let bregion_sup = anon_reg_sup.boundregion;
         let scope_def_id_sub = anon_reg_sub.def_id;
@@ -138,7 +138,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         };
 
 
-        struct_span_err!(self.tcx.sess, span, E0623, "lifetime mismatch")
+        struct_span_err!(self.tcx().sess, span, E0623, "lifetime mismatch")
             .span_label(span_1, main_label)
             .span_label(span_2, String::new())
             .span_label(span, span_label)
diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs
index d230ce55471..eeaa01375ed 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs
@@ -26,10 +26,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         region: Region<'tcx>,
         br: &ty::BoundRegion,
     ) -> Option<(&hir::Ty, &hir::FnDecl)> {
-        if let Some(anon_reg) = self.tcx.is_suitable_region(region) {
+        if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
             let def_id = anon_reg.def_id;
-            if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) {
-                let fndecl = match self.tcx.hir().get(node_id) {
+            if let Some(node_id) = self.tcx().hir().as_local_node_id(def_id) {
+                let fndecl = match self.tcx().hir().get(node_id) {
                     Node::Item(&hir::Item {
                         node: hir::ItemKind::Fn(ref fndecl, ..),
                         ..
@@ -64,7 +64,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         br: &ty::BoundRegion,
     ) -> Option<(&'gcx hir::Ty)> {
         let mut nested_visitor = FindNestedTypeVisitor {
-            tcx: self.tcx,
+            tcx: self.tcx(),
             bound_region: *br,
             found_type: None,
             current_index: ty::INNERMOST,
diff --git a/src/librustc/infer/error_reporting/nice_region_error/mod.rs b/src/librustc/infer/error_reporting/nice_region_error/mod.rs
index f7ba546fa7f..d34b71c33f4 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/mod.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/mod.rs
@@ -22,15 +22,15 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
 
         if let Some(tables) = self.in_progress_tables {
             let tables = tables.borrow();
-            NiceRegionError::new(self.tcx, error.clone(), Some(&tables)).try_report().is_some()
+            NiceRegionError::new(self, error.clone(), Some(&tables)).try_report().is_some()
         } else {
-            NiceRegionError::new(self.tcx, error.clone(), None).try_report().is_some()
+            NiceRegionError::new(self, error.clone(), None).try_report().is_some()
         }
     }
 }
 
 pub struct NiceRegionError<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
-    tcx: TyCtxt<'cx, 'gcx, 'tcx>,
+    infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
     error: Option<RegionResolutionError<'tcx>>,
     regions: Option<(Span, ty::Region<'tcx>, ty::Region<'tcx>)>,
     tables: Option<&'cx ty::TypeckTables<'tcx>>,
@@ -38,21 +38,25 @@ pub struct NiceRegionError<'cx, 'gcx: 'tcx, 'tcx: 'cx> {
 
 impl<'cx, 'gcx, 'tcx> NiceRegionError<'cx, 'gcx, 'tcx> {
     pub fn new(
-        tcx: TyCtxt<'cx, 'gcx, 'tcx>,
+        infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
         error: RegionResolutionError<'tcx>,
         tables: Option<&'cx ty::TypeckTables<'tcx>>,
     ) -> Self {
-        Self { tcx, error: Some(error), regions: None, tables }
+        Self { infcx, error: Some(error), regions: None, tables }
     }
 
     pub fn new_from_span(
-        tcx: TyCtxt<'cx, 'gcx, 'tcx>,
+        infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
         span: Span,
         sub: ty::Region<'tcx>,
         sup: ty::Region<'tcx>,
         tables: Option<&'cx ty::TypeckTables<'tcx>>,
     ) -> Self {
-        Self { tcx, error: None, regions: Some((span, sub, sup)), tables }
+        Self { infcx, error: None, regions: Some((span, sub, sup)), tables }
+    }
+
+    fn tcx(&self) -> TyCtxt<'cx, 'gcx, 'tcx> {
+        self.infcx.tcx
     }
 
     pub fn try_report_from_nll(&self) -> Option<ErrorReported> {
diff --git a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs
index 918a46aacd0..05333f43373 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs
@@ -24,23 +24,23 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         // version new_ty of its type where the anonymous region is replaced
         // with the named one.//scope_def_id
         let (named, anon, anon_arg_info, region_info) = if self.is_named_region(sub)
-            && self.tcx.is_suitable_region(sup).is_some()
+            && self.tcx().is_suitable_region(sup).is_some()
             && self.find_arg_with_region(sup, sub).is_some()
         {
             (
                 sub,
                 sup,
                 self.find_arg_with_region(sup, sub).unwrap(),
-                self.tcx.is_suitable_region(sup).unwrap(),
+                self.tcx().is_suitable_region(sup).unwrap(),
             )
-        } else if self.is_named_region(sup) && self.tcx.is_suitable_region(sub).is_some()
+        } else if self.is_named_region(sup) && self.tcx().is_suitable_region(sub).is_some()
             && self.find_arg_with_region(sub, sup).is_some()
         {
             (
                 sup,
                 sub,
                 self.find_arg_with_region(sub, sup).unwrap(),
-                self.tcx.is_suitable_region(sub).unwrap(),
+                self.tcx().is_suitable_region(sub).unwrap(),
             )
         } else {
             return None; // inapplicable
@@ -97,7 +97,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         };
 
         struct_span_err!(
-            self.tcx.sess,
+            self.tcx().sess,
             span,
             E0621,
             "explicit lifetime required in {}",
diff --git a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs
index c4c71037d8b..cbd36a8b2db 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs
@@ -47,7 +47,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
             // closure, provide a specific message pointing this out.
             if let (&SubregionOrigin::BindingTypeIsNotValidAtDecl(ref external_span),
                     &RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) {
-                let hir = &self.tcx.hir();
+                let hir = &self.tcx().hir();
                 if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
                     if let Node::Expr(Expr {
                         node: Closure(_, _, _, closure_span, None),
@@ -55,7 +55,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
                     }) = hir.get(node_id) {
                         let sup_sp = sup_origin.span();
                         let origin_sp = origin.span();
-                        let mut err = self.tcx.sess.struct_span_err(
+                        let mut err = self.tcx().sess.struct_span_err(
                             sup_sp,
                             "borrowed data cannot be stored outside of its closure");
                         err.span_label(sup_sp, "cannot be stored outside of its closure");
diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs
index 0dda636a9bd..7ece3d38a7f 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs
@@ -38,7 +38,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
                 if expected.def_id == found.def_id =>
             {
                 Some(self.try_report_placeholders_trait(
-                    Some(self.tcx.mk_region(ty::ReVar(*vid))),
+                    Some(self.tcx().mk_region(ty::ReVar(*vid))),
                     cause,
                     Some(sub_placeholder),
                     Some(sup_placeholder),
@@ -62,7 +62,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
                 if expected.def_id == found.def_id =>
             {
                 Some(self.try_report_placeholders_trait(
-                    Some(self.tcx.mk_region(ty::ReVar(*vid))),
+                    Some(self.tcx().mk_region(ty::ReVar(*vid))),
                     cause,
                     Some(sub_placeholder),
                     None,
@@ -86,7 +86,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
                 if expected.def_id == found.def_id =>
             {
                 Some(self.try_report_placeholders_trait(
-                    Some(self.tcx.mk_region(ty::ReVar(*vid))),
+                    Some(self.tcx().mk_region(ty::ReVar(*vid))),
                     cause,
                     None,
                     Some(*sup_placeholder),
@@ -182,11 +182,11 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
         expected_substs: &'tcx Substs<'tcx>,
         actual_substs: &'tcx Substs<'tcx>,
     ) -> ErrorReported {
-        let mut err = self.tcx.sess.struct_span_err(
-            cause.span(&self.tcx),
+        let mut err = self.tcx().sess.struct_span_err(
+            cause.span(&self.tcx()),
             &format!(
                 "implementation of `{}` is not general enough",
-                self.tcx.item_path_str(trait_def_id),
+                self.tcx().item_path_str(trait_def_id),
             ),
         );
 
@@ -194,7 +194,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
             ObligationCauseCode::ItemObligation(def_id) => {
                 err.note(&format!(
                     "Due to a where-clause on `{}`,",
-                    self.tcx.item_path_str(def_id),
+                    self.tcx().item_path_str(def_id),
                 ));
             }
             _ => (),
@@ -220,7 +220,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
         let mut has_sup = None;
         let mut has_vid = None;
 
-        self.tcx.for_each_free_region(&expected_trait_ref, |r| {
+        self.tcx().for_each_free_region(&expected_trait_ref, |r| {
             if Some(r) == sub_placeholder && has_sub.is_none() {
                 has_sub = Some(counter);
                 counter += 1;
@@ -230,7 +230,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
             }
         });
 
-        self.tcx.for_each_free_region(&actual_trait_ref, |r| {
+        self.tcx().for_each_free_region(&actual_trait_ref, |r| {
             if Some(r) == vid && has_vid.is_none() {
                 has_vid = Some(counter);
                 counter += 1;
@@ -238,7 +238,7 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
         });
 
         let self_ty_has_vid = self
-            .tcx
+            .tcx()
             .any_free_region_meets(&actual_trait_ref.self_ty(), |r| Some(r) == vid);
 
         RegionHighlightMode::maybe_highlighting_region(sub_placeholder, has_sub, || {
diff --git a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs
index 7501e2f2108..4331518d403 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs
@@ -19,13 +19,13 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
                     sup_r,
                 ) = error.clone()
             {
-                let anon_reg_sup = self.tcx.is_suitable_region(sup_r)?;
+                let anon_reg_sup = self.tcx().is_suitable_region(sup_r)?;
                 if sub_r == &RegionKind::ReStatic &&
-                    self.tcx.return_type_impl_trait(anon_reg_sup.def_id).is_some()
+                    self.tcx().return_type_impl_trait(anon_reg_sup.def_id).is_some()
                 {
                     let sp = var_origin.span();
                     let return_sp = sub_origin.span();
-                    let mut err = self.tcx.sess.struct_span_err(
+                    let mut err = self.tcx().sess.struct_span_err(
                         sp,
                         "cannot infer an appropriate lifetime",
                     );
@@ -38,7 +38,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
                         "...but this borrow...",
                     );
 
-                    let (lifetime, lt_sp_opt) = self.tcx.msg_span_from_free_region(sup_r);
+                    let (lifetime, lt_sp_opt) = self.tcx().msg_span_from_free_region(sup_r);
                     if let Some(lifetime_sp) = lt_sp_opt {
                         err.span_note(
                             lifetime_sp,
@@ -52,7 +52,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
                         }) => name.to_string(),
                         _ => "'_".to_owned(),
                     };
-                    if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) {
+                    if let Ok(snippet) = self.tcx().sess.source_map().span_to_snippet(return_sp) {
                         err.span_suggestion(
                             return_sp,
                             &format!(
diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs
index 43590a606ae..dd8a33829eb 100644
--- a/src/librustc/infer/error_reporting/nice_region_error/util.rs
+++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs
@@ -44,13 +44,13 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         let (id, bound_region) = match *anon_region {
             ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
             ty::ReEarlyBound(ref ebr) => (
-                self.tcx.parent_def_id(ebr.def_id).unwrap(),
+                self.tcx().parent_def_id(ebr.def_id).unwrap(),
                 ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
             ),
             _ => return None, // not a free region
         };
 
-        let hir = &self.tcx.hir();
+        let hir = &self.tcx().hir();
         if let Some(node_id) = hir.as_local_node_id(id) {
             if let Some(body_id) = hir.maybe_body_owned_by(node_id) {
                 let body = hir.body(body_id);
@@ -66,7 +66,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
                             let arg_ty_span = hir.span(hir.hir_to_node_id(ty_hir_id));
                             let ty = tables.node_id_to_type_opt(arg.hir_id)?;
                             let mut found_anon_region = false;
-                            let new_arg_ty = self.tcx.fold_regions(&ty, &mut false, |r, _| {
+                            let new_arg_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| {
                                 if *r == *anon_region {
                                     found_anon_region = true;
                                     replace_region
@@ -108,10 +108,10 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
         br: ty::BoundRegion,
         decl: &hir::FnDecl,
     ) -> Option<Span> {
-        let ret_ty = self.tcx.type_of(scope_def_id);
+        let ret_ty = self.tcx().type_of(scope_def_id);
         if let ty::FnDef(_, _) = ret_ty.sty {
-            let sig = ret_ty.fn_sig(self.tcx);
-            let late_bound_regions = self.tcx
+            let sig = ret_ty.fn_sig(self.tcx());
+            let late_bound_regions = self.tcx()
                 .collect_referenced_late_bound_regions(&sig.output());
             if late_bound_regions.iter().any(|r| *r == br) {
                 return Some(decl.output.span());
@@ -126,7 +126,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
     // enable E0621 for it.
     pub(super) fn is_self_anon(&self, is_first: bool, scope_def_id: DefId) -> bool {
         is_first
-            && self.tcx
+            && self.tcx()
                    .opt_associated_item(scope_def_id)
                    .map(|i| i.method_has_self_argument) == Some(true)
     }
diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
index f07880075c1..ec68ddaf3c8 100644
--- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
@@ -243,7 +243,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         // Check if we can use one of the "nice region errors".
         if let (Some(f), Some(o)) = (self.to_error_region(fr), self.to_error_region(outlived_fr)) {
             let tables = infcx.tcx.typeck_tables_of(mir_def_id);
-            let nice = NiceRegionError::new_from_span(infcx.tcx, span, o, f, Some(tables));
+            let nice = NiceRegionError::new_from_span(infcx, span, o, f, Some(tables));
             if let Some(_error_reported) = nice.try_report_from_nll() {
                 return;
             }