Make type_ascribe! not a built-in
This commit is contained in:
parent
e3df96cfda
commit
a015b90953
7 changed files with 28 additions and 44 deletions
|
@ -49,7 +49,6 @@ mod log_syntax;
|
|||
mod source_util;
|
||||
mod test;
|
||||
mod trace_macros;
|
||||
mod type_ascribe;
|
||||
mod util;
|
||||
|
||||
pub mod asm;
|
||||
|
@ -99,7 +98,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
|
|||
std_panic: edition_panic::expand_panic,
|
||||
stringify: source_util::expand_stringify,
|
||||
trace_macros: trace_macros::expand_trace_macros,
|
||||
type_ascribe: type_ascribe::expand_type_ascribe,
|
||||
unreachable: edition_panic::expand_unreachable,
|
||||
// tidy-alphabetical-end
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::tokenstream::TokenStream;
|
||||
use rustc_ast::{token, Expr, ExprKind, Ty};
|
||||
use rustc_errors::PResult;
|
||||
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
|
||||
use rustc_span::Span;
|
||||
|
||||
pub fn expand_type_ascribe(
|
||||
cx: &mut ExtCtxt<'_>,
|
||||
span: Span,
|
||||
tts: TokenStream,
|
||||
) -> MacroExpanderResult<'static> {
|
||||
let (expr, ty) = match parse_ascribe(cx, tts) {
|
||||
Ok(parsed) => parsed,
|
||||
Err(err) => {
|
||||
let guar = err.emit();
|
||||
return ExpandResult::Ready(DummyResult::any(span, guar));
|
||||
}
|
||||
};
|
||||
|
||||
let asc_expr = cx.expr(span, ExprKind::Type(expr, ty));
|
||||
|
||||
ExpandResult::Ready(MacEager::expr(asc_expr))
|
||||
}
|
||||
|
||||
fn parse_ascribe<'a>(cx: &mut ExtCtxt<'a>, stream: TokenStream) -> PResult<'a, (P<Expr>, P<Ty>)> {
|
||||
let mut parser = cx.new_parser_from_tts(stream);
|
||||
|
||||
let expr = parser.parse_expr()?;
|
||||
parser.expect(&token::Comma)?;
|
||||
|
||||
let ty = parser.parse_ty()?;
|
||||
|
||||
Ok((expr, ty))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue