diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fc62cee92fdbc..777cce43abecc 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2440,6 +2440,13 @@ impl<'a> Parser<'a> { err.cancel(); let msg = format!("expected expression, found {}", self.this_token_descr()); + if self.token == token::Token::Eof { + let help = format!("{} in this context refers \ + to the end of the macro invocation", + self.this_token_descr()); + return Err(self.span_fatal_help( + self.span, &msg, &help)); + } return Err(self.fatal(&msg)); } } diff --git a/src/test/parse-fail/macro-eof-message.rs b/src/test/parse-fail/macro-eof-message.rs new file mode 100644 index 0000000000000..c648bcb626294 --- /dev/null +++ b/src/test/parse-fail/macro-eof-message.rs @@ -0,0 +1,16 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +fn main() { + let message = "test"; + println!("{}", message/); //~ ERROR expected expression, found `` + //~^ HELP `` in this context refers to the end of the macro invocation +}