]> git.lizzy.rs Git - rust.git/commitdiff
Allow unstable code to be injected by placement-`in` expansion.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Fri, 5 Jun 2015 16:51:23 +0000 (18:51 +0200)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Wed, 22 Jul 2015 13:34:00 +0000 (15:34 +0200)
(Over time the stability checking has gotten more finicky; in
particular one must attach the (whole) span of the original `in PLACE
BLOCK` expression to the injected references to unstable paths, as
noted in the comments.)

call `push_compiler_expansion` during the placement-`in` expansion.

src/libsyntax/ext/expand.rs

index 93e744287bae57274928c2973ac0f323135fea66..faa1e5b2f515fff67234c75677733d14e69e8b85 100644 (file)
@@ -50,12 +50,23 @@ fn push_compiler_expansion(fld: &mut MacroExpander, span: Span, expansion_desc:
             callee: NameAndSpan {
                 name: expansion_desc.to_string(),
                 format: CompilerExpansion,
+
+                // This does *not* mean code generated after
+                // `push_compiler_expansion` is automatically exempt
+                // from stability lints; must also tag such code with
+                // an appropriate span from `fld.cx.backtrace()`.
                 allow_internal_unstable: true,
+
                 span: None,
             },
         });
     }
 
+    // Sets the expn_id so that we can use unstable methods.
+    fn allow_unstable(fld: &mut MacroExpander, span: Span) -> Span {
+        Span { expn_id: fld.cx.backtrace(), ..span }
+    }
+
     let expr_span = e.span;
     return e.and_then(|ast::Expr {id, node, span}| match node {
 
@@ -101,6 +112,8 @@ fn push_compiler_expansion(fld: &mut MacroExpander, span: Span, expansion_desc:
                 &fld.cx.parse_sess.span_diagnostic,
                 expr_span);
 
+            push_compiler_expansion(fld, expr_span, "placement-in expansion");
+
             let value_span = value_expr.span;
             let placer_span = placer.span;
 
@@ -121,9 +134,14 @@ fn push_compiler_expansion(fld: &mut MacroExpander, span: Span, expansion_desc:
             let inplace_finalize = ["ops", "InPlace", "finalize"];
 
             let make_call = |fld: &mut MacroExpander, p, args| {
-                let path = mk_core_path(fld, placer_span, p);
+                // We feed in the `expr_span` because codemap's span_allows_unstable
+                // allows the call_site span to inherit the `allow_internal_unstable`
+                // setting.
+                let span_unstable = allow_unstable(fld, expr_span);
+                let path = mk_core_path(fld, span_unstable, p);
                 let path = fld.cx.expr_path(path);
-                fld.cx.expr_call(span, path, args)
+                let expr_span_unstable = allow_unstable(fld, span);
+                fld.cx.expr_call(expr_span_unstable, path, args)
             };
 
             let stmt_let = |fld: &mut MacroExpander, bind, expr| {
@@ -166,7 +184,9 @@ fn push_compiler_expansion(fld: &mut MacroExpander, span: Span, expansion_desc:
             };
 
             let block = fld.cx.block_all(span, vec![s1, s2, s3], expr);
-            fld.cx.expr_block(block)
+            let result = fld.cx.expr_block(block);
+            fld.cx.bt_pop();
+            result
         }
 
         // Issue #22181: