]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/region.rs
Auto merge of #30341 - pnkfelix:call-site-scope, r=nikomatsakis
[rust.git] / src / librustc / middle / region.rs
index e3504b6a744dcc46f813314d8efb284658525921..543b218a2bc05f128699755cd9c388d3b7a25d46 100644 (file)
@@ -125,6 +125,10 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 pub enum CodeExtentData {
     Misc(ast::NodeId),
 
+    // extent of the call-site for a function or closure (outlives
+    // the parameters as well as the body).
+    CallSiteScope { fn_id: ast::NodeId, body_id: ast::NodeId },
+
     // extent of parameters passed to a function or closure (they
     // outlive its body)
     ParameterScope { fn_id: ast::NodeId, body_id: ast::NodeId },
@@ -136,20 +140,20 @@ pub enum CodeExtentData {
     Remainder(BlockRemainder)
 }
 
-/// extent of destructors for temporaries of node-id
+/// extent of call-site for a function/method.
 #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable,
            RustcDecodable, Debug, Copy)]
-pub struct DestructionScopeData {
-    pub node_id: ast::NodeId
+pub struct CallSiteScopeData {
+    pub fn_id: ast::NodeId, pub body_id: ast::NodeId,
 }
 
-impl DestructionScopeData {
-    pub fn new(node_id: ast::NodeId) -> DestructionScopeData {
-        DestructionScopeData { node_id: node_id }
-    }
+impl CallSiteScopeData {
     pub fn to_code_extent(&self, region_maps: &RegionMaps) -> CodeExtent {
         region_maps.lookup_code_extent(
-            CodeExtentData::DestructionScope(self.node_id))
+            match *self {
+                CallSiteScopeData { fn_id, body_id } =>
+                    CodeExtentData::CallSiteScope { fn_id: fn_id, body_id: body_id },
+            })
     }
 }
 
@@ -190,6 +194,7 @@ pub fn node_id(&self) -> ast::NodeId {
             // precise extent denoted by `self`.
             CodeExtentData::Remainder(br) => br.block,
             CodeExtentData::DestructionScope(node_id) => node_id,
+            CodeExtentData::CallSiteScope { fn_id: _, body_id } |
             CodeExtentData::ParameterScope { fn_id: _, body_id } => body_id,
         }
     }
@@ -215,6 +220,7 @@ pub fn span(&self, region_maps: &RegionMaps, ast_map: &ast_map::Map) -> Option<S
         match ast_map.find(self.node_id(region_maps)) {
             Some(ast_map::NodeBlock(ref blk)) => {
                 match region_maps.code_extent_data(*self) {
+                    CodeExtentData::CallSiteScope { .. } |
                     CodeExtentData::ParameterScope { .. } |
                     CodeExtentData::Misc(_) |
                     CodeExtentData::DestructionScope(_) => Some(blk.span),
@@ -346,6 +352,10 @@ pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
     pub fn item_extent(&self, n: ast::NodeId) -> CodeExtent {
         self.lookup_code_extent(CodeExtentData::DestructionScope(n))
     }
+    pub fn call_site_extent(&self, fn_id: ast::NodeId, body_id: ast::NodeId) -> CodeExtent {
+        assert!(fn_id != body_id);
+        self.lookup_code_extent(CodeExtentData::CallSiteScope { fn_id: fn_id, body_id: body_id })
+    }
     pub fn opt_destruction_extent(&self, n: ast::NodeId) -> Option<CodeExtent> {
         self.code_extent_interner.borrow().get(&CodeExtentData::DestructionScope(n)).cloned()
     }
@@ -630,7 +640,7 @@ fn ancestors_of<'a>(scope_map: &[CodeExtent],
             }
 
             *vec = Vec::with_capacity(64);
-            vec.push_all(buf);
+            vec.extend_from_slice(buf);
             loop {
                 vec.push(scope);
                 match scope_map[scope.0 as usize].into_option() {
@@ -720,7 +730,7 @@ fn resolve_block(visitor: &mut RegionResolutionVisitor, blk: &hir::Block) {
                     parent: stmt_extent,
                 };
             }
-            visitor.visit_stmt(&**statement)
+            visitor.visit_stmt(statement)
         }
         walk_list!(visitor, visit_expr, &blk.expr);
     }
@@ -1101,6 +1111,9 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
            body.id,
            visitor.cx.parent);
 
+    visitor.cx.parent = visitor.new_code_extent(
+        CodeExtentData::CallSiteScope { fn_id: id, body_id: body.id });
+
     let fn_decl_scope = visitor.new_code_extent(
         CodeExtentData::ParameterScope { fn_id: id, body_id: body.id });