Auto merge of #23857 - phildawes:libsyntax_nopanic, r=nikomatsakis
Hello! I've been working towards a libsyntax without panics. See: http://internals.rust-lang.org/t/changing-libsyntax-to-use-result-instead-of-panic/1670 This patch changes the internals of parser.rs to use Result<> rather than panicing. It keeps the following old-style panicing functions as a facade: parse_expr, parse_item, parse_pat, parse_arm, parse_ty, parse_stmt I left these functions because I wasn't sure what to do about the quote_* macros or how many syntax-extensions would break if these and quoting macros returned Result. The gyst of the rest of the patch is: - Functions in parse/parser.rs return PResult<> rather than panicing - Other functions in libsyntax call panic! explicitly if they rely on panicing behaviour. - I added a macro 'panictry!()' to act as scaffolding for callers while converting panicing functions. (This does the same as 'unwrap()' but is easier to grep for and turn into try!()). Am I on the right track? I'd quite like to get something merged soon as keeping this rebased in the face of libsyntax changes is a lot of work. Please let me know what changes you'd like to see to make this happen. Thanks!, Phil
This commit is contained in:
commit
b49a5ef003
23 changed files with 1397 additions and 1318 deletions
|
|
@ -528,7 +528,10 @@ impl<'a> CrateReader<'a> {
|
|||
source_name.clone(),
|
||||
body);
|
||||
let lo = p.span.lo;
|
||||
let body = p.parse_all_token_trees();
|
||||
let body = match p.parse_all_token_trees() {
|
||||
Ok(body) => body,
|
||||
Err(err) => panic!(err),
|
||||
};
|
||||
let span = mk_sp(lo, p.last_span.hi);
|
||||
p.abort_if_errors();
|
||||
macros.push(ast::MacroDef {
|
||||
|
|
|
|||
|
|
@ -68,13 +68,13 @@ impl Session {
|
|||
if self.opts.treat_err_as_bug {
|
||||
self.span_bug(sp, msg);
|
||||
}
|
||||
self.diagnostic().span_fatal(sp, msg)
|
||||
panic!(self.diagnostic().span_fatal(sp, msg))
|
||||
}
|
||||
pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> ! {
|
||||
if self.opts.treat_err_as_bug {
|
||||
self.span_bug(sp, msg);
|
||||
}
|
||||
self.diagnostic().span_fatal_with_code(sp, msg, code)
|
||||
panic!(self.diagnostic().span_fatal_with_code(sp, msg, code))
|
||||
}
|
||||
pub fn fatal(&self, msg: &str) -> ! {
|
||||
if self.opts.treat_err_as_bug {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue