]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #24021 - pnkfelix:fn-params-outlive-body, r=nikomatsakis
authorbors <bors@rust-lang.org>
Wed, 8 Apr 2015 12:57:58 +0000 (12:57 +0000)
committerbors <bors@rust-lang.org>
Wed, 8 Apr 2015 12:57:58 +0000 (12:57 +0000)
Encode more precise scoping rules for function params

Function params outlive everything in the body (incl temporaries).  Thus if we assign them their own `CodeExtent`, the region inference can properly show that it is sound to have temporaries with destructors that reference the parameters (because such temporaries will be dropped before the parameters are dropped).

Fix #23338

1  2 
src/librustc/metadata/tydecode.rs

index 9836f8d7991df37b4387f2b711e84311b367c2b1,8030275ef303a0bbd08624c12021589c224f9f28..cce31b1f4c249fb5aaa89758adae6428947cdfeb
@@@ -101,6 -101,10 +101,6 @@@ fn scan<R, F, G>(st: &mut PState, mut i
      return op(&st.data[start_pos..end_pos]);
  }
  
 -pub fn parse_ident(st: &mut PState, last: char) -> ast::Ident {
 -    ast::Ident::new(parse_name(st, last))
 -}
 -
  pub fn parse_name(st: &mut PState, last: char) -> ast::Name {
      fn is_last(b: char, c: char) -> bool { return c == b; }
      parse_name_(st, |a| is_last(last, a) )
@@@ -369,6 -373,16 +369,16 @@@ fn parse_region_<F>(st: &mut PState, co
  
  fn parse_scope(st: &mut PState) -> region::CodeExtent {
      match next(st) {
+         'P' => {
+             assert_eq!(next(st), '[');
+             let fn_id = parse_uint(st) as ast::NodeId;
+             assert_eq!(next(st), '|');
+             let body_id = parse_uint(st) as ast::NodeId;
+             assert_eq!(next(st), ']');
+             region::CodeExtent::ParameterScope {
+                 fn_id: fn_id, body_id: body_id
+             }
+         }
          'M' => {
              let node_id = parse_uint(st) as ast::NodeId;
              region::CodeExtent::Misc(node_id)
              region::CodeExtent::DestructionScope(node_id)
          }
          'B' => {
+             assert_eq!(next(st), '[');
              let node_id = parse_uint(st) as ast::NodeId;
+             assert_eq!(next(st), '|');
              let first_stmt_index = parse_uint(st);
+             assert_eq!(next(st), ']');
              let block_remainder = region::BlockRemainder {
                  block: node_id, first_statement_index: first_stmt_index,
              };