Skip to content

Commit

Permalink
When parsing a source string, fail when the entire string is not parsed.
Browse files Browse the repository at this point in the history
(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.)
  • Loading branch information
kevina committed Feb 11, 2012
1 parent 48eda22 commit 5487590
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/comp/syntax/parse/parser.rs
Expand Up @@ -2622,6 +2622,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;
Expand Down
File renamed without changes.
48 changes: 48 additions & 0 deletions src/test/compile-fail/qquote-2.rs
@@ -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;
}

0 comments on commit 5487590

Please sign in to comment.