1
Fork 0

Rollup merge of #123182 - jhpratt:fix-decodable-derive, r=davidtwco

Avoid expanding to unstable internal method

Fixes #123156

Rather than expanding to `std::rt::begin_panic`, the expansion is now to `unreachable!()`. The resulting behavior is identical. A test that previously triggered the same error as #123156 has been added to ensure it does not regress.

r? compiler
This commit is contained in:
Jacob Pratt 2024-04-02 20:37:40 -04:00 committed by GitHub
commit e41d7e7aaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 70 additions and 9 deletions

View file

@ -48,6 +48,23 @@ impl<'a> ExtCtxt<'a> {
ast::Path { span, segments, tokens: None }
}
pub fn macro_call(
&self,
span: Span,
path: ast::Path,
delim: ast::token::Delimiter,
tokens: ast::tokenstream::TokenStream,
) -> P<ast::MacCall> {
P(ast::MacCall {
path,
args: P(ast::DelimArgs {
dspan: ast::tokenstream::DelimSpan { open: span, close: span },
delim,
tokens,
}),
})
}
pub fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {
ast::MutTy { ty, mutbl }
}
@ -265,6 +282,10 @@ impl<'a> ExtCtxt<'a> {
self.expr(span, ast::ExprKind::Field(expr, field))
}
pub fn expr_macro_call(&self, span: Span, call: P<ast::MacCall>) -> P<ast::Expr> {
self.expr(span, ast::ExprKind::MacCall(call))
}
pub fn expr_binary(
&self,
sp: Span,
@ -410,16 +431,19 @@ impl<'a> ExtCtxt<'a> {
self.expr(sp, ast::ExprKind::Tup(exprs))
}
pub fn expr_fail(&self, span: Span, msg: Symbol) -> P<ast::Expr> {
self.expr_call_global(
span,
[sym::std, sym::rt, sym::begin_panic].iter().map(|s| Ident::new(*s, span)).collect(),
thin_vec![self.expr_str(span, msg)],
)
}
pub fn expr_unreachable(&self, span: Span) -> P<ast::Expr> {
self.expr_fail(span, Symbol::intern("internal error: entered unreachable code"))
self.expr_macro_call(
span,
self.macro_call(
span,
self.path_global(
span,
[sym::std, sym::unreachable].map(|s| Ident::new(s, span)).to_vec(),
),
ast::token::Delimiter::Parenthesis,
ast::tokenstream::TokenStream::default(),
),
)
}
pub fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {