From 1872b9a5b0bccc57fa7867b57371e680545e2d57 Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Tekuri Date: Fri, 27 Dec 2024 21:27:31 +0530 Subject: [PATCH] clippy: fix warnings --- src/compiler.rs | 6 +++--- src/draft.rs | 4 ++-- src/ecma.rs | 4 ++-- src/lib.rs | 4 ++-- src/loader.rs | 5 ++--- src/output.rs | 22 +++++++++++----------- src/validator.rs | 28 ++++++++++++++-------------- 7 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index 93a7a32..ca30eee 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -327,7 +327,7 @@ struct ObjCompiler<'c, 'v, 'l, 's, 'r, 'q> { } // compile supported drafts -impl<'c, 'v, 'l, 's, 'r, 'q> ObjCompiler<'c, 'v, 'l, 's, 'r, 'q> { +impl ObjCompiler<'_, '_, '_, '_, '_, '_> { fn compile_obj(&mut self, s: &mut Schema) -> Result<(), CompileError> { self.compile_draft4(s)?; if self.draft_version() >= 6 { @@ -628,7 +628,7 @@ impl<'c, 'v, 'l, 's, 'r, 'q> ObjCompiler<'c, 'v, 'l, 's, 'r, 'q> { } // enqueue helpers -impl<'c, 'v, 'l, 's, 'r, 'q> ObjCompiler<'c, 'v, 'l, 's, 'r, 'q> { +impl ObjCompiler<'_, '_, '_, '_, '_, '_> { fn enqueue_schema(&mut self, ptr: JsonPointer) -> SchemaIndex { let up = UrlPtr { url: self.up.url.clone(), @@ -701,7 +701,7 @@ impl<'c, 'v, 'l, 's, 'r, 'q> ObjCompiler<'c, 'v, 'l, 's, 'r, 'q> { } // query helpers -impl<'c, 'v, 'l, 's, 'r, 'q> ObjCompiler<'c, 'v, 'l, 's, 'r, 'q> { +impl<'v> ObjCompiler<'_, 'v, '_, '_, '_, '_> { fn draft_version(&self) -> usize { self.root.draft.version } diff --git a/src/draft.rs b/src/draft.rs index c526ff8..91b73d2 100644 --- a/src/draft.rs +++ b/src/draft.rs @@ -253,12 +253,12 @@ impl Draft { // anchor with same root_ptr already exists return Ok(()); } - return Err(CompileError::DuplicateAnchor { + Err(CompileError::DuplicateAnchor { url: url.as_str().to_owned(), anchor: entry.key().to_string(), ptr1: entry.get().to_string(), ptr2: sch_ptr.to_string(), - }); + }) } entry => { entry.or_insert(sch_ptr.to_owned()); diff --git a/src/ecma.rs b/src/ecma.rs index e5cb0e2..200f05d 100644 --- a/src/ecma.rs +++ b/src/ecma.rs @@ -83,7 +83,7 @@ struct Translator<'a> { out: Option, } -impl<'a> Translator<'a> { +impl Translator<'_> { fn replace(&mut self, span: &Span, with: &str) { let (start, end) = (span.start.offset, span.end.offset); self.out = Some(format!("{}{with}{}", &self.pat[..start], &self.pat[end..])); @@ -114,7 +114,7 @@ impl<'a> Translator<'a> { } } -impl<'a> Visitor for Translator<'a> { +impl Visitor for Translator<'_> { type Output = Option; type Err = &'static str; diff --git a/src/lib.rs b/src/lib.rs index abea383..a5d68b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -419,7 +419,7 @@ pub struct ValidationError<'s, 'v> { pub causes: Vec>, } -impl<'s, 'v> Error for ValidationError<'s, 'v> {} +impl Error for ValidationError<'_, '_> {} /// A list specifying general categories of validation errors. #[derive(Debug)] @@ -557,7 +557,7 @@ pub enum ErrorKind<'s, 'v> { OneOf(Option<(usize, usize)>), } -impl<'s, 'v> Display for ErrorKind<'s, 'v> { +impl Display for ErrorKind<'_, '_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Group => write!(f, "validation failed"), diff --git a/src/loader.rs b/src/loader.rs index 68559c8..8871337 100644 --- a/src/loader.rs +++ b/src/loader.rs @@ -133,9 +133,8 @@ impl DefaultUrlLoader { })? }; self.add_doc(url.clone(), doc); - return self - .get_doc(url) - .ok_or(CompileError::Bug("doc must exist".into())); + self.get_doc(url) + .ok_or(CompileError::Bug("doc must exist".into())) } pub(crate) fn get_draft( diff --git a/src/output.rs b/src/output.rs index 1ab78a4..fa9626e 100644 --- a/src/output.rs +++ b/src/output.rs @@ -10,7 +10,7 @@ use serde::{ use crate::{util::*, ErrorKind, InstanceLocation, ValidationError}; -impl<'s, 'v> ValidationError<'s, 'v> { +impl<'s> ValidationError<'s, '_> { fn absolute_keyword_location(&self) -> AbsoluteKeywordLocation<'s> { if let ErrorKind::Reference { url, .. } = &self.kind { AbsoluteKeywordLocation { @@ -139,7 +139,7 @@ impl<'s, 'v> ValidationError<'s, 'v> { // DfsIterator -- -impl<'s, 'v> Display for ValidationError<'s, 'v> { +impl Display for ValidationError<'_, '_> { /// Formats error hierarchy. Use `#` to show the schema location. fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut indent = Indent::default(); @@ -282,7 +282,7 @@ impl<'a, 's, 'v> SchemaLocation<'a, 's, 'v> { } } -impl<'a, 's, 'v> Display for SchemaLocation<'a, 's, 'v> { +impl Display for SchemaLocation<'_, '_, '_> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let mut iter = self.stack.iter().cloned(); let cur = iter.next_back().unwrap(); @@ -423,7 +423,7 @@ pub struct OutputUnit<'e, 's, 'v> { pub error: OutputError<'e, 's, 'v>, } -impl<'e, 's, 'v> Serialize for OutputUnit<'e, 's, 'v> { +impl Serialize for OutputUnit<'_, '_, '_> { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -445,7 +445,7 @@ impl<'e, 's, 'v> Serialize for OutputUnit<'e, 's, 'v> { } } -impl<'e, 's, 'v> Display for OutputUnit<'e, 's, 'v> { +impl Display for OutputUnit<'_, '_, '_> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write_json_to_fmt(f, self) } @@ -459,7 +459,7 @@ pub enum OutputError<'e, 's, 'v> { Branch(Vec>), } -impl<'e, 's, 'v> Serialize for OutputError<'e, 's, 'v> { +impl Serialize for OutputError<'_, '_, '_> { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -479,10 +479,10 @@ impl<'e, 's, 'v> Serialize for OutputError<'e, 's, 'v> { // AbsoluteKeywordLocation -- -impl<'s, 'v> ErrorKind<'s, 'v> { +impl<'s> ErrorKind<'s, '_> { pub fn keyword_path(&self) -> Option> { #[inline(always)] - fn kw(kw: &'static str) -> Option { + fn kw(kw: &'static str) -> Option> { Some(KeywordPath { keyword: kw, token: None, @@ -550,7 +550,7 @@ pub struct AbsoluteKeywordLocation<'s> { pub keyword_path: Option>, } -impl<'s> Display for AbsoluteKeywordLocation<'s> { +impl Display for AbsoluteKeywordLocation<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.schema_url.fmt(f)?; if let Some(path) = &self.keyword_path { @@ -577,7 +577,7 @@ pub struct KeywordPath<'s> { pub token: Option>, } -impl<'s> Display for KeywordPath<'s> { +impl Display for KeywordPath<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.keyword.fmt(f)?; if let Some(token) = &self.token { @@ -597,7 +597,7 @@ pub enum SchemaToken<'s> { Item(usize), } -impl<'s> Display for SchemaToken<'s> { +impl Display for SchemaToken<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { SchemaToken::Prop(p) => write!(f, "{}", escape(p)), diff --git a/src/validator.rs b/src/validator.rs index be5f78b..44ea546 100644 --- a/src/validator.rs +++ b/src/validator.rs @@ -91,7 +91,7 @@ struct Validator<'v, 's, 'd, 'e> { bool_result: bool, // is interested to know valid or not (but not actuall error) } -impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { +impl<'v, 's> Validator<'v, 's, '_, '_> { fn validate(mut self) -> Result, ValidationError<'s, 'v>> { let s = self.schema; let v = self.v; @@ -186,7 +186,7 @@ impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { } // type specific validations -impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { +impl<'v> Validator<'v, '_, '_, '_> { fn obj_validate(&mut self, obj: &'v Map) { let s = self.schema; macro_rules! add_err { @@ -565,7 +565,7 @@ impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { } // references validation -impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { +impl<'v, 's> Validator<'v, 's, '_, '_> { fn refs_validate(&mut self) { let s = self.schema; macro_rules! add_err { @@ -653,7 +653,7 @@ impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { } // conditional validation -impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { +impl Validator<'_, '_, '_, '_> { fn cond_validate(&mut self) { let s = self.schema; macro_rules! add_err { @@ -746,7 +746,7 @@ impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { } // uneval validation -impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { +impl Validator<'_, '_, '_, '_> { fn uneval_validate(&mut self) { let s = self.schema; let v = self.v; @@ -783,7 +783,7 @@ impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { } // validation helpers -impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { +impl<'v, 's> Validator<'v, 's, '_, '_> { fn validate_val( &mut self, sch: SchemaIndex, @@ -843,7 +843,7 @@ impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { } // error helpers -impl<'v, 's, 'd, 'e> Validator<'v, 's, 'd, 'e> { +impl<'v, 's> Validator<'v, 's, '_, '_> { #[inline(always)] fn error(&self, kind: ErrorKind<'s, 'v>) -> ValidationError<'s, 'v> { if self.bool_result { @@ -981,7 +981,7 @@ struct Scope<'a> { parent: Option<&'a Scope<'a>>, } -impl<'a> Scope<'a> { +impl Scope<'_> { fn child<'x>( &'x self, sch: SchemaIndex, @@ -1020,7 +1020,7 @@ pub enum InstanceToken<'v> { Item(usize), } -impl<'v> From for InstanceToken<'v> { +impl From for InstanceToken<'_> { fn from(prop: String) -> Self { InstanceToken::Prop(prop.into()) } @@ -1032,7 +1032,7 @@ impl<'v> From<&'v str> for InstanceToken<'v> { } } -impl<'v> From for InstanceToken<'v> { +impl From for InstanceToken<'_> { fn from(index: usize) -> Self { InstanceToken::Item(index) } @@ -1044,7 +1044,7 @@ pub struct InstanceLocation<'v> { pub tokens: Vec>, } -impl<'v> InstanceLocation<'v> { +impl InstanceLocation<'_> { fn new() -> Self { Self::default() } @@ -1062,7 +1062,7 @@ impl<'v> InstanceLocation<'v> { } } -impl<'v> Display for InstanceLocation<'v> { +impl Display for InstanceLocation<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { for tok in &self.tokens { f.write_char('/')?; @@ -1075,7 +1075,7 @@ impl<'v> Display for InstanceLocation<'v> { } } -impl<'s, 'v> ValidationError<'s, 'v> { +impl<'s> ValidationError<'s, '_> { pub(crate) fn clone_static(self) -> ValidationError<'s, 'static> { let mut causes = Vec::with_capacity(self.causes.len()); for cause in self.causes { @@ -1090,7 +1090,7 @@ impl<'s, 'v> ValidationError<'s, 'v> { } } -impl<'s, 'v> ErrorKind<'s, 'v> { +impl<'s> ErrorKind<'s, '_> { fn clone_static(self) -> ErrorKind<'s, 'static> { use ErrorKind::*; match self {