]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/infer/error_reporting/mod.rs
Rollup merge of #44562 - eddyb:ugh-rustdoc, r=nikomatsakis
[rust.git] / src / librustc / infer / error_reporting / mod.rs
index 90d781c6e36649e15357bf3faf14a802da7b165a..a88e90caee3076608b93427b332259000ead0b91 100644 (file)
@@ -64,9 +64,9 @@
 use hir;
 use hir::map as hir_map;
 use hir::def_id::DefId;
-use middle::region::{self, RegionMaps};
+use middle::region;
 use traits::{ObligationCause, ObligationCauseCode};
-use ty::{self, Region, TyCtxt, TypeFoldable};
+use ty::{self, Region, Ty, TyCtxt, TypeFoldable};
 use ty::error::TypeError;
 use syntax::ast::DUMMY_NODE_ID;
 use syntax_pos::{Pos, Span};
 mod named_anon_conflict;
 #[macro_use]
 mod util;
-mod anon_anon_conflict;
+mod different_lifetimes;
 
 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
     pub fn note_and_explain_region(self,
-                                   region_maps: &RegionMaps,
+                                   region_scope_tree: &region::ScopeTree,
                                    err: &mut DiagnosticBuilder,
                                    prefix: &str,
                                    region: ty::Region<'tcx>,
@@ -131,8 +131,8 @@ fn explain_span<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
                     format!("{}unknown scope: {:?}{}.  Please report a bug.",
                             prefix, scope, suffix)
                 };
-                let span = scope.span(self, region_maps);
-                let tag = match self.hir.find(scope.node_id(self, region_maps)) {
+                let span = scope.span(self, region_scope_tree);
+                let tag = match self.hir.find(scope.node_id(self, region_scope_tree)) {
                     Some(hir_map::NodeBlock(_)) => "block",
                     Some(hir_map::NodeExpr(expr)) => match expr.node {
                         hir::ExprCall(..) => "call",
@@ -153,18 +153,18 @@ fn explain_span<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
                     }
                 };
                 let scope_decorated_tag = match scope {
-                    region::CodeExtent::Misc(_) => tag,
-                    region::CodeExtent::CallSiteScope(_) => {
+                    region::Scope::Node(_) => tag,
+                    region::Scope::CallSite(_) => {
                         "scope of call-site for function"
                     }
-                    region::CodeExtent::ParameterScope(_) => {
+                    region::Scope::Arguments(_) => {
                         "scope of function body"
                     }
-                    region::CodeExtent::DestructionScope(_) => {
+                    region::Scope::Destruction(_) => {
                         new_string = format!("destruction scope surrounding {}", tag);
                         &new_string[..]
                     }
-                    region::CodeExtent::Remainder(r) => {
+                    region::Scope::Remainder(r) => {
                         new_string = format!("block suffix following statement {}",
                                              r.first_statement_index);
                         &new_string[..]
@@ -256,7 +256,7 @@ fn explain_span<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
 
 impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     pub fn report_region_errors(&self,
-                                region_maps: &RegionMaps,
+                                region_scope_tree: &region::ScopeTree,
                                 errors: &Vec<RegionResolutionError<'tcx>>) {
         debug!("report_region_errors(): {} errors to start", errors.len());
 
@@ -281,15 +281,15 @@ pub fn report_region_errors(&self,
                   // the error. If all of these fails, we fall back to a rather
                   // general bit of code that displays the error information
                   ConcreteFailure(origin, sub, sup) => {
-                      self.report_concrete_failure(region_maps, origin, sub, sup).emit();
+                      self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
                   }
 
                   GenericBoundFailure(kind, param_ty, sub) => {
-                      self.report_generic_bound_failure(region_maps, kind, param_ty, sub);
+                      self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
                   }
 
                   SubSupConflict(var_origin, sub_origin, sub_r, sup_origin, sup_r) => {
-                        self.report_sub_sup_conflict(region_maps,
+                        self.report_sub_sup_conflict(region_scope_tree,
                                                      var_origin,
                                                      sub_origin,
                                                      sub_r,
@@ -357,7 +357,7 @@ fn check_and_note_conflicting_crates(&self,
                 // for imported and non-imported crates
                 if exp_path == found_path
                 || exp_abs_path == found_abs_path {
-                    let crate_name = self.tcx.sess.cstore.crate_name(did1.krate);
+                    let crate_name = self.tcx.crate_name(did1.krate);
                     err.span_note(sp, &format!("Perhaps two different versions \
                                                 of crate `{}` are being used?",
                                                crate_name));
@@ -418,7 +418,7 @@ fn highlight_outer(&self,
                        name: String,
                        sub: &ty::subst::Substs<'tcx>,
                        pos: usize,
-                       other_ty: &ty::Ty<'tcx>) {
+                       other_ty: &Ty<'tcx>) {
         // `value` and `other_value` hold two incomplete type representation for display.
         // `name` is the path of both types being compared. `sub`
         value.push_highlighted(name);
@@ -491,7 +491,7 @@ fn cmp_type_arg(&self,
                     path: String,
                     sub: &ty::subst::Substs<'tcx>,
                     other_path: String,
-                    other_ty: &ty::Ty<'tcx>) -> Option<()> {
+                    other_ty: &Ty<'tcx>) -> Option<()> {
         for (i, ta) in sub.types().enumerate() {
             if &ta == other_ty {
                 self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
@@ -522,7 +522,7 @@ fn push_comma(&self,
 
     /// Compare two given types, eliding parts that are the same between them and highlighting
     /// relevant differences, and return two representation of those types for highlighted printing.
-    fn cmp(&self, t1: ty::Ty<'tcx>, t2: ty::Ty<'tcx>)
+    fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>)
         -> (DiagnosticStyledString, DiagnosticStyledString)
     {
         match (&t1.sty, &t2.sty) {
@@ -743,7 +743,7 @@ fn values_str(&self, values: &ValuePairs<'tcx>)
     }
 
     fn expected_found_str_ty(&self,
-                             exp_found: &ty::error::ExpectedFound<ty::Ty<'tcx>>)
+                             exp_found: &ty::error::ExpectedFound<Ty<'tcx>>)
                              -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
         let exp_found = self.resolve_type_vars_if_possible(exp_found);
         if exp_found.references_error() {
@@ -769,7 +769,7 @@ fn expected_found_str<T: fmt::Display + TypeFoldable<'tcx>>(
     }
 
     fn report_generic_bound_failure(&self,
-                                    region_maps: &RegionMaps,
+                                    region_scope_tree: &region::ScopeTree,
                                     origin: SubregionOrigin<'tcx>,
                                     bound_kind: GenericKind<'tcx>,
                                     sub: Region<'tcx>)
@@ -837,7 +837,7 @@ fn report_generic_bound_failure(&self,
                 err.help(&format!("consider adding an explicit lifetime bound for `{}`",
                                   bound_kind));
                 self.tcx.note_and_explain_region(
-                    region_maps,
+                    region_scope_tree,
                     &mut err,
                     &format!("{} must be valid for ", labeled_user_string),
                     sub,
@@ -851,7 +851,7 @@ fn report_generic_bound_failure(&self,
     }
 
     fn report_sub_sup_conflict(&self,
-                               region_maps: &RegionMaps,
+                               region_scope_tree: &region::ScopeTree,
                                var_origin: RegionVariableOrigin,
                                sub_origin: SubregionOrigin<'tcx>,
                                sub_region: Region<'tcx>,
@@ -859,14 +859,14 @@ fn report_sub_sup_conflict(&self,
                                sup_region: Region<'tcx>) {
         let mut err = self.report_inference_failure(var_origin);
 
-        self.tcx.note_and_explain_region(region_maps, &mut err,
+        self.tcx.note_and_explain_region(region_scope_tree, &mut err,
             "first, the lifetime cannot outlive ",
             sup_region,
             "...");
 
         self.note_region_origin(&mut err, &sup_origin);
 
-        self.tcx.note_and_explain_region(region_maps, &mut err,
+        self.tcx.note_and_explain_region(region_scope_tree, &mut err,
             "but, the lifetime must be valid for ",
             sub_region,
             "...");
@@ -913,8 +913,9 @@ fn report_inference_failure(&self,
                         name)
             }
             infer::UpvarRegion(ref upvar_id, _) => {
-                format!(" for capture of `{}` by closure",
-                        self.tcx.local_var_name_str_def_index(upvar_id.var_id))
+                let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
+                let var_name = self.tcx.hir.name(var_node_id);
+                format!(" for capture of `{}` by closure", var_name)
             }
         };