Skip to content

Commit 07afe91

Browse files
committed
Allow unstable code to be injected by placement-in expansion.
(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.
1 parent cb5f0b4 commit 07afe91

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,23 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
5050
callee: NameAndSpan {
5151
name: expansion_desc.to_string(),
5252
format: CompilerExpansion,
53+
54+
// This does *not* mean code generated after
55+
// `push_compiler_expansion` is automatically exempt
56+
// from stability lints; must also tag such code with
57+
// an appropriate span from `fld.cx.backtrace()`.
5358
allow_internal_unstable: true,
59+
5460
span: None,
5561
},
5662
});
5763
}
5864

65+
// Sets the expn_id so that we can use unstable methods.
66+
fn allow_unstable(fld: &mut MacroExpander, span: Span) -> Span {
67+
Span { expn_id: fld.cx.backtrace(), ..span }
68+
}
69+
5970
let expr_span = e.span;
6071
return e.and_then(|ast::Expr {id, node, span}| match node {
6172

@@ -101,6 +112,8 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
101112
&fld.cx.parse_sess.span_diagnostic,
102113
expr_span);
103114

115+
push_compiler_expansion(fld, expr_span, "placement-in expansion");
116+
104117
let value_span = value_expr.span;
105118
let placer_span = placer.span;
106119

@@ -121,9 +134,14 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
121134
let inplace_finalize = ["ops", "InPlace", "finalize"];
122135

123136
let make_call = |fld: &mut MacroExpander, p, args| {
124-
let path = mk_core_path(fld, placer_span, p);
137+
// We feed in the `expr_span` because codemap's span_allows_unstable
138+
// allows the call_site span to inherit the `allow_internal_unstable`
139+
// setting.
140+
let span_unstable = allow_unstable(fld, expr_span);
141+
let path = mk_core_path(fld, span_unstable, p);
125142
let path = fld.cx.expr_path(path);
126-
fld.cx.expr_call(span, path, args)
143+
let expr_span_unstable = allow_unstable(fld, span);
144+
fld.cx.expr_call(expr_span_unstable, path, args)
127145
};
128146

129147
let stmt_let = |fld: &mut MacroExpander, bind, expr| {
@@ -166,7 +184,9 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
166184
};
167185

168186
let block = fld.cx.block_all(span, vec![s1, s2, s3], expr);
169-
fld.cx.expr_block(block)
187+
let result = fld.cx.expr_block(block);
188+
fld.cx.bt_pop();
189+
result
170190
}
171191

172192
// Issue #22181:

0 commit comments

Comments
 (0)