]> git.lizzy.rs Git - rust.git/commitdiff
rustc: take TyCtxt and RegionMaps in CodeMap::span.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Tue, 29 Aug 2017 23:39:06 +0000 (02:39 +0300)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Fri, 1 Sep 2017 08:17:03 +0000 (11:17 +0300)
13 files changed:
src/librustc/infer/error_reporting/mod.rs
src/librustc/infer/error_reporting/note.rs
src/librustc/infer/mod.rs
src/librustc/middle/region.rs
src/librustc/ty/error.rs
src/librustc/ty/structural_impls.rs
src/librustc_borrowck/borrowck/mod.rs
src/librustc_mir/build/block.rs
src/librustc_mir/build/scope.rs
src/librustc_mir/hair/cx/block.rs
src/librustc_mir/hair/mod.rs
src/librustc_typeck/check/generator_interior.rs
src/test/ui/mismatched_types/closure-mismatch.stderr

index 4c55c1474a326c11759e6ce1aa87c81dbcba47d4..d86626c210e14ae3fea10371707b9be432a97b88 100644 (file)
@@ -64,7 +64,7 @@
 use hir;
 use hir::map as hir_map;
 use hir::def_id::DefId;
-use middle::region;
+use middle::region::{self, RegionMaps};
 use traits::{ObligationCause, ObligationCauseCode};
 use ty::{self, Region, TyCtxt, TypeFoldable};
 use ty::error::TypeError;
@@ -83,6 +83,7 @@
 
 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
     pub fn note_and_explain_region(self,
+                                   region_maps: &RegionMaps,
                                    err: &mut DiagnosticBuilder,
                                    prefix: &str,
                                    region: ty::Region<'tcx>,
@@ -130,13 +131,7 @@ fn explain_span<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
                     format!("{}unknown scope: {:?}{}.  Please report a bug.",
                             prefix, scope, suffix)
                 };
-                let span = match scope.span(&self.hir) {
-                    Some(s) => s,
-                    None => {
-                        err.note(&unknown_scope());
-                        return;
-                    }
-                };
+                let span = scope.span(self, region_maps);
                 let tag = match self.hir.find(scope.node_id()) {
                     Some(hir_map::NodeBlock(_)) => "block",
                     Some(hir_map::NodeExpr(expr)) => match expr.node {
@@ -260,8 +255,9 @@ 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, errors: &Vec<RegionResolutionError<'tcx>>) {
+    pub fn report_region_errors(&self,
+                                region_maps: &RegionMaps,
+                                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
@@ -285,16 +281,16 @@ pub fn report_region_errors(&self, errors: &Vec<RegionResolutionError<'tcx>>) {
                   // 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(origin, sub, sup).emit();
+                      self.report_concrete_failure(region_maps, origin, sub, sup).emit();
                   }
 
                   GenericBoundFailure(kind, param_ty, sub) => {
-                      self.report_generic_bound_failure(kind, param_ty, sub);
+                      self.report_generic_bound_failure(region_maps, kind, param_ty, sub);
                   }
 
                   SubSupConflict(var_origin, sub_origin, sub_r, sup_origin, sup_r) => {
-                        self.report_sub_sup_conflict(var_origin,
+                        self.report_sub_sup_conflict(region_maps,
+                                                     var_origin,
                                                      sub_origin,
                                                      sub_r,
                                                      sup_origin,
@@ -773,6 +769,7 @@ fn expected_found_str<T: fmt::Display + TypeFoldable<'tcx>>(
     }
 
     fn report_generic_bound_failure(&self,
+                                    region_maps: &RegionMaps,
                                     origin: SubregionOrigin<'tcx>,
                                     bound_kind: GenericKind<'tcx>,
                                     sub: Region<'tcx>)
@@ -840,6 +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,
                     &mut err,
                     &format!("{} must be valid for ", labeled_user_string),
                     sub,
@@ -853,6 +851,7 @@ fn report_generic_bound_failure(&self,
     }
 
     fn report_sub_sup_conflict(&self,
+                               region_maps: &RegionMaps,
                                var_origin: RegionVariableOrigin,
                                sub_origin: SubregionOrigin<'tcx>,
                                sub_region: Region<'tcx>,
@@ -860,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(&mut err,
+        self.tcx.note_and_explain_region(region_maps, &mut err,
             "first, the lifetime cannot outlive ",
             sup_region,
             "...");
 
         self.note_region_origin(&mut err, &sup_origin);
 
-        self.tcx.note_and_explain_region(&mut err,
+        self.tcx.note_and_explain_region(region_maps, &mut err,
             "but, the lifetime must be valid for ",
             sub_region,
             "...");
index 87047d0df144cca40f03a3f0c83ba835545f8a8d..3e78cce80f594ad24657f502a58b773f17378fe8 100644 (file)
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 use infer::{self, InferCtxt, SubregionOrigin};
+use middle::region::RegionMaps;
 use ty::{self, Region};
 use ty::error::TypeError;
 use errors::DiagnosticBuilder;
@@ -144,6 +145,7 @@ pub(super) fn note_region_origin(&self,
     }
 
     pub(super) fn report_concrete_failure(&self,
+                                          region_maps: &RegionMaps,
                                           origin: SubregionOrigin<'tcx>,
                                           sub: Region<'tcx>,
                                           sup: Region<'tcx>)
@@ -151,7 +153,11 @@ pub(super) fn report_concrete_failure(&self,
         match origin {
             infer::Subtype(trace) => {
                 let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
-                self.report_and_explain_type_error(trace, &terr)
+                let mut err = self.report_and_explain_type_error(trace, &terr);
+                self.tcx.note_and_explain_region(region_maps, &mut err, "", sup, "...");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "...does not necessarily outlive ", sub, "");
+                err
             }
             infer::Reborrow(span) => {
                 let mut err = struct_span_err!(self.tcx.sess,
@@ -159,11 +165,11 @@ pub(super) fn report_concrete_failure(&self,
                                                E0312,
                                                "lifetime of reference outlives lifetime of \
                                                 borrowed content...");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "...the reference is valid for ",
                                                  sub,
                                                  "...");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "...but the borrowed content is only valid for ",
                                                  sup,
                                                  "");
@@ -177,27 +183,27 @@ pub(super) fn report_concrete_failure(&self,
                                                 of captured variable `{}`...",
                                                self.tcx
                                                    .local_var_name_str_def_index(upvar_id.var_id));
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "...the borrowed pointer is valid for ",
                                                  sub,
                                                  "...");
-                self.tcx
-                    .note_and_explain_region(
-                      &mut err,
-                      &format!("...but `{}` is only valid for ",
-                               self.tcx.local_var_name_str_def_index(upvar_id.var_id)),
-                      sup,
-                      "");
+                self.tcx.note_and_explain_region(
+                    region_maps,
+                    &mut err,
+                    &format!("...but `{}` is only valid for ",
+                        self.tcx.local_var_name_str_def_index(upvar_id.var_id)),
+                    sup,
+                    "");
                 err
             }
             infer::InfStackClosure(span) => {
                 let mut err =
                     struct_span_err!(self.tcx.sess, span, E0314, "closure outlives stack frame");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "...the closure must be valid for ",
                                                  sub,
                                                  "...");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "...but the closure's stack frame is only valid \
                                                   for ",
                                                  sup,
@@ -209,8 +215,8 @@ pub(super) fn report_concrete_failure(&self,
                                                span,
                                                E0315,
                                                "cannot invoke closure outside of its lifetime");
-                self.tcx
-                    .note_and_explain_region(&mut err, "the closure is only valid for ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "the closure is only valid for ", sup, "");
                 err
             }
             infer::DerefPointer(span) => {
@@ -218,8 +224,8 @@ pub(super) fn report_concrete_failure(&self,
                                                span,
                                                E0473,
                                                "dereference of reference outside its lifetime");
-                self.tcx
-                    .note_and_explain_region(&mut err, "the reference is only valid for ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "the reference is only valid for ", sup, "");
                 err
             }
             infer::FreeVariable(span, id) => {
@@ -229,9 +235,10 @@ pub(super) fn report_concrete_failure(&self,
                                                "captured variable `{}` does not outlive the \
                                                 enclosing closure",
                                                self.tcx.local_var_name_str(id));
-                self.tcx
-                    .note_and_explain_region(&mut err, "captured variable is valid for ", sup, "");
-                self.tcx.note_and_explain_region(&mut err, "closure is valid for ", sub, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "captured variable is valid for ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "closure is valid for ", sub, "");
                 err
             }
             infer::IndexSlice(span) => {
@@ -239,7 +246,8 @@ pub(super) fn report_concrete_failure(&self,
                                                span,
                                                E0475,
                                                "index of slice outside its lifetime");
-                self.tcx.note_and_explain_region(&mut err, "the slice is only valid for ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "the slice is only valid for ", sup, "");
                 err
             }
             infer::RelateObjectBound(span) => {
@@ -248,8 +256,9 @@ pub(super) fn report_concrete_failure(&self,
                                                E0476,
                                                "lifetime of the source pointer does not outlive \
                                                 lifetime bound of the object type");
-                self.tcx.note_and_explain_region(&mut err, "object type is valid for ", sub, "");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "object type is valid for ", sub, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "source pointer is only valid for ",
                                                  sup,
                                                  "");
@@ -264,10 +273,12 @@ pub(super) fn report_concrete_failure(&self,
                                                self.ty_to_string(ty));
                 match *sub {
                     ty::ReStatic => {
-                        self.tcx.note_and_explain_region(&mut err, "type must satisfy ", sub, "")
+                        self.tcx.note_and_explain_region(region_maps, &mut err,
+                            "type must satisfy ", sub, "")
                     }
                     _ => {
-                        self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "")
+                        self.tcx.note_and_explain_region(region_maps, &mut err,
+                            "type must outlive ", sub, "")
                     }
                 }
                 err
@@ -275,11 +286,11 @@ pub(super) fn report_concrete_failure(&self,
             infer::RelateRegionParamBound(span) => {
                 let mut err =
                     struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "lifetime parameter instantiated with ",
                                                  sup,
                                                  "");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "but lifetime parameter must outlive ",
                                                  sub,
                                                  "");
@@ -292,7 +303,8 @@ pub(super) fn report_concrete_failure(&self,
                                                "the type `{}` (provided as the value of a type \
                                                 parameter) is not valid at this point",
                                                self.ty_to_string(ty));
-                self.tcx.note_and_explain_region(&mut err, "type must outlive ", sub, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "type must outlive ", sub, "");
                 err
             }
             infer::CallRcvr(span) => {
@@ -301,8 +313,8 @@ pub(super) fn report_concrete_failure(&self,
                                                E0480,
                                                "lifetime of method receiver does not outlive the \
                                                 method call");
-                self.tcx
-                    .note_and_explain_region(&mut err, "the receiver is only valid for ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                "the receiver is only valid for ", sup, "");
                 err
             }
             infer::CallArg(span) => {
@@ -311,7 +323,7 @@ pub(super) fn report_concrete_failure(&self,
                                                E0481,
                                                "lifetime of function argument does not outlive \
                                                 the function call");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "the function argument is only valid for ",
                                                  sup,
                                                  "");
@@ -323,7 +335,7 @@ pub(super) fn report_concrete_failure(&self,
                                                E0482,
                                                "lifetime of return value does not outlive the \
                                                 function call");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "the return value is only valid for ",
                                                  sup,
                                                  "");
@@ -335,8 +347,8 @@ pub(super) fn report_concrete_failure(&self,
                                                E0483,
                                                "lifetime of operand does not outlive the \
                                                 operation");
-                self.tcx
-                    .note_and_explain_region(&mut err, "the operand is only valid for ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "the operand is only valid for ", sup, "");
                 err
             }
             infer::AddrOf(span) => {
@@ -344,8 +356,8 @@ pub(super) fn report_concrete_failure(&self,
                                                span,
                                                E0484,
                                                "reference is not valid at the time of borrow");
-                self.tcx
-                    .note_and_explain_region(&mut err, "the borrow is only valid for ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "the borrow is only valid for ", sup, "");
                 err
             }
             infer::AutoBorrow(span) => {
@@ -354,7 +366,7 @@ pub(super) fn report_concrete_failure(&self,
                                                E0485,
                                                "automatically reference is not valid at the time \
                                                 of borrow");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "the automatic borrow is only valid for ",
                                                  sup,
                                                  "");
@@ -367,7 +379,8 @@ pub(super) fn report_concrete_failure(&self,
                                                "type of expression contains references that are \
                                                 not valid during the expression: `{}`",
                                                self.ty_to_string(t));
-                self.tcx.note_and_explain_region(&mut err, "type is only valid for ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "type is only valid for ", sup, "");
                 err
             }
             infer::SafeDestructor(span) => {
@@ -377,8 +390,8 @@ pub(super) fn report_concrete_failure(&self,
                                                "unsafe use of destructor: destructor might be \
                                                 called while references are dead");
                 // FIXME (22171): terms "super/subregion" are suboptimal
-                self.tcx.note_and_explain_region(&mut err, "superregion: ", sup, "");
-                self.tcx.note_and_explain_region(&mut err, "subregion: ", sub, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err, "superregion: ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err, "subregion: ", sub, "");
                 err
             }
             infer::BindingTypeIsNotValidAtDecl(span) => {
@@ -387,8 +400,8 @@ pub(super) fn report_concrete_failure(&self,
                                                E0488,
                                                "lifetime of variable does not enclose its \
                                                 declaration");
-                self.tcx
-                    .note_and_explain_region(&mut err, "the variable is only valid for ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "the variable is only valid for ", sup, "");
                 err
             }
             infer::ParameterInScope(_, span) => {
@@ -396,8 +409,8 @@ pub(super) fn report_concrete_failure(&self,
                                                span,
                                                E0489,
                                                "type/lifetime parameter not in scope here");
-                self.tcx
-                    .note_and_explain_region(&mut err, "the parameter is only valid for ", sub, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "the parameter is only valid for ", sub, "");
                 err
             }
             infer::DataBorrowed(ty, span) => {
@@ -406,8 +419,10 @@ pub(super) fn report_concrete_failure(&self,
                                                E0490,
                                                "a value of type `{}` is borrowed for too long",
                                                self.ty_to_string(ty));
-                self.tcx.note_and_explain_region(&mut err, "the type is valid for ", sub, "");
-                self.tcx.note_and_explain_region(&mut err, "but the borrow lasts for ", sup, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "the type is valid for ", sub, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "but the borrow lasts for ", sup, "");
                 err
             }
             infer::ReferenceOutlivesReferent(ty, span) => {
@@ -417,8 +432,9 @@ pub(super) fn report_concrete_failure(&self,
                                                "in type `{}`, reference has a longer lifetime \
                                                 than the data it references",
                                                self.ty_to_string(ty));
-                self.tcx.note_and_explain_region(&mut err, "the pointer is valid for ", sub, "");
-                self.tcx.note_and_explain_region(&mut err,
+                self.tcx.note_and_explain_region(region_maps, &mut err,
+                    "the pointer is valid for ", sub, "");
+                self.tcx.note_and_explain_region(region_maps, &mut err,
                                                  "but the referenced data is only valid for ",
                                                  sup,
                                                  "");
index 27c6a4c5cf291546b6412f590897870674c79d26..21af92a25e6845249be4e56f9f732dba18fc7063 100644 (file)
@@ -1084,7 +1084,7 @@ pub fn resolve_regions_and_report_errors(&self,
             // 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(&errors); // see error_reporting module
+            self.report_region_errors(region_map, &errors); // see error_reporting module
         }
     }
 
index 8b01d5045c6b06b39f2e3d3634e9cc29a890482f..10a21a582f55439da5534cb9a76b7d4df8a04ff9 100644 (file)
@@ -16,7 +16,6 @@
 //! Most of the documentation on regions can be found in
 //! `middle/infer/region_inference/README.md`
 
-use hir::map as hir_map;
 use util::nodemap::{FxHashMap, NodeMap, NodeSet};
 use ty;
 
@@ -161,34 +160,31 @@ pub fn node_id(&self) -> ast::NodeId {
     /// Returns the span of this CodeExtent.  Note that in general the
     /// returned span may not correspond to the span of any node id in
     /// the AST.
-    pub fn span(&self, hir_map: &hir_map::Map) -> Option<Span> {
-        match hir_map.find(self.node_id()) {
-            Some(hir_map::NodeBlock(ref blk)) => {
-                match *self {
-                    CodeExtent::CallSiteScope(_) |
-                    CodeExtent::ParameterScope(_) |
-                    CodeExtent::Misc(_) |
-                    CodeExtent::DestructionScope(_) => Some(blk.span),
-
-                    CodeExtent::Remainder(r) => {
-                        assert_eq!(r.block, blk.id);
-                        // Want span for extent starting after the
-                        // indexed statement and ending at end of
-                        // `blk`; reuse span of `blk` and shift `lo`
-                        // forward to end of indexed statement.
-                        //
-                        // (This is the special case aluded to in the
-                        // doc-comment for this method)
-                        let stmt_span = blk.stmts[r.first_statement_index as usize].span;
-                        Some(Span::new(stmt_span.hi(), blk.span.hi(), stmt_span.ctxt()))
-                    }
+    pub fn span(&self, tcx: TyCtxt, region_maps: &RegionMaps) -> Span {
+        let root_node = region_maps.root_body.unwrap().node_id;
+        assert_eq!(DefId::local(tcx.hir.node_to_hir_id(self.node_id()).owner),
+                   DefId::local(tcx.hir.node_to_hir_id(root_node).owner));
+        let span = tcx.hir.span(self.node_id());
+        if let CodeExtent::Remainder(r) = *self {
+            if let hir::map::NodeBlock(ref blk) = tcx.hir.get(r.block) {
+                // Want span for extent starting after the
+                // indexed statement and ending at end of
+                // `blk`; reuse span of `blk` and shift `lo`
+                // forward to end of indexed statement.
+                //
+                // (This is the special case aluded to in the
+                // doc-comment for this method)
+
+                let stmt_span = blk.stmts[r.first_statement_index as usize].span;
+
+                // To avoid issues with macro-generated spans, the span
+                // of the statement must be nested in that of the block.
+                if span.lo() <= stmt_span.lo() && stmt_span.lo() <= span.hi() {
+                    return Span::new(stmt_span.lo(), span.hi(), span.ctxt());
                 }
             }
-            Some(hir_map::NodeExpr(ref expr)) => Some(expr.span),
-            Some(hir_map::NodeStmt(ref stmt)) => Some(stmt.span),
-            Some(hir_map::NodeItem(ref item)) => Some(item.span),
-            Some(_) | None => None,
          }
+         span
     }
 }
 
index 802994ae0948ab452c89afbc75cf6dfff9177315..49d7f40000f079b7847c5846c3b49f3b9b5521bc 100644 (file)
@@ -36,11 +36,11 @@ pub enum TypeError<'tcx> {
     TupleSize(ExpectedFound<usize>),
     FixedArraySize(ExpectedFound<usize>),
     ArgCount,
+
     RegionsDoesNotOutlive(Region<'tcx>, Region<'tcx>),
-    RegionsNotSame(Region<'tcx>, Region<'tcx>),
-    RegionsNoOverlap(Region<'tcx>, Region<'tcx>),
     RegionsInsufficientlyPolymorphic(BoundRegion, Region<'tcx>),
     RegionsOverlyPolymorphic(BoundRegion, Region<'tcx>),
+
     Sorts(ExpectedFound<Ty<'tcx>>),
     IntMismatch(ExpectedFound<ty::IntVarValue>),
     FloatMismatch(ExpectedFound<ast::FloatTy>),
@@ -110,12 +110,6 @@ fn report_maybe_different(f: &mut fmt::Formatter,
             RegionsDoesNotOutlive(..) => {
                 write!(f, "lifetime mismatch")
             }
-            RegionsNotSame(..) => {
-                write!(f, "lifetimes are not the same")
-            }
-            RegionsNoOverlap(..) => {
-                write!(f, "lifetimes do not intersect")
-            }
             RegionsInsufficientlyPolymorphic(br, _) => {
                 write!(f,
                        "expected bound lifetime parameter{}{}, found concrete lifetime",
@@ -243,33 +237,6 @@ pub fn note_and_explain_type_err(self,
         use self::TypeError::*;
 
         match err.clone() {
-            RegionsDoesNotOutlive(subregion, superregion) => {
-                self.note_and_explain_region(db, "", subregion, "...");
-                self.note_and_explain_region(db, "...does not necessarily outlive ",
-                                           superregion, "");
-            }
-            RegionsNotSame(region1, region2) => {
-                self.note_and_explain_region(db, "", region1, "...");
-                self.note_and_explain_region(db, "...is not the same lifetime as ",
-                                           region2, "");
-            }
-            RegionsNoOverlap(region1, region2) => {
-                self.note_and_explain_region(db, "", region1, "...");
-                self.note_and_explain_region(db, "...does not overlap ",
-                                           region2, "");
-            }
-            RegionsInsufficientlyPolymorphic(_, conc_region) => {
-                self.note_and_explain_region(db, "concrete lifetime that was found is ",
-                                           conc_region, "");
-            }
-            RegionsOverlyPolymorphic(_, &ty::ReVar(_)) => {
-                // don't bother to print out the message below for
-                // inference variables, it's not very illuminating.
-            }
-            RegionsOverlyPolymorphic(_, conc_region) => {
-                self.note_and_explain_region(db, "expected concrete lifetime is ",
-                                           conc_region, "");
-            }
             Sorts(values) => {
                 let expected_str = values.expected.sort_string(self);
                 let found_str = values.found.sort_string(self);
index 6353c5e0dd0e015020dee1f9bab637bb03402cd4..ae05568ab414854a6edbbbfb27ac3a9d45c57774 100644 (file)
@@ -371,12 +371,6 @@ fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lif
             RegionsDoesNotOutlive(a, b) => {
                 return tcx.lift(&(a, b)).map(|(a, b)| RegionsDoesNotOutlive(a, b))
             }
-            RegionsNotSame(a, b) => {
-                return tcx.lift(&(a, b)).map(|(a, b)| RegionsNotSame(a, b))
-            }
-            RegionsNoOverlap(a, b) => {
-                return tcx.lift(&(a, b)).map(|(a, b)| RegionsNoOverlap(a, b))
-            }
             RegionsInsufficientlyPolymorphic(a, b) => {
                 return tcx.lift(&b).map(|b| RegionsInsufficientlyPolymorphic(a, b))
             }
@@ -1057,12 +1051,6 @@ fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F)
             RegionsDoesNotOutlive(a, b) => {
                 RegionsDoesNotOutlive(a.fold_with(folder), b.fold_with(folder))
             },
-            RegionsNotSame(a, b) => {
-                RegionsNotSame(a.fold_with(folder), b.fold_with(folder))
-            },
-            RegionsNoOverlap(a, b) => {
-                RegionsNoOverlap(a.fold_with(folder), b.fold_with(folder))
-            },
             RegionsInsufficientlyPolymorphic(a, b) => {
                 RegionsInsufficientlyPolymorphic(a, b.fold_with(folder))
             },
@@ -1088,9 +1076,7 @@ fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
         match *self {
             UnsafetyMismatch(x) => x.visit_with(visitor),
             AbiMismatch(x) => x.visit_with(visitor),
-            RegionsDoesNotOutlive(a, b) |
-            RegionsNotSame(a, b) |
-            RegionsNoOverlap(a, b) => {
+            RegionsDoesNotOutlive(a, b) => {
                 a.visit_with(visitor) || b.visit_with(visitor)
             },
             RegionsInsufficientlyPolymorphic(_, b) |
index 0b62da306db47f3febe02cc85b8e8094a7adbbfc..e4384935e373320dc9b0b7c10cb2820949dc312e 100644 (file)
@@ -943,6 +943,7 @@ fn report_bckerr(&self, err: &BckError<'tcx>) {
                             }
                             None => {
                                 self.tcx.note_and_explain_region(
+                                    &self.region_maps,
                                     &mut db,
                                     "borrowed value must be valid for ",
                                     sub_scope,
@@ -955,6 +956,7 @@ fn report_bckerr(&self, err: &BckError<'tcx>) {
                             }
                             None => {
                                 self.tcx.note_and_explain_region(
+                                    &self.region_maps,
                                     &mut db,
                                     "...but borrowed value is only valid for ",
                                     super_scope,
@@ -984,12 +986,14 @@ fn report_bckerr(&self, err: &BckError<'tcx>) {
                     None => self.cmt_to_string(&err.cmt),
                 };
                 self.tcx.note_and_explain_region(
+                    &self.region_maps,
                     &mut db,
                     &format!("{} would have to be valid for ",
                             descr),
                     loan_scope,
                     "...");
                 self.tcx.note_and_explain_region(
+                    &self.region_maps,
                     &mut db,
                     &format!("...but {} is only valid for ", descr),
                     ptr_scope,
@@ -1245,14 +1249,7 @@ fn report_out_of_scope_escaping_closure_capture(&self,
     fn region_end_span(&self, region: ty::Region<'tcx>) -> Option<Span> {
         match *region {
             ty::ReScope(scope) => {
-                match scope.span(&self.tcx.hir) {
-                    Some(s) => {
-                        Some(s.end_point())
-                    }
-                    None => {
-                        None
-                    }
-                }
+                Some(scope.span(self.tcx, &self.region_maps).end_point())
             }
             _ => None
         }
index 4583d80b83ddce228a8db1f122e33342d2dfa8cc..5c0388a020c76b63e3724cb42cc2751e6c254fd3 100644 (file)
@@ -71,7 +71,7 @@ fn ast_block_stmts(&mut self,
         let outer_visibility_scope = this.visibility_scope;
         let source_info = this.source_info(span);
         for stmt in stmts {
-            let Stmt { span, kind, opt_destruction_extent } = this.hir.mirror(stmt);
+            let Stmt { kind, opt_destruction_extent } = this.hir.mirror(stmt);
             match kind {
                 StmtKind::Expr { scope, expr } => {
                     unpack!(block = this.in_opt_scope(
@@ -83,15 +83,13 @@ fn ast_block_stmts(&mut self,
                         }));
                 }
                 StmtKind::Let { remainder_scope, init_scope, pattern, initializer } => {
-                    let tcx = this.hir.tcx();
-
                     // Enter the remainder scope, i.e. the bindings' destruction scope.
                     this.push_scope((remainder_scope, source_info));
                     let_extent_stack.push(remainder_scope);
 
                     // Declare the bindings, which may create a visibility scope.
-                    let remainder_span = remainder_scope.span(&tcx.hir);
-                    let remainder_span = remainder_span.unwrap_or(span);
+                    let remainder_span = remainder_scope.span(this.hir.tcx(),
+                                                              &this.hir.region_maps);
                     let scope = this.declare_bindings(None, remainder_span, &pattern);
 
                     // Evaluate the initializer, if present.
index 90f9c1c0d5f56cbb69ed203118da821e559a21d6..2471d8c2c56f7d66fe9710fe402ae3f482de36e2 100644 (file)
@@ -633,8 +633,7 @@ pub fn schedule_drop(&mut self,
                 if let DropKind::Value { .. } = drop_kind {
                     scope.needs_cleanup = true;
                 }
-                let tcx = self.hir.tcx();
-                let extent_span = extent.span(&tcx.hir).unwrap();
+                let extent_span = extent.span(self.hir.tcx(), &self.hir.region_maps);
                 // Attribute scope exit drops to scope's closing brace
                 let scope_end = extent_span.with_lo(extent_span.hi());
                 scope.drops.push(DropData {
index 61d128fc847827d2a3adcb7c6dd38d86d46aa614..d38c72c37e80f97ab4927b07a20d9765d6014935 100644 (file)
@@ -45,7 +45,6 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
             hir::StmtExpr(ref expr, id) |
             hir::StmtSemi(ref expr, id) => {
                 result.push(StmtRef::Mirror(Box::new(Stmt {
-                    span: stmt.span,
                     kind: StmtKind::Expr {
                         scope: CodeExtent::Misc(id),
                         expr: expr.to_ref(),
@@ -69,7 +68,6 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
                                                         cx.tables(),
                                                         &local.pat);
                         result.push(StmtRef::Mirror(Box::new(Stmt {
-                            span: stmt.span,
                             kind: StmtKind::Let {
                                 remainder_scope: remainder_extent,
                                 init_scope: CodeExtent::Misc(id),
index 9bd5df16a14e9ff31f88cc38f844f6d5c3cd157d..58051aaecdaab464ae057200a7454b367064a53c 100644 (file)
@@ -46,7 +46,6 @@ pub enum StmtRef<'tcx> {
 
 #[derive(Clone, Debug)]
 pub struct Stmt<'tcx> {
-    pub span: Span,
     pub kind: StmtKind<'tcx>,
     pub opt_destruction_extent: Option<CodeExtent>,
 }
index e9d400c64393b5ac7d60f0bb79137cbbe74cb689..46948b687d26dd09eba98862d45023b4b1b528bc 100644 (file)
@@ -13,7 +13,6 @@
 //! is calculated in `rustc_mir::transform::generator` and may be a subset of the
 //! types computed here.
 
-use log;
 use rustc::hir::def_id::DefId;
 use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
 use rustc::hir::{self, Body, Pat, PatKind, Expr};
@@ -36,18 +35,15 @@ impl<'a, 'gcx, 'tcx> InteriorVisitor<'a, 'gcx, 'tcx> {
     fn record(&mut self, ty: Ty<'tcx>, scope: Option<CodeExtent>, expr: Option<&'tcx Expr>) {
         use syntax_pos::DUMMY_SP;
 
-        let live_across_yield = scope.map(|s| {
-            self.fcx.tcx.yield_in_extent(s, &mut self.cache).is_some()
-        }).unwrap_or(true);
+        let live_across_yield = scope.map_or(Some(DUMMY_SP), |s| {
+            self.fcx.tcx.yield_in_extent(s, &mut self.cache)
+        });
 
-        if live_across_yield {
+        if let Some(span) = live_across_yield {
             let ty = self.fcx.resolve_type_vars_if_possible(&ty);
 
-            if log_enabled!(log::LogLevel::Debug) {
-                let span = scope.map(|s| s.span(&self.fcx.tcx.hir).unwrap_or(DUMMY_SP));
-                debug!("type in expr = {:?}, scope = {:?}, type = {:?}, span = {:?}",
-                       expr, scope, ty, span);
-            }
+            debug!("type in expr = {:?}, scope = {:?}, type = {:?}, span = {:?}",
+                   expr, scope, ty, span);
 
             // Map the type to the number of types added before it
             let entries = self.types.len();
index b7479f15b181294b88bb7cebba33c910d5224e65..d928a6a0a8e64b0299ca3fc2bf807963dbce1fbd 100644 (file)
@@ -4,7 +4,6 @@ error[E0271]: type mismatch resolving `for<'r> <[closure@$DIR/closure-mismatch.r
 18 |     baz(|_| ());
    |     ^^^ expected bound lifetime parameter, found concrete lifetime
    |
-   = note: concrete lifetime that was found is lifetime '_#0r
    = note: required because of the requirements on the impl of `Foo` for `[closure@$DIR/closure-mismatch.rs:18:9: 18:15]`
    = note: required by `baz`