From 4ac592516f0627778ac4aaee52acd7d7591e5cb3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 20 Dec 2018 02:33:56 +0300 Subject: Get rid of `Block::recovered` --- src/libsyntax/parse/parser.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e6f0d871222..d68a6546f48 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -32,6 +32,7 @@ use ast::{UseTree, UseTreeKind}; use ast::{BinOpKind, UnOp}; use ast::{RangeEnd, RangeSyntax}; use {ast, attr}; +use ext::base::DummyResult; use source_map::{self, SourceMap, Spanned, respan}; use syntax_pos::{self, Span, MultiSpan, BytePos, FileName}; use errors::{self, Applicability, DiagnosticBuilder, DiagnosticId}; @@ -4966,16 +4967,16 @@ impl<'a> Parser<'a> { /// Precondition: already parsed the '{'. fn parse_block_tail(&mut self, lo: Span, s: BlockCheckMode) -> PResult<'a, P> { let mut stmts = vec![]; - let mut recovered = false; - while !self.eat(&token::CloseDelim(token::Brace)) { let stmt = match self.parse_full_stmt(false) { Err(mut err) => { err.emit(); self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore); - self.eat(&token::CloseDelim(token::Brace)); - recovered = true; - break; + Some(Stmt { + id: ast::DUMMY_NODE_ID, + node: StmtKind::Expr(DummyResult::raw_expr(self.span)), + span: self.span, + }) } Ok(stmt) => stmt, }; @@ -4993,7 +4994,6 @@ impl<'a> Parser<'a> { id: ast::DUMMY_NODE_ID, rules: s, span: lo.to(self.prev_span), - recovered, })) } -- cgit 1.4.1-3-g733a5 From b99fb2f5445fa5a791cca7601c7d609aaf708304 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 20 Dec 2018 03:57:48 +0300 Subject: Fix `trace_macros` and `log_syntax` --- src/libsyntax/ext/base.rs | 30 ++++++++++++++++++------------ src/libsyntax/parse/parser.rs | 2 +- src/libsyntax_ext/deriving/default.rs | 2 +- src/libsyntax_ext/format.rs | 6 +++--- src/libsyntax_ext/log_syntax.rs | 2 +- src/libsyntax_ext/trace_macros.rs | 2 +- 6 files changed, 25 insertions(+), 19 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 84aa57d7d86..1efe0b3478d 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -456,7 +456,8 @@ impl MacResult for MacEager { #[derive(Copy, Clone)] pub struct DummyResult { expr_only: bool, - span: Span + is_error: bool, + span: Span, } impl DummyResult { @@ -464,8 +465,13 @@ impl DummyResult { /// /// Use this as a return value after hitting any errors and /// calling `span_err`. - pub fn any(sp: Span) -> Box { - Box::new(DummyResult { expr_only: false, span: sp }) + pub fn any(span: Span) -> Box { + 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 { + Box::new(DummyResult { expr_only: false, is_error: false, span }) } /// 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 /// if an error is encountered internally, the user will receive /// an error that they also used it in the wrong place. - pub fn expr(sp: Span) -> Box { - Box::new(DummyResult { expr_only: true, span: sp }) + pub fn expr(span: Span) -> Box { + Box::new(DummyResult { expr_only: true, is_error: true, span }) } /// A plain dummy expression. - pub fn raw_expr(sp: Span) -> P { + pub fn raw_expr(sp: Span, is_error: bool) -> P { P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprKind::Err, + node: if is_error { ast::ExprKind::Err } else { ast::ExprKind::Tup(Vec::new()) }, span: sp, attrs: ThinVec::new(), }) @@ -497,10 +503,10 @@ impl DummyResult { } /// A plain dummy type. - pub fn raw_ty(sp: Span) -> P { + pub fn raw_ty(sp: Span, is_error: bool) -> P { P(ast::Ty { id: ast::DUMMY_NODE_ID, - node: ast::TyKind::Err, + node: if is_error { ast::TyKind::Err } else { ast::TyKind::Tup(Vec::new()) }, span: sp }) } @@ -508,7 +514,7 @@ impl DummyResult { impl MacResult for DummyResult { fn make_expr(self: Box) -> Option> { - Some(DummyResult::raw_expr(self.span)) + Some(DummyResult::raw_expr(self.span, self.is_error)) } fn make_pat(self: Box) -> Option> { @@ -551,13 +557,13 @@ impl MacResult for DummyResult { fn make_stmts(self: Box) -> Option> { Some(smallvec![ast::Stmt { 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, }]) } fn make_ty(self: Box) -> Option> { - Some(DummyResult::raw_ty(self.span)) + Some(DummyResult::raw_ty(self.span, self.is_error)) } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d68a6546f48..11d570072cd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4974,7 +4974,7 @@ impl<'a> Parser<'a> { self.recover_stmt_(SemiColonMode::Ignore, BlockMode::Ignore); Some(Stmt { 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, }) } diff --git a/src/libsyntax_ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs index 771a559b37c..32d02bec798 100644 --- a/src/libsyntax_ext/deriving/default.rs +++ b/src/libsyntax_ext/deriving/default.rs @@ -69,7 +69,7 @@ fn default_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructur span_err!(cx, trait_span, E0665, "`Default` cannot be derived for enums, only structs"); // 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)`"), }; diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index c6f427e63cd..10516503480 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -666,7 +666,7 @@ impl<'a, 'b> Context<'a, 'b> { "X" => "UpperHex", _ => { 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, ); 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.emit(); - return DummyResult::raw_expr(sp); + return DummyResult::raw_expr(sp, true); } let arg_spans = parser.arg_places.iter() diff --git a/src/libsyntax_ext/log_syntax.rs b/src/libsyntax_ext/log_syntax.rs index 5f24ed81cdd..f6bb1285c53 100644 --- a/src/libsyntax_ext/log_syntax.rs +++ b/src/libsyntax_ext/log_syntax.rs @@ -20,5 +20,5 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt, println!("{}", print::pprust::tts_to_string(tts)); // any so that `log_syntax` can be invoked as an expression and item. - base::DummyResult::any(sp) + base::DummyResult::any_valid(sp) } diff --git a/src/libsyntax_ext/trace_macros.rs b/src/libsyntax_ext/trace_macros.rs index f17c6de19d9..b20da5af09a 100644 --- a/src/libsyntax_ext/trace_macros.rs +++ b/src/libsyntax_ext/trace_macros.rs @@ -28,5 +28,5 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt, _ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"), } - base::DummyResult::any(sp) + base::DummyResult::any_valid(sp) } -- cgit 1.4.1-3-g733a5 From 37af04ff8d784969882296c0fb74aa3e68624873 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 21 Dec 2018 02:58:55 +0300 Subject: Address review comments and CI failures --- src/librustc_resolve/macros.rs | 2 +- src/libsyntax/parse/parser.rs | 1 + src/test/compile-fail/auxiliary/depends.rs | 8 ++++++++ src/test/compile-fail/auxiliary/needs-panic-runtime.rs | 6 ++++++ src/test/compile-fail/runtime-depend-on-needs-runtime.rs | 7 +++++++ src/test/compile-fail/runtime-depend-on-needs-runtime.stderr | 4 ++++ src/test/ui/issues/issue-6596-1.rs | 1 - src/test/ui/issues/issue-6596-1.stderr | 12 +----------- src/test/ui/issues/issue-6596-2.rs | 1 - src/test/ui/issues/issue-6596-2.stderr | 12 +----------- src/test/ui/macros/macro-comma-behavior.core.stderr | 5 +---- src/test/ui/macros/macro-comma-behavior.rs | 2 ++ src/test/ui/macros/macro-comma-behavior.std.stderr | 1 - src/test/ui/panic-runtime/auxiliary/depends.rs | 8 -------- src/test/ui/panic-runtime/auxiliary/needs-panic-runtime.rs | 6 ------ src/test/ui/panic-runtime/runtime-depend-on-needs-runtime.rs | 7 ------- .../ui/panic-runtime/runtime-depend-on-needs-runtime.stderr | 4 ---- 17 files changed, 32 insertions(+), 55 deletions(-) create mode 100644 src/test/compile-fail/auxiliary/depends.rs create mode 100644 src/test/compile-fail/auxiliary/needs-panic-runtime.rs create mode 100644 src/test/compile-fail/runtime-depend-on-needs-runtime.rs create mode 100644 src/test/compile-fail/runtime-depend-on-needs-runtime.stderr delete mode 100644 src/test/ui/panic-runtime/auxiliary/depends.rs delete mode 100644 src/test/ui/panic-runtime/auxiliary/needs-panic-runtime.rs delete mode 100644 src/test/ui/panic-runtime/runtime-depend-on-needs-runtime.rs delete mode 100644 src/test/ui/panic-runtime/runtime-depend-on-needs-runtime.stderr (limited to 'src/libsyntax/parse') diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 9c0c8a6016f..182dcfe4098 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -186,7 +186,7 @@ impl<'a> base::Resolver for Resolver<'a> { Ok((def, ext)) => (def, ext), Err(Determinacy::Determined) if kind == MacroKind::Attr => { // Replace unresolved attributes with used inert attributes for better recovery. - return Ok(Some(self.get_macro(Def::NonMacroAttr(NonMacroAttrKind::Tool)))); + return Ok(Some(Lrc::new(SyntaxExtension::NonMacroAttr { mark_used: true }))); } Err(determinacy) => return Err(determinacy), }; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 11d570072cd..52da8a072c7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2871,6 +2871,7 @@ impl<'a> Parser<'a> { let mut err = self.fatal(&format!("unknown macro variable `{}`", name)); err.span_label(self.span, "unknown macro variable"); err.emit(); + self.bump(); return } token::Interpolated(ref nt) => { diff --git a/src/test/compile-fail/auxiliary/depends.rs b/src/test/compile-fail/auxiliary/depends.rs new file mode 100644 index 00000000000..e9bc2f4893e --- /dev/null +++ b/src/test/compile-fail/auxiliary/depends.rs @@ -0,0 +1,8 @@ +// no-prefer-dynamic + +#![feature(panic_runtime)] +#![crate_type = "rlib"] +#![panic_runtime] +#![no_std] + +extern crate needs_panic_runtime; diff --git a/src/test/compile-fail/auxiliary/needs-panic-runtime.rs b/src/test/compile-fail/auxiliary/needs-panic-runtime.rs new file mode 100644 index 00000000000..3f030c169f6 --- /dev/null +++ b/src/test/compile-fail/auxiliary/needs-panic-runtime.rs @@ -0,0 +1,6 @@ +// no-prefer-dynamic + +#![feature(needs_panic_runtime)] +#![crate_type = "rlib"] +#![needs_panic_runtime] +#![no_std] diff --git a/src/test/compile-fail/runtime-depend-on-needs-runtime.rs b/src/test/compile-fail/runtime-depend-on-needs-runtime.rs new file mode 100644 index 00000000000..866c5b2e34b --- /dev/null +++ b/src/test/compile-fail/runtime-depend-on-needs-runtime.rs @@ -0,0 +1,7 @@ +// aux-build:needs-panic-runtime.rs +// aux-build:depends.rs +// error-pattern:cannot depend on a crate that needs a panic runtime + +extern crate depends; + +fn main() {} diff --git a/src/test/compile-fail/runtime-depend-on-needs-runtime.stderr b/src/test/compile-fail/runtime-depend-on-needs-runtime.stderr new file mode 100644 index 00000000000..27e27dda5ef --- /dev/null +++ b/src/test/compile-fail/runtime-depend-on-needs-runtime.stderr @@ -0,0 +1,4 @@ +error: the crate `depends` cannot depend on a crate that needs a panic runtime, but it depends on `needs_panic_runtime` + +error: aborting due to previous error + diff --git a/src/test/ui/issues/issue-6596-1.rs b/src/test/ui/issues/issue-6596-1.rs index 6a5986c355e..5da54451346 100644 --- a/src/test/ui/issues/issue-6596-1.rs +++ b/src/test/ui/issues/issue-6596-1.rs @@ -2,7 +2,6 @@ macro_rules! e { ($inp:ident) => ( $nonexistent //~^ ERROR unknown macro variable `nonexistent` - //~| ERROR cannot find value `nonexistent` in this scope ); } diff --git a/src/test/ui/issues/issue-6596-1.stderr b/src/test/ui/issues/issue-6596-1.stderr index face8725914..2a4ece2f242 100644 --- a/src/test/ui/issues/issue-6596-1.stderr +++ b/src/test/ui/issues/issue-6596-1.stderr @@ -7,15 +7,5 @@ LL | $nonexistent LL | e!(foo); | -------- in this macro invocation -error[E0425]: cannot find value `nonexistent` in this scope - --> $DIR/issue-6596-1.rs:14:9 - | -LL | $nonexistent - | ^^^^^^^^^^^^ not found in this scope -... -LL | e!(foo); - | -------- in this macro invocation - -error: aborting due to 2 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/issues/issue-6596-2.rs b/src/test/ui/issues/issue-6596-2.rs index 4ff7cfe3865..b19700efe5a 100644 --- a/src/test/ui/issues/issue-6596-2.rs +++ b/src/test/ui/issues/issue-6596-2.rs @@ -4,7 +4,6 @@ macro_rules! g { ($inp:ident) => ( { $inp $nonexistent } //~^ ERROR unknown macro variable `nonexistent` - //~| ERROR expected one of ); } diff --git a/src/test/ui/issues/issue-6596-2.stderr b/src/test/ui/issues/issue-6596-2.stderr index 99decd177ef..3e707ba6fff 100644 --- a/src/test/ui/issues/issue-6596-2.stderr +++ b/src/test/ui/issues/issue-6596-2.stderr @@ -7,14 +7,4 @@ LL | { $inp $nonexistent } LL | g!(foo); | -------- in this macro invocation -error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `nonexistent` - --> $DIR/issue-6596-2.rs:5:16 - | -LL | { $inp $nonexistent } - | ^^^^^^^^^^^^ expected one of 8 possible tokens here -... -LL | g!(foo); - | -------- in this macro invocation - -error: aborting due to 2 previous errors - +error: aborting due to previous error diff --git a/src/test/ui/macros/macro-comma-behavior.core.stderr b/src/test/ui/macros/macro-comma-behavior.core.stderr index 7a4b9278e0a..cd752352aef 100644 --- a/src/test/ui/macros/macro-comma-behavior.core.stderr +++ b/src/test/ui/macros/macro-comma-behavior.core.stderr @@ -44,7 +44,4 @@ error: `#[panic_handler]` function required, but not found error: language item required, but not found: `eh_personality` -error: language item required, but not found: `eh_unwind_resume` - -error: aborting due to 10 previous errors - +error: aborting due to 9 previous errors diff --git a/src/test/ui/macros/macro-comma-behavior.rs b/src/test/ui/macros/macro-comma-behavior.rs index 7bd4cb0d2e7..46b93edca3a 100644 --- a/src/test/ui/macros/macro-comma-behavior.rs +++ b/src/test/ui/macros/macro-comma-behavior.rs @@ -3,10 +3,12 @@ // compile-flags: -C debug_assertions=yes // revisions: std core +#![feature(lang_items)] #![cfg_attr(core, no_std)] #[cfg(std)] use std::fmt; #[cfg(core)] use core::fmt; +#[cfg(core)] #[lang = "eh_unwind_resume"] fn eh_unwind_resume() {} // (see documentation of the similarly-named test in run-pass) fn to_format_or_not_to_format() { diff --git a/src/test/ui/macros/macro-comma-behavior.std.stderr b/src/test/ui/macros/macro-comma-behavior.std.stderr index 8759d4efae6..e56ed40e024 100644 --- a/src/test/ui/macros/macro-comma-behavior.std.stderr +++ b/src/test/ui/macros/macro-comma-behavior.std.stderr @@ -59,4 +59,3 @@ LL | write!(f, "{}",)?; | ^^ error: aborting due to 10 previous errors - diff --git a/src/test/ui/panic-runtime/auxiliary/depends.rs b/src/test/ui/panic-runtime/auxiliary/depends.rs deleted file mode 100644 index e9bc2f4893e..00000000000 --- a/src/test/ui/panic-runtime/auxiliary/depends.rs +++ /dev/null @@ -1,8 +0,0 @@ -// no-prefer-dynamic - -#![feature(panic_runtime)] -#![crate_type = "rlib"] -#![panic_runtime] -#![no_std] - -extern crate needs_panic_runtime; diff --git a/src/test/ui/panic-runtime/auxiliary/needs-panic-runtime.rs b/src/test/ui/panic-runtime/auxiliary/needs-panic-runtime.rs deleted file mode 100644 index 3f030c169f6..00000000000 --- a/src/test/ui/panic-runtime/auxiliary/needs-panic-runtime.rs +++ /dev/null @@ -1,6 +0,0 @@ -// no-prefer-dynamic - -#![feature(needs_panic_runtime)] -#![crate_type = "rlib"] -#![needs_panic_runtime] -#![no_std] diff --git a/src/test/ui/panic-runtime/runtime-depend-on-needs-runtime.rs b/src/test/ui/panic-runtime/runtime-depend-on-needs-runtime.rs deleted file mode 100644 index 866c5b2e34b..00000000000 --- a/src/test/ui/panic-runtime/runtime-depend-on-needs-runtime.rs +++ /dev/null @@ -1,7 +0,0 @@ -// aux-build:needs-panic-runtime.rs -// aux-build:depends.rs -// error-pattern:cannot depend on a crate that needs a panic runtime - -extern crate depends; - -fn main() {} diff --git a/src/test/ui/panic-runtime/runtime-depend-on-needs-runtime.stderr b/src/test/ui/panic-runtime/runtime-depend-on-needs-runtime.stderr deleted file mode 100644 index 27e27dda5ef..00000000000 --- a/src/test/ui/panic-runtime/runtime-depend-on-needs-runtime.stderr +++ /dev/null @@ -1,4 +0,0 @@ -error: the crate `depends` cannot depend on a crate that needs a panic runtime, but it depends on `needs_panic_runtime` - -error: aborting due to previous error - -- cgit 1.4.1-3-g733a5