Eliminate panics and enable the missing panics docs check
This commit is contained in:
parent
a42f26b306
commit
9e505d552f
4 changed files with 18 additions and 8 deletions
|
@ -16,6 +16,8 @@
|
|||
- `Yaml::load_from_bytes()` is now available.
|
||||
([#156](https://github.com/chyh1990/yaml-rust/pull/156))
|
||||
|
||||
- The parser and scanner now return Err() instead of calling panic.
|
||||
|
||||
**Development**:
|
||||
|
||||
- The documentation was updated to include a security note mentioning that
|
||||
|
|
|
@ -33,11 +33,7 @@
|
|||
#![cfg_attr(feature = "cargo-clippy", warn(clippy::pedantic))]
|
||||
#![cfg_attr(
|
||||
feature = "cargo-clippy",
|
||||
allow(
|
||||
clippy::should_implement_trait,
|
||||
clippy::missing_errors_doc,
|
||||
clippy::missing_panics_doc,
|
||||
)
|
||||
allow(clippy::should_implement_trait, clippy::missing_errors_doc,)
|
||||
)]
|
||||
|
||||
extern crate hashlink;
|
||||
|
|
|
@ -306,7 +306,9 @@ impl<T: Iterator<Item = char>> Parser<T> {
|
|||
) -> Result<(), ScanError> {
|
||||
if !self.scanner.stream_started() {
|
||||
let (ev, mark) = self.next()?;
|
||||
assert_eq!(ev, Event::StreamStart);
|
||||
if ev != Event::StreamStart {
|
||||
return Err(ScanError::new(mark, "did not find expected <stream-start>"));
|
||||
}
|
||||
recv.on_event(ev, mark);
|
||||
}
|
||||
|
||||
|
@ -337,7 +339,12 @@ impl<T: Iterator<Item = char>> Parser<T> {
|
|||
mark: Marker,
|
||||
recv: &mut R,
|
||||
) -> Result<(), ScanError> {
|
||||
assert_eq!(first_ev, Event::DocumentStart);
|
||||
if first_ev != Event::DocumentStart {
|
||||
return Err(ScanError::new(
|
||||
mark,
|
||||
"did not find expected <document-start>",
|
||||
));
|
||||
}
|
||||
recv.on_event(first_ev, mark);
|
||||
|
||||
let (ev, mark) = self.next()?;
|
||||
|
|
|
@ -716,7 +716,12 @@ impl<T: Iterator<Item = char>> Scanner<T> {
|
|||
if !self.token_available {
|
||||
self.fetch_more_tokens()?;
|
||||
}
|
||||
let t = self.tokens.pop_front().unwrap();
|
||||
let Some(t) = self.tokens.pop_front() else {
|
||||
return Err(ScanError::new(
|
||||
self.mark,
|
||||
"did not find expected next token",
|
||||
));
|
||||
};
|
||||
self.token_available = false;
|
||||
self.tokens_parsed += 1;
|
||||
|
||||
|
|
Loading…
Reference in a new issue