clippy fix
This commit is contained in:
parent
1354d931b2
commit
7c29e44f20
5 changed files with 43 additions and 29 deletions
14
src/file.rs
14
src/file.rs
|
@ -169,6 +169,7 @@ impl<'event> MutableMultiValue<'_, '_, 'event> {
|
|||
|
||||
/// Returns the size of values the multivar has.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn len(&self) -> usize {
|
||||
self.indices_and_sizes.len()
|
||||
}
|
||||
|
@ -176,6 +177,7 @@ impl<'event> MutableMultiValue<'_, '_, 'event> {
|
|||
/// Returns if the multivar has any values. This might occur if the value
|
||||
/// was deleted but not set with a new value.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.indices_and_sizes.is_empty()
|
||||
}
|
||||
|
@ -1131,8 +1133,8 @@ impl Display for GitConfig<'_> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod from_parser {
|
||||
use super::*;
|
||||
use crate::test_util::*;
|
||||
use super::{Cow, Event, GitConfig, HashMap, LookupTreeNode, SectionId, TryFrom};
|
||||
use crate::test_util::{name_event, newline_event, section_header, value_event};
|
||||
|
||||
#[test]
|
||||
fn parse_empty() {
|
||||
|
@ -1331,7 +1333,7 @@ mod from_parser {
|
|||
|
||||
#[cfg(test)]
|
||||
mod get_raw_value {
|
||||
use super::*;
|
||||
use super::{Cow, GitConfig, GitConfigError, TryFrom};
|
||||
|
||||
#[test]
|
||||
fn single_section() {
|
||||
|
@ -1407,7 +1409,7 @@ mod get_raw_value {
|
|||
|
||||
#[cfg(test)]
|
||||
mod get_value {
|
||||
use super::*;
|
||||
use super::{Cow, GitConfig, TryFrom};
|
||||
use crate::values::{Boolean, TrueVariant, Value};
|
||||
use std::error::Error;
|
||||
|
||||
|
@ -1426,7 +1428,7 @@ mod get_value {
|
|||
|
||||
#[cfg(test)]
|
||||
mod get_raw_multi_value {
|
||||
use super::*;
|
||||
use super::{Cow, GitConfig, GitConfigError, TryFrom};
|
||||
|
||||
#[test]
|
||||
fn single_value_is_identical_to_single_value_query() {
|
||||
|
@ -1515,7 +1517,7 @@ mod get_raw_multi_value {
|
|||
|
||||
#[cfg(test)]
|
||||
mod display {
|
||||
use super::*;
|
||||
use super::{GitConfig, TryFrom};
|
||||
|
||||
#[test]
|
||||
fn can_reconstruct_empty_config() {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
#![forbid(unsafe_code)]
|
||||
// #![deny(missing_docs)]
|
||||
#![warn(clippy::pedantic, clippy::nursery, clippy::cargo)]
|
||||
#![allow(
|
||||
// clippy::must_use_candidate,
|
||||
clippy::shadow_unrelated)]
|
||||
#![allow(clippy::shadow_unrelated)]
|
||||
|
||||
//! # `git_config`
|
||||
//!
|
||||
|
|
|
@ -69,6 +69,7 @@ pub enum Event<'a> {
|
|||
}
|
||||
|
||||
impl Event<'_> {
|
||||
#[must_use]
|
||||
pub fn to_vec(&self) -> Vec<u8> {
|
||||
self.into()
|
||||
}
|
||||
|
@ -151,6 +152,7 @@ pub struct ParsedSectionHeader<'a> {
|
|||
}
|
||||
|
||||
impl ParsedSectionHeader<'_> {
|
||||
#[must_use]
|
||||
pub fn to_vec(&self) -> Vec<u8> {
|
||||
self.into()
|
||||
}
|
||||
|
@ -243,11 +245,13 @@ pub struct Error<'a> {
|
|||
impl Error<'_> {
|
||||
/// The one-indexed line number where the error occurred. This is determined
|
||||
/// by the number of newlines that were successfully parsed.
|
||||
#[must_use]
|
||||
pub const fn line_number(&self) -> usize {
|
||||
self.line_number + 1
|
||||
}
|
||||
|
||||
/// The remaining data that was left unparsed.
|
||||
#[must_use]
|
||||
pub const fn remaining_data(&self) -> &[u8] {
|
||||
self.parsed_until
|
||||
}
|
||||
|
@ -521,6 +525,7 @@ impl<'a> Parser<'a> {
|
|||
/// a section) from the parser. Consider [`Parser::take_frontmatter`] if
|
||||
/// you need an owned copy only once. If that function was called, then this
|
||||
/// will always return an empty slice.
|
||||
#[must_use]
|
||||
pub fn frontmatter(&self) -> &[Event<'a>] {
|
||||
&self.frontmatter
|
||||
}
|
||||
|
@ -538,6 +543,7 @@ impl<'a> Parser<'a> {
|
|||
/// Returns the parsed sections from the parser. Consider
|
||||
/// [`Parser::take_sections`] if you need an owned copy only once. If that
|
||||
/// function was called, then this will always return an empty slice.
|
||||
#[must_use]
|
||||
pub fn sections(&self) -> &[ParsedSection<'a>] {
|
||||
&self.sections
|
||||
}
|
||||
|
@ -552,6 +558,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Consumes the parser to produce a Vec of Events.
|
||||
#[must_use]
|
||||
pub fn into_vec(self) -> Vec<Event<'a>> {
|
||||
self.into_iter().collect()
|
||||
}
|
||||
|
@ -994,7 +1001,7 @@ fn take_newline(i: &[u8]) -> IResult<&[u8], (&str, usize)> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod comments {
|
||||
use super::*;
|
||||
use super::comment;
|
||||
use crate::test_util::{comment as parsed_comment, fully_consumed};
|
||||
|
||||
#[test]
|
||||
|
@ -1024,7 +1031,7 @@ mod comments {
|
|||
|
||||
#[cfg(test)]
|
||||
mod section_headers {
|
||||
use super::*;
|
||||
use super::section_header;
|
||||
use crate::test_util::{fully_consumed, section_header as parsed_section_header};
|
||||
|
||||
#[test]
|
||||
|
@ -1096,7 +1103,7 @@ mod section_headers {
|
|||
|
||||
#[cfg(test)]
|
||||
mod config_name {
|
||||
use super::*;
|
||||
use super::config_name;
|
||||
use crate::test_util::fully_consumed;
|
||||
|
||||
#[test]
|
||||
|
@ -1118,7 +1125,7 @@ mod config_name {
|
|||
|
||||
#[cfg(test)]
|
||||
mod section_body {
|
||||
use super::*;
|
||||
use super::{section_body, Event, ParserNode};
|
||||
use crate::test_util::{name_event, value_event, whitespace_event};
|
||||
|
||||
#[test]
|
||||
|
@ -1152,7 +1159,7 @@ mod section_body {
|
|||
|
||||
#[cfg(test)]
|
||||
mod value_no_continuation {
|
||||
use super::*;
|
||||
use super::value_impl;
|
||||
use crate::test_util::value_event;
|
||||
|
||||
#[test]
|
||||
|
@ -1258,7 +1265,7 @@ mod value_no_continuation {
|
|||
|
||||
#[cfg(test)]
|
||||
mod value_continuation {
|
||||
use super::*;
|
||||
use super::value_impl;
|
||||
use crate::test_util::{newline_event, value_done_event, value_not_done_event};
|
||||
|
||||
#[test]
|
||||
|
@ -1318,10 +1325,7 @@ mod value_continuation {
|
|||
#[test]
|
||||
fn quote_split_over_two_lines_with_leftover_comment() {
|
||||
let mut events = vec![];
|
||||
assert_eq!(
|
||||
value_impl(b"\"\\\n;\";a", &mut events).unwrap().0,
|
||||
";a".as_bytes()
|
||||
);
|
||||
assert_eq!(value_impl(b"\"\\\n;\";a", &mut events).unwrap().0, b";a");
|
||||
assert_eq!(
|
||||
events,
|
||||
vec![
|
||||
|
@ -1335,7 +1339,7 @@ mod value_continuation {
|
|||
|
||||
#[cfg(test)]
|
||||
mod section {
|
||||
use super::*;
|
||||
use super::{section, Event, ParsedSection, ParserNode};
|
||||
use crate::test_util::{
|
||||
comment_event, fully_consumed, name_event, newline_event,
|
||||
section_header as parsed_section_header, value_done_event, value_event,
|
||||
|
@ -1535,7 +1539,7 @@ mod section {
|
|||
|
||||
#[cfg(test)]
|
||||
mod error {
|
||||
use super::*;
|
||||
use super::parse_from_str;
|
||||
|
||||
#[test]
|
||||
fn line_no_is_one_indexed() {
|
||||
|
|
|
@ -59,6 +59,7 @@ use std::str::FromStr;
|
|||
/// ```
|
||||
///
|
||||
/// [`parser`]: crate::parser::Parser
|
||||
#[must_use]
|
||||
pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
|
||||
let size = input.len();
|
||||
if &*input == b"\"\"" {
|
||||
|
@ -120,18 +121,21 @@ pub fn normalize_cow(input: Cow<'_, [u8]>) -> Cow<'_, [u8]> {
|
|||
|
||||
/// `&[u8]` variant of [`normalize_cow`].
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn normalize_bytes(input: &[u8]) -> Cow<'_, [u8]> {
|
||||
normalize_cow(Cow::Borrowed(input))
|
||||
}
|
||||
|
||||
/// `Vec[u8]` variant of [`normalize_cow`].
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn normalize_vec(input: Vec<u8>) -> Cow<'static, [u8]> {
|
||||
normalize_cow(Cow::Owned(input))
|
||||
}
|
||||
|
||||
/// [`str`] variant of [`normalize_cow`].
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn normalize_str(input: &str) -> Cow<'_, [u8]> {
|
||||
normalize_bytes(input.as_bytes())
|
||||
}
|
||||
|
@ -150,6 +154,7 @@ pub enum Value<'a> {
|
|||
}
|
||||
|
||||
impl Value<'_> {
|
||||
#[must_use]
|
||||
pub fn to_vec(&self) -> Vec<u8> {
|
||||
self.into()
|
||||
}
|
||||
|
@ -261,10 +266,12 @@ pub enum Boolean<'a> {
|
|||
}
|
||||
|
||||
impl Boolean<'_> {
|
||||
#[must_use]
|
||||
pub fn to_vec(&self) -> Vec<u8> {
|
||||
self.into()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
self.into()
|
||||
}
|
||||
|
@ -500,6 +507,7 @@ pub struct Integer {
|
|||
}
|
||||
|
||||
impl Integer {
|
||||
#[must_use]
|
||||
pub fn to_vec(&self) -> Vec<u8> {
|
||||
self.into()
|
||||
}
|
||||
|
@ -610,6 +618,7 @@ pub enum IntegerSuffix {
|
|||
|
||||
impl IntegerSuffix {
|
||||
/// Returns the number of bits that the suffix shifts left by.
|
||||
#[must_use]
|
||||
pub const fn bitwise_offset(self) -> usize {
|
||||
match self {
|
||||
Self::Kibi => 10,
|
||||
|
@ -690,6 +699,7 @@ pub struct Color {
|
|||
}
|
||||
|
||||
impl Color {
|
||||
#[must_use]
|
||||
pub fn to_vec(&self) -> Vec<u8> {
|
||||
self.into()
|
||||
}
|
||||
|
@ -1118,7 +1128,7 @@ mod normalize {
|
|||
|
||||
#[cfg(test)]
|
||||
mod boolean {
|
||||
use super::*;
|
||||
use super::{Boolean, TrueVariant, TryFrom};
|
||||
|
||||
#[test]
|
||||
fn from_str_false() {
|
||||
|
@ -1171,7 +1181,7 @@ mod boolean {
|
|||
|
||||
#[cfg(test)]
|
||||
mod integer {
|
||||
use super::*;
|
||||
use super::{FromStr, Integer, IntegerSuffix};
|
||||
|
||||
#[test]
|
||||
fn from_str_no_suffix() {
|
||||
|
|
|
@ -13,12 +13,12 @@ pub fn section_header(
|
|||
name: &str,
|
||||
subsection: impl Into<Option<(&'static str, &'static str)>>,
|
||||
) -> ParsedSectionHeader<'_> {
|
||||
let name = Cow::Borrowed(name.into());
|
||||
let name = Cow::Borrowed(name);
|
||||
if let Some((separator, subsection_name)) = subsection.into() {
|
||||
ParsedSectionHeader {
|
||||
name,
|
||||
separator: Some(Cow::Borrowed(separator.into())),
|
||||
subsection_name: Some(Cow::Borrowed(subsection_name.into())),
|
||||
separator: Some(Cow::Borrowed(separator)),
|
||||
subsection_name: Some(Cow::Borrowed(subsection_name)),
|
||||
}
|
||||
} else {
|
||||
ParsedSectionHeader {
|
||||
|
@ -30,7 +30,7 @@ pub fn section_header(
|
|||
}
|
||||
|
||||
fn name(name: &'static str) -> Event<'static> {
|
||||
Event::Key(Cow::Borrowed(name.into()))
|
||||
Event::Key(Cow::Borrowed(name))
|
||||
}
|
||||
|
||||
fn value(value: &'static str) -> Event<'static> {
|
||||
|
@ -42,11 +42,11 @@ fn newline() -> Event<'static> {
|
|||
}
|
||||
|
||||
fn newline_custom(value: &'static str) -> Event<'static> {
|
||||
Event::Newline(Cow::Borrowed(value.into()))
|
||||
Event::Newline(Cow::Borrowed(value))
|
||||
}
|
||||
|
||||
fn whitespace(value: &'static str) -> Event<'static> {
|
||||
Event::Whitespace(Cow::Borrowed(value.into()))
|
||||
Event::Whitespace(Cow::Borrowed(value))
|
||||
}
|
||||
|
||||
fn separator() -> Event<'static> {
|
||||
|
|
Reference in a new issue