Eliminate panics and enable the missing panics docs check

This commit is contained in:
David Aguilar 2024-03-17 02:56:21 -07:00 committed by Ethiraric
parent a42f26b306
commit 9e505d552f
4 changed files with 18 additions and 8 deletions

View file

@ -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

View file

@ -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;

View file

@ -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()?;

View file

@ -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;