Skip to content

Commit cbbd3d9

Browse files
committed
Auto merge of #31631 - jonas-schievink:agoraphobia, r=nrc
[breaking-batch] Move more uses of `panictry!` out of libsyntax
2 parents 4b86841 + 11e0ba4 commit cbbd3d9

File tree

12 files changed

+129
-119
lines changed

12 files changed

+129
-119
lines changed

src/librustc_driver/driver.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ use std::fs;
4848
use std::io::{self, Write};
4949
use std::path::{Path, PathBuf};
5050
use syntax::ast::{self, NodeIdAssigner};
51-
use syntax::attr;
52-
use syntax::attr::AttrMetaMethods;
51+
use syntax::attr::{self, AttrMetaMethods};
5352
use syntax::diagnostics;
5453
use syntax::fold::Folder;
55-
use syntax::parse;
56-
use syntax::parse::token;
54+
use syntax::parse::{self, PResult, token};
5755
use syntax::util::node_count::NodeCounter;
5856
use syntax::visit;
5957
use syntax;
@@ -86,7 +84,13 @@ pub fn compile_input(sess: &Session,
8684
// possible to keep the peak memory usage low
8785
let (outputs, trans) = {
8886
let (outputs, expanded_crate, id) = {
89-
let krate = phase_1_parse_input(sess, cfg, input);
87+
let krate = match phase_1_parse_input(sess, cfg, input) {
88+
Ok(krate) => krate,
89+
Err(mut parse_error) => {
90+
parse_error.emit();
91+
return Err(1);
92+
}
93+
};
9094

9195
controller_entry_point!(after_parse,
9296
sess,
@@ -415,17 +419,20 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> {
415419
}
416420
}
417421

418-
pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input) -> ast::Crate {
422+
pub fn phase_1_parse_input<'a>(sess: &'a Session,
423+
cfg: ast::CrateConfig,
424+
input: &Input)
425+
-> PResult<'a, ast::Crate> {
419426
// These may be left in an incoherent state after a previous compile.
420427
// `clear_tables` and `get_ident_interner().clear()` can be used to free
421428
// memory, but they do not restore the initial state.
422429
syntax::ext::mtwt::reset_tables();
423430
token::reset_ident_interner();
424431

425-
let krate = time(sess.time_passes(), "parsing", || {
432+
let krate = try!(time(sess.time_passes(), "parsing", || {
426433
match *input {
427434
Input::File(ref file) => {
428-
parse::parse_crate_from_file(&(*file), cfg.clone(), &sess.parse_sess)
435+
parse::parse_crate_from_file(file, cfg.clone(), &sess.parse_sess)
429436
}
430437
Input::Str(ref src) => {
431438
parse::parse_crate_from_source_str(anon_src().to_string(),
@@ -434,7 +441,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
434441
&sess.parse_sess)
435442
}
436443
}
437-
});
444+
}));
438445

439446
if sess.opts.debugging_opts.ast_json_noexpand {
440447
println!("{}", json::as_json(&krate));
@@ -449,7 +456,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
449456
syntax::show_span::run(sess.diagnostic(), s, &krate);
450457
}
451458

452-
krate
459+
Ok(krate)
453460
}
454461

455462
fn count_nodes(krate: &ast::Crate) -> usize {

src/librustc_driver/lib.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use std::thread;
8989
use rustc::session::{early_error, early_warn};
9090

9191
use syntax::ast;
92-
use syntax::parse;
92+
use syntax::parse::{self, PResult};
9393
use syntax::errors;
9494
use syntax::errors::emitter::Emitter;
9595
use syntax::diagnostics;
@@ -531,7 +531,19 @@ impl RustcDefaultCalls {
531531
return Compilation::Continue;
532532
}
533533

534-
let attrs = input.map(|input| parse_crate_attrs(sess, input));
534+
let attrs = match input {
535+
None => None,
536+
Some(input) => {
537+
let result = parse_crate_attrs(sess, input);
538+
match result {
539+
Ok(attrs) => Some(attrs),
540+
Err(mut parse_error) => {
541+
parse_error.emit();
542+
return Compilation::Stop;
543+
}
544+
}
545+
}
546+
};
535547
for req in &sess.opts.prints {
536548
match *req {
537549
PrintRequest::TargetList => {
@@ -977,8 +989,8 @@ pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
977989
Some(matches)
978990
}
979991

980-
fn parse_crate_attrs(sess: &Session, input: &Input) -> Vec<ast::Attribute> {
981-
let result = match *input {
992+
fn parse_crate_attrs<'a>(sess: &'a Session, input: &Input) -> PResult<'a, Vec<ast::Attribute>> {
993+
match *input {
982994
Input::File(ref ifile) => {
983995
parse::parse_crate_attrs_from_file(ifile, Vec::new(), &sess.parse_sess)
984996
}
@@ -988,8 +1000,7 @@ fn parse_crate_attrs(sess: &Session, input: &Input) -> Vec<ast::Attribute> {
9881000
Vec::new(),
9891001
&sess.parse_sess)
9901002
}
991-
};
992-
result.into_iter().collect()
1003+
}
9931004
}
9941005

9951006
/// Run a procedure which will detect panics in the compiler and print nicer

src/librustc_driver/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ pub fn pretty_print_input(sess: Session,
686686
ppm: PpMode,
687687
opt_uii: Option<UserIdentifiedItem>,
688688
ofile: Option<PathBuf>) {
689-
let krate = driver::phase_1_parse_input(&sess, cfg, input);
689+
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, input));
690690

691691
let krate = if let PpmSource(PpmEveryBodyLoops) = ppm {
692692
let mut fold = ReplaceBodyWithLoop::new();

src/librustc_driver/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn test_env<F>(source_string: &str,
114114
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
115115
let krate_config = Vec::new();
116116
let input = config::Input::Str(source_string.to_string());
117-
let krate = driver::phase_1_parse_input(&sess, krate_config, &input);
117+
let krate = driver::phase_1_parse_input(&sess, krate_config, &input).unwrap();
118118
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate, "test", None)
119119
.expect("phase 2 aborted");
120120

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
133133
let mut cfg = config::build_configuration(&sess);
134134
target_features::add_configuration(&mut cfg, &sess);
135135

136-
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
136+
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
137137

138138
let name = link::find_crate_name(Some(&sess), &krate.attrs,
139139
&input);

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern crate rustc_back;
4343
extern crate rustc_front;
4444
extern crate rustc_metadata;
4545
extern crate serialize;
46-
extern crate syntax;
46+
#[macro_use] extern crate syntax;
4747
extern crate test as testing;
4848
extern crate rustc_unicode;
4949
#[macro_use] extern crate log;

src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn run(input: &str,
9191

9292
let mut cfg = config::build_configuration(&sess);
9393
cfg.extend(config::parse_cfgspecs(cfgs.clone()));
94-
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
94+
let krate = panictry!(driver::phase_1_parse_input(&sess, cfg, &input));
9595
let krate = driver::phase_2_configure_and_expand(&sess, &cstore, krate,
9696
"rustdoc-test", None)
9797
.expect("phase_2_configure_and_expand aborted in rustdoc!");

src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ pub struct WhereEqPredicate {
458458

459459
/// The set of MetaItems that define the compilation environment of the crate,
460460
/// used to drive conditional compilation
461-
pub type CrateConfig = Vec<P<MetaItem>> ;
461+
pub type CrateConfig = Vec<P<MetaItem>>;
462462

463463
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
464464
pub struct Crate {

src/libsyntax/ext/expand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ mod tests {
15191519
let crate_ast = parse::parse_crate_from_source_str(
15201520
"<test>".to_string(),
15211521
src,
1522-
Vec::new(), &sess);
1522+
Vec::new(), &sess).unwrap();
15231523
// should fail:
15241524
let mut gated_cfgs = vec![];
15251525
let ecx = ExtCtxt::new(&sess, vec![], test_ecfg(), &mut gated_cfgs);
@@ -1535,7 +1535,7 @@ mod tests {
15351535
let crate_ast = parse::parse_crate_from_source_str(
15361536
"<test>".to_string(),
15371537
src,
1538-
Vec::new(), &sess);
1538+
Vec::new(), &sess).unwrap();
15391539
let mut gated_cfgs = vec![];
15401540
let ecx = ExtCtxt::new(&sess, vec![], test_ecfg(), &mut gated_cfgs);
15411541
expand_crate(ecx, vec![], vec![], crate_ast);
@@ -1549,7 +1549,7 @@ mod tests {
15491549
let crate_ast = parse::parse_crate_from_source_str(
15501550
"<test>".to_string(),
15511551
src,
1552-
Vec::new(), &sess);
1552+
Vec::new(), &sess).unwrap();
15531553
let mut gated_cfgs = vec![];
15541554
let ecx = ExtCtxt::new(&sess, vec![], test_ecfg(), &mut gated_cfgs);
15551555
expand_crate(ecx, vec![], vec![], crate_ast);

src/libsyntax/ext/quote.rs

+22-20
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ use parse::token::*;
1818
use parse::token;
1919
use ptr::P;
2020

21-
/// Quasiquoting works via token trees.
21+
/// Quasiquoting works via token trees.
2222
///
23-
/// This is registered as a set of expression syntax extension called quote!
24-
/// that lifts its argument token-tree to an AST representing the
25-
/// construction of the same token tree, with token::SubstNt interpreted
26-
/// as antiquotes (splices).
23+
/// This is registered as a set of expression syntax extension called quote!
24+
/// that lifts its argument token-tree to an AST representing the
25+
/// construction of the same token tree, with token::SubstNt interpreted
26+
/// as antiquotes (splices).
2727
2828
pub mod rt {
2929
use ast;
@@ -319,34 +319,36 @@ pub mod rt {
319319
}
320320

321321
impl<'a> ExtParseUtils for ExtCtxt<'a> {
322-
323322
fn parse_item(&self, s: String) -> P<ast::Item> {
324-
parse::parse_item_from_source_str(
323+
panictry!(parse::parse_item_from_source_str(
325324
"<quote expansion>".to_string(),
326325
s,
327326
self.cfg(),
328-
self.parse_sess()).expect("parse error")
327+
self.parse_sess())).expect("parse error")
329328
}
330329

331330
fn parse_stmt(&self, s: String) -> ast::Stmt {
332-
parse::parse_stmt_from_source_str("<quote expansion>".to_string(),
333-
s,
334-
self.cfg(),
335-
self.parse_sess()).expect("parse error")
331+
panictry!(parse::parse_stmt_from_source_str(
332+
"<quote expansion>".to_string(),
333+
s,
334+
self.cfg(),
335+
self.parse_sess())).expect("parse error")
336336
}
337337

338338
fn parse_expr(&self, s: String) -> P<ast::Expr> {
339-
parse::parse_expr_from_source_str("<quote expansion>".to_string(),
340-
s,
341-
self.cfg(),
342-
self.parse_sess())
339+
panictry!(parse::parse_expr_from_source_str(
340+
"<quote expansion>".to_string(),
341+
s,
342+
self.cfg(),
343+
self.parse_sess()))
343344
}
344345

345346
fn parse_tts(&self, s: String) -> Vec<TokenTree> {
346-
parse::parse_tts_from_source_str("<quote expansion>".to_string(),
347-
s,
348-
self.cfg(),
349-
self.parse_sess())
347+
panictry!(parse::parse_tts_from_source_str(
348+
"<quote expansion>".to_string(),
349+
s,
350+
self.cfg(),
351+
self.parse_sess()))
350352
}
351353
}
352354
}

0 commit comments

Comments
 (0)