diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2024-03-29 05:35:45 +0000 |
|---|---|---|
| committer | Jacob Pratt <jacob@jhpratt.dev> | 2024-04-02 22:21:16 +0000 |
| commit | 0fcdf3486146b5b2fc5d4b7f3bcaffbbb6a95fdc (patch) | |
| tree | b85362a048a0ba7ae840c7f638c2c420acda2aef /compiler/rustc_expand/src/build.rs | |
| parent | d74804636fa57e80d1e213fa9d2d65b27216b515 (diff) | |
| download | rust-0fcdf3486146b5b2fc5d4b7f3bcaffbbb6a95fdc.tar.gz rust-0fcdf3486146b5b2fc5d4b7f3bcaffbbb6a95fdc.zip | |
Avoid expanding to unstable internal method
Diffstat (limited to 'compiler/rustc_expand/src/build.rs')
| -rw-r--r-- | compiler/rustc_expand/src/build.rs | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 30559871b4e..cdcf67b26f8 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -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,18 +431,21 @@ 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( + pub fn expr_unreachable(&self, span: Span) -> P<ast::Expr> { + self.expr_macro_call( span, - [sym::std, sym::rt, sym::begin_panic].iter().map(|s| Ident::new(*s, span)).collect(), - thin_vec![self.expr_str(span, msg)], + 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_unreachable(&self, span: Span) -> P<ast::Expr> { - self.expr_fail(span, Symbol::intern("internal error: entered unreachable code")) - } - pub fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> { let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]); self.expr_call_global(sp, ok, thin_vec![expr]) |
