When parsing a source string, fail when the entire string is not parsed.
(For now only fail when parse_from_source_str is used to avoid possible compatibility problems; parse_expr_from_source_str still does not check.)
This commit is contained in:
parent
a803a14b56
commit
d6d7134c37
@ -2633,6 +2633,9 @@ fn parse_from_source_str<T>(f: fn (p: parser) -> T,
|
||||
{
|
||||
let p = new_parser_from_source_str(sess, cfg, name, ss, source);
|
||||
let r = f(p);
|
||||
if !p.reader.is_eof() {
|
||||
p.reader.fatal("expected end-of-string");
|
||||
}
|
||||
sess.chpos = p.reader.chpos;
|
||||
sess.byte_pos = sess.byte_pos + p.reader.pos;
|
||||
ret r;
|
||||
|
48
src/test/compile-fail/qquote-2.rs
Normal file
48
src/test/compile-fail/qquote-2.rs
Normal file
@ -0,0 +1,48 @@
|
||||
// xfail-pretty
|
||||
|
||||
use std;
|
||||
use rustc;
|
||||
|
||||
import rustc::*;
|
||||
import std::io::*;
|
||||
|
||||
import rustc::driver::diagnostic;
|
||||
import rustc::syntax::ast;
|
||||
import rustc::syntax::codemap;
|
||||
import rustc::syntax::parse::parser;
|
||||
import rustc::syntax::print::*;
|
||||
|
||||
fn new_parse_sess() -> parser::parse_sess {
|
||||
fail;
|
||||
}
|
||||
|
||||
iface fake_ext_ctxt {
|
||||
fn session() -> fake_session;
|
||||
}
|
||||
|
||||
type fake_options = {cfg: ast::crate_cfg};
|
||||
|
||||
type fake_session = {opts: @fake_options,
|
||||
parse_sess: parser::parse_sess};
|
||||
|
||||
impl of fake_ext_ctxt for fake_session {
|
||||
fn session() -> fake_session {self}
|
||||
}
|
||||
|
||||
fn mk_ctxt() -> fake_ext_ctxt {
|
||||
let opts : fake_options = {cfg: []};
|
||||
{opts: @opts, parse_sess: new_parse_sess()} as fake_ext_ctxt
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let ext_cx = mk_ctxt();
|
||||
|
||||
let stmt = #ast(stmt){let x int = 20;}; //! ERROR expected end-of-string
|
||||
check_pp(*stmt, pprust::print_stmt, "");
|
||||
}
|
||||
|
||||
fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: str) {
|
||||
fail;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user