Fix trace_macros
and log_syntax
This commit is contained in:
parent
4ac592516f
commit
b99fb2f544
6 changed files with 25 additions and 19 deletions
|
@ -456,7 +456,8 @@ impl MacResult for MacEager {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct DummyResult {
|
pub struct DummyResult {
|
||||||
expr_only: bool,
|
expr_only: bool,
|
||||||
span: Span
|
is_error: bool,
|
||||||
|
span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DummyResult {
|
impl DummyResult {
|
||||||
|
@ -464,8 +465,13 @@ impl DummyResult {
|
||||||
///
|
///
|
||||||
/// Use this as a return value after hitting any errors and
|
/// Use this as a return value after hitting any errors and
|
||||||
/// calling `span_err`.
|
/// calling `span_err`.
|
||||||
pub fn any(sp: Span) -> Box<dyn MacResult+'static> {
|
pub fn any(span: Span) -> Box<dyn MacResult+'static> {
|
||||||
Box::new(DummyResult { expr_only: false, span: sp })
|
Box::new(DummyResult { expr_only: false, is_error: true, span })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Same as `any`, but must be a valid fragment, not error.
|
||||||
|
pub fn any_valid(span: Span) -> Box<dyn MacResult+'static> {
|
||||||
|
Box::new(DummyResult { expr_only: false, is_error: false, span })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a default MacResult that can only be an expression.
|
/// Create a default MacResult that can only be an expression.
|
||||||
|
@ -473,15 +479,15 @@ impl DummyResult {
|
||||||
/// Use this for macros that must expand to an expression, so even
|
/// Use this for macros that must expand to an expression, so even
|
||||||
/// if an error is encountered internally, the user will receive
|
/// if an error is encountered internally, the user will receive
|
||||||
/// an error that they also used it in the wrong place.
|
/// an error that they also used it in the wrong place.
|
||||||
pub fn expr(sp: Span) -> Box<dyn MacResult+'static> {
|
pub fn expr(span: Span) -> Box<dyn MacResult+'static> {
|
||||||
Box::new(DummyResult { expr_only: true, span: sp })
|
Box::new(DummyResult { expr_only: true, is_error: true, span })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A plain dummy expression.
|
/// A plain dummy expression.
|
||||||
pub fn raw_expr(sp: Span) -> P<ast::Expr> {
|
pub fn raw_expr(sp: Span, is_error: bool) -> P<ast::Expr> {
|
||||||
P(ast::Expr {
|
P(ast::Expr {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: ast::ExprKind::Err,
|
node: if is_error { ast::ExprKind::Err } else { ast::ExprKind::Tup(Vec::new()) },
|
||||||
span: sp,
|
span: sp,
|
||||||
attrs: ThinVec::new(),
|
attrs: ThinVec::new(),
|
||||||
})
|
})
|
||||||
|
@ -497,10 +503,10 @@ impl DummyResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A plain dummy type.
|
/// A plain dummy type.
|
||||||
pub fn raw_ty(sp: Span) -> P<ast::Ty> {
|
pub fn raw_ty(sp: Span, is_error: bool) -> P<ast::Ty> {
|
||||||
P(ast::Ty {
|
P(ast::Ty {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: ast::TyKind::Err,
|
node: if is_error { ast::TyKind::Err } else { ast::TyKind::Tup(Vec::new()) },
|
||||||
span: sp
|
span: sp
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -508,7 +514,7 @@ impl DummyResult {
|
||||||
|
|
||||||
impl MacResult for DummyResult {
|
impl MacResult for DummyResult {
|
||||||
fn make_expr(self: Box<DummyResult>) -> Option<P<ast::Expr>> {
|
fn make_expr(self: Box<DummyResult>) -> Option<P<ast::Expr>> {
|
||||||
Some(DummyResult::raw_expr(self.span))
|
Some(DummyResult::raw_expr(self.span, self.is_error))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_pat(self: Box<DummyResult>) -> Option<P<ast::Pat>> {
|
fn make_pat(self: Box<DummyResult>) -> Option<P<ast::Pat>> {
|
||||||
|
@ -551,13 +557,13 @@ impl MacResult for DummyResult {
|
||||||
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVec<[ast::Stmt; 1]>> {
|
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVec<[ast::Stmt; 1]>> {
|
||||||
Some(smallvec![ast::Stmt {
|
Some(smallvec![ast::Stmt {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span)),
|
node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span, self.is_error)),
|
||||||
span: self.span,
|
span: self.span,
|
||||||
}])
|
}])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> {
|
fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> {
|
||||||
Some(DummyResult::raw_ty(self.span))
|
Some(DummyResult::raw_ty(self.span, self.is_error))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4974,7 +4974,7 @@ impl<'a> Parser<'a> {
|
||||||
self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore);
|
self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore);
|
||||||
Some(Stmt {
|
Some(Stmt {
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
node: StmtKind::Expr(DummyResult::raw_expr(self.span)),
|
node: StmtKind::Expr(DummyResult::raw_expr(self.span, true)),
|
||||||
span: self.span,
|
span: self.span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructur
|
||||||
span_err!(cx, trait_span, E0665,
|
span_err!(cx, trait_span, E0665,
|
||||||
"`Default` cannot be derived for enums, only structs");
|
"`Default` cannot be derived for enums, only structs");
|
||||||
// let compilation continue
|
// let compilation continue
|
||||||
DummyResult::raw_expr(trait_span)
|
DummyResult::raw_expr(trait_span, true)
|
||||||
}
|
}
|
||||||
_ => cx.span_bug(trait_span, "Non-static method in `derive(Default)`"),
|
_ => cx.span_bug(trait_span, "Non-static method in `derive(Default)`"),
|
||||||
};
|
};
|
||||||
|
|
|
@ -666,7 +666,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||||
"X" => "UpperHex",
|
"X" => "UpperHex",
|
||||||
_ => {
|
_ => {
|
||||||
ecx.span_err(sp, &format!("unknown format trait `{}`", *tyname));
|
ecx.span_err(sp, &format!("unknown format trait `{}`", *tyname));
|
||||||
return DummyResult::raw_expr(sp);
|
return DummyResult::raw_expr(sp, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -761,7 +761,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
err.emit();
|
err.emit();
|
||||||
return DummyResult::raw_expr(sp);
|
return DummyResult::raw_expr(sp, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -857,7 +857,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
|
||||||
e.span_label(sp, label);
|
e.span_label(sp, label);
|
||||||
}
|
}
|
||||||
e.emit();
|
e.emit();
|
||||||
return DummyResult::raw_expr(sp);
|
return DummyResult::raw_expr(sp, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
let arg_spans = parser.arg_places.iter()
|
let arg_spans = parser.arg_places.iter()
|
||||||
|
|
|
@ -20,5 +20,5 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt,
|
||||||
println!("{}", print::pprust::tts_to_string(tts));
|
println!("{}", print::pprust::tts_to_string(tts));
|
||||||
|
|
||||||
// any so that `log_syntax` can be invoked as an expression and item.
|
// any so that `log_syntax` can be invoked as an expression and item.
|
||||||
base::DummyResult::any(sp)
|
base::DummyResult::any_valid(sp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,5 +28,5 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt,
|
||||||
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
|
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
|
||||||
}
|
}
|
||||||
|
|
||||||
base::DummyResult::any(sp)
|
base::DummyResult::any_valid(sp)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue