Skip to content

Commit e8d02fe

Browse files
committed
Make top-level rustc_parse functions fallible.
Currently we have an awkward mix of fallible and infallible functions: ``` new_parser_from_source_str maybe_new_parser_from_source_str new_parser_from_file (maybe_new_parser_from_file) // missing (new_parser_from_source_file) // missing maybe_new_parser_from_source_file source_str_to_stream maybe_source_file_to_stream ``` We could add the two missing functions, but instead this commit removes of all the infallible ones and renames the fallible ones leaving us with these which are all fallible: ``` new_parser_from_source_str new_parser_from_file new_parser_from_source_file source_str_to_stream source_file_to_stream ``` This requires making `unwrap_or_emit_fatal` public so callers of formerly infallible functions can still work. This does make some of the call sites slightly more verbose, but I think it's worth it for the simpler API. Also, there are two `catch_unwind` calls and one `catch_fatal_errors` call in this diff that become removable thanks this change. (I will do that in a follow-up PR.)
1 parent 9f4a2dd commit e8d02fe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clippy_lints/src/doc/needless_doctest_main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::sync::Lrc;
88
use rustc_errors::emitter::HumanEmitter;
99
use rustc_errors::{Diag, DiagCtxt};
1010
use rustc_lint::LateContext;
11-
use rustc_parse::maybe_new_parser_from_source_str;
11+
use rustc_parse::new_parser_from_source_str;
1212
use rustc_parse::parser::ForceCollect;
1313
use rustc_session::parse::ParseSess;
1414
use rustc_span::edition::Edition;
@@ -50,7 +50,7 @@ pub fn check(
5050
let sm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
5151
let psess = ParseSess::with_dcx(dcx, sm);
5252

53-
let mut parser = match maybe_new_parser_from_source_str(&psess, filename, code) {
53+
let mut parser = match new_parser_from_source_str(&psess, filename, code) {
5454
Ok(p) => p,
5555
Err(errs) => {
5656
errs.into_iter().for_each(Diag::cancel);

0 commit comments

Comments
 (0)