diff --git a/crates/stef-build/src/definition.rs b/crates/stef-build/src/definition.rs index 377a7ad..2a0157b 100644 --- a/crates/stef-build/src/definition.rs +++ b/crates/stef-build/src/definition.rs @@ -21,7 +21,7 @@ pub fn compile_schema(opts: &Opts, Schema { definitions, .. }: &Schema<'_>) -> T } fn compile_definition(opts: &Opts, definition: &Definition<'_>) -> TokenStream { - let definition = match definition { + match definition { Definition::Module(m) => compile_module(opts, m), Definition::Struct(s) => { let def = compile_struct(opts, s); @@ -48,9 +48,7 @@ fn compile_definition(opts: &Opts, definition: &Definition<'_>) -> TokenStream { Definition::TypeAlias(a) => compile_alias(opts, a), Definition::Const(c) => compile_const(c), Definition::Import(i) => compile_import(i), - }; - - quote! { #definition } + } } fn compile_module( diff --git a/crates/stef-build/src/encode.rs b/crates/stef-build/src/encode.rs index bd74915..b42a824 100644 --- a/crates/stef-build/src/encode.rs +++ b/crates/stef-build/src/encode.rs @@ -270,8 +270,10 @@ fn compile_data_type(opts: &Opts, ty: &Type<'_>, name: TokenStream) -> TokenStre DataType::I128 => quote! { ::stef::buf::encode_i128(w, #name) }, DataType::F32 => quote! { ::stef::buf::encode_f32(w, #name) }, DataType::F64 => quote! { ::stef::buf::encode_f64(w, #name) }, - DataType::String | DataType::StringRef => quote! { ::stef::buf::encode_string(w, &#name) }, - DataType::Bytes | DataType::BytesRef => match opts.bytes_type { + DataType::String | DataType::StringRef | DataType::BoxString => { + quote! { ::stef::buf::encode_string(w, &#name) } + } + DataType::Bytes | DataType::BytesRef | DataType::BoxBytes => match opts.bytes_type { BytesType::VecU8 => quote! { ::stef::buf::encode_bytes_std(w, &#name) }, BytesType::Bytes => quote! { ::stef::buf::encode_bytes_bytes(w, &#name) }, }, @@ -352,9 +354,6 @@ fn compile_data_type(opts: &Opts, ty: &Type<'_>, name: TokenStream) -> TokenStre | DataType::HashSet(_) => compile_data_type(opts, ty, quote! { #name.get() }), ty => todo!("compiler should catch invalid {ty:?} type"), }, - - DataType::BoxString => quote! { ::stef::buf::encode_string(w, &*#name) }, - DataType::BoxBytes => quote! { ::stef::buf::encode_bytes_std(w, &*#name) }, DataType::Tuple(types) => match types.len() { 2..=12 => { let types = types.iter().enumerate().map(|(idx, ty)| { @@ -371,9 +370,7 @@ fn compile_data_type(opts: &Opts, ty: &Type<'_>, name: TokenStream) -> TokenStre }); quote! { #(#types;)* } } - 0 => panic!("tuple with zero elements"), - 1 => panic!("tuple with single element"), - _ => panic!("tuple with more than 12 elements"), + n => todo!("compiler should catch invalid tuple with {n} elements"), }, DataType::Array(ty, _size) => { let ty = compile_data_type( diff --git a/crates/stef-build/tests/snapshots/compiler__compile@types_basic.stef.snap b/crates/stef-build/tests/snapshots/compiler__compile@types_basic.stef.snap index a4bff2c..e23016b 100644 --- a/crates/stef-build/tests/snapshots/compiler__compile@types_basic.stef.snap +++ b/crates/stef-build/tests/snapshots/compiler__compile@types_basic.stef.snap @@ -162,14 +162,14 @@ impl ::stef::Encode for Sample { w, 18, |w| { - ::stef::buf::encode_string(w, &*self.f18); + ::stef::buf::encode_string(w, &self.f18); }, ); ::stef::buf::encode_field( w, 19, |w| { - ::stef::buf::encode_bytes_std(w, &*self.f19); + ::stef::buf::encode_bytes_std(w, &self.f19); }, ); ::stef::buf::encode_field( diff --git a/crates/stef-build/tests/snapshots/compiler__compile@types_nested.stef.snap b/crates/stef-build/tests/snapshots/compiler__compile@types_nested.stef.snap index b880705..9fc7855 100644 --- a/crates/stef-build/tests/snapshots/compiler__compile@types_nested.stef.snap +++ b/crates/stef-build/tests/snapshots/compiler__compile@types_nested.stef.snap @@ -38,7 +38,7 @@ impl ::stef::Encode for Sample { ::stef::buf::encode_i64(w, *k); }, |w, v| { - ::stef::buf::encode_string(w, &*v); + ::stef::buf::encode_string(w, &v); }, ); }, diff --git a/crates/stef-compiler/src/resolve/mod.rs b/crates/stef-compiler/src/resolve/mod.rs index e595cc3..5f07065 100644 --- a/crates/stef-compiler/src/resolve/mod.rs +++ b/crates/stef-compiler/src/resolve/mod.rs @@ -104,7 +104,7 @@ pub(crate) enum ResolvedImport<'a> { }, } -impl<'a> Module<'a> { +impl Module<'_> { fn resolve_local(&self, ty: &ExternalType<'_>) -> Result<(), ResolveLocal> { let module = if ty.path.is_empty() { self diff --git a/crates/stef-compiler/tests/compiler.rs b/crates/stef-compiler/tests/compiler.rs index 64aff97..ee26156 100644 --- a/crates/stef-compiler/tests/compiler.rs +++ b/crates/stef-compiler/tests/compiler.rs @@ -30,7 +30,7 @@ impl<'a> Wrapper<'a> { } } -impl<'a> Display for Wrapper<'a> { +impl Display for Wrapper<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.debug(self.1, f) } diff --git a/crates/stef-parser/src/lib.rs b/crates/stef-parser/src/lib.rs index 3f19051..ac28aaf 100644 --- a/crates/stef-parser/src/lib.rs +++ b/crates/stef-parser/src/lib.rs @@ -144,7 +144,7 @@ impl<'a> Schema<'a> { } } -impl<'a> Display for Schema<'a> { +impl Display for Schema<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { for definition in &self.definitions { writeln!(f, "{definition}")?; @@ -170,7 +170,7 @@ pub enum Definition<'a> { Import(Import<'a>), } -impl<'a> Print for Definition<'a> { +impl Print for Definition<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { match self { Definition::Module(v) => v.print(f, level), @@ -183,7 +183,7 @@ impl<'a> Print for Definition<'a> { } } -impl<'a> Display for Definition<'a> { +impl Display for Definition<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -232,7 +232,7 @@ pub struct Module<'a> { pub definitions: Vec>, } -impl<'a> Print for Module<'a> { +impl Print for Module<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { let Self { comment, @@ -257,7 +257,7 @@ impl<'a> Print for Module<'a> { } } -impl<'a> Display for Module<'a> { +impl Display for Module<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -291,7 +291,7 @@ pub struct Struct<'a> { pub fields: Fields<'a>, } -impl<'a> Print for Struct<'a> { +impl Print for Struct<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { let indent = Self::INDENT.repeat(level); let Self { @@ -310,7 +310,7 @@ impl<'a> Print for Struct<'a> { } } -impl<'a> Display for Struct<'a> { +impl Display for Struct<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -345,7 +345,7 @@ pub struct Enum<'a> { pub variants: Vec>, } -impl<'a> Print for Enum<'a> { +impl Print for Enum<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { let Self { comment, @@ -371,7 +371,7 @@ impl<'a> Print for Enum<'a> { } } -impl<'a> Display for Enum<'a> { +impl Display for Enum<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -392,7 +392,7 @@ pub struct Variant<'a> { span: Span, } -impl<'a> Print for Variant<'a> { +impl Print for Variant<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { let Self { comment, @@ -412,13 +412,13 @@ impl<'a> Print for Variant<'a> { } } -impl<'a> Spanned for Variant<'a> { +impl Spanned for Variant<'_> { fn span(&self) -> Span { self.span } } -impl<'a> Display for Variant<'a> { +impl Display for Variant<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -445,7 +445,7 @@ pub struct TypeAlias<'a> { pub target: Type<'a>, } -impl<'a> Print for TypeAlias<'a> { +impl Print for TypeAlias<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { let Self { comment, @@ -488,7 +488,7 @@ pub enum Fields<'a> { Unit, } -impl<'a> Print for Fields<'a> { +impl Print for Fields<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { match self { Fields::Named(fields) => { @@ -508,7 +508,7 @@ impl<'a> Print for Fields<'a> { } } -impl<'a> Display for Fields<'a> { +impl Display for Fields<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -537,7 +537,7 @@ pub struct NamedField<'a> { span: Span, } -impl<'a> Print for NamedField<'a> { +impl Print for NamedField<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { let Self { comment, @@ -554,13 +554,13 @@ impl<'a> Print for NamedField<'a> { } } -impl<'a> Spanned for NamedField<'a> { +impl Spanned for NamedField<'_> { fn span(&self) -> Span { self.span } } -impl<'a> Display for NamedField<'a> { +impl Display for NamedField<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -584,13 +584,13 @@ pub struct UnnamedField<'a> { span: Span, } -impl<'a> Spanned for UnnamedField<'a> { +impl Spanned for UnnamedField<'_> { fn span(&self) -> Span { self.span } } -impl<'a> Display for UnnamedField<'a> { +impl Display for UnnamedField<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { ty, id, span: _ } = self; write!(f, "{ty} {id}") @@ -607,7 +607,7 @@ impl<'a> Display for UnnamedField<'a> { #[derive(Debug, Default, Eq, PartialEq)] pub struct Comment<'a>(pub Vec<&'a str>); -impl<'a> Print for Comment<'a> { +impl Print for Comment<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { let lines = &self.0; @@ -620,7 +620,7 @@ impl<'a> Print for Comment<'a> { } } -impl<'a> Display for Comment<'a> { +impl Display for Comment<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -630,7 +630,7 @@ impl<'a> Display for Comment<'a> { #[derive(Debug, Default, PartialEq)] pub struct Attributes<'a>(pub Vec>); -impl<'a> Print for Attributes<'a> { +impl Print for Attributes<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { if self.0.is_empty() { return Ok(()); @@ -643,7 +643,7 @@ impl<'a> Print for Attributes<'a> { } } -impl<'a> Display for Attributes<'a> { +impl Display for Attributes<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -658,7 +658,7 @@ pub struct Attribute<'a> { pub value: AttributeValue<'a>, } -impl<'a> Print for Attribute<'a> { +impl Print for Attribute<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { let indent = Self::INDENT.repeat(level); let Self { name, value } = self; @@ -667,7 +667,7 @@ impl<'a> Print for Attribute<'a> { } } -impl<'a> Display for Attribute<'a> { +impl Display for Attribute<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -684,7 +684,7 @@ pub enum AttributeValue<'a> { Multi(Vec>), } -impl<'a> Print for AttributeValue<'a> { +impl Print for AttributeValue<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, _level: usize) -> fmt::Result { match self { Self::Unit => Ok(()), @@ -694,7 +694,7 @@ impl<'a> Print for AttributeValue<'a> { } } -impl<'a> Display for AttributeValue<'a> { +impl Display for AttributeValue<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.print(f, 0) } @@ -710,13 +710,13 @@ pub struct Type<'a> { span: Span, } -impl<'a> Spanned for Type<'a> { +impl Spanned for Type<'_> { fn span(&self) -> Span { self.span } } -impl<'a> Display for Type<'a> { +impl Display for Type<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.value.fmt(f) } @@ -792,7 +792,7 @@ pub enum DataType<'a> { External(ExternalType<'a>), } -impl<'a> Display for DataType<'a> { +impl Display for DataType<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Bool => f.write_str("bool"), @@ -840,7 +840,7 @@ pub struct ExternalType<'a> { pub generics: Vec>, } -impl<'a> Display for ExternalType<'a> { +impl Display for ExternalType<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let Self { path, @@ -864,7 +864,7 @@ impl<'a> Display for ExternalType<'a> { #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct Generics<'a>(pub Vec>); -impl<'a> Display for Generics<'a> { +impl Display for Generics<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { concat(f, "<", &self.0, ", ", ">") } @@ -914,7 +914,7 @@ pub struct Name<'a> { span: Span, } -impl<'a> Name<'a> { +impl Name<'_> { /// Retrieve the raw string value of this name. #[must_use] pub const fn get(&self) -> &str { @@ -922,13 +922,13 @@ impl<'a> Name<'a> { } } -impl<'a> Spanned for Name<'a> { +impl Spanned for Name<'_> { fn span(&self) -> Span { self.span } } -impl<'a> Display for Name<'a> { +impl Display for Name<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.value.fmt(f) } @@ -956,7 +956,7 @@ pub struct Const<'a> { pub value: Literal, } -impl<'a> Print for Const<'a> { +impl Print for Const<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { let Self { comment, @@ -1009,7 +1009,7 @@ pub struct Import<'a> { pub element: Option>, } -impl<'a> Print for Import<'a> { +impl Print for Import<'_> { fn print(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { let Self { segments, element } = self; diff --git a/crates/stef-parser/src/parser.rs b/crates/stef-parser/src/parser.rs index 43977cb..fa7d4a7 100644 --- a/crates/stef-parser/src/parser.rs +++ b/crates/stef-parser/src/parser.rs @@ -101,7 +101,7 @@ mod ids { #[err( msg("Failed to parse id declaration"), code(stef::parse::id), - help("Expected id declaration in the form `{}`", highlight::sample("@..."),) + help("Expected id declaration in the form `{}`", highlight::sample("@...")) )] #[rename(ParseIdError)] pub struct ParseError { diff --git a/crates/stef-parser/tests/parser.rs b/crates/stef-parser/tests/parser.rs index 59119e7..53c4c47 100644 --- a/crates/stef-parser/tests/parser.rs +++ b/crates/stef-parser/tests/parser.rs @@ -34,7 +34,7 @@ fn parse_schema() { fn parse_invalid_schema() { struct Wrapper<'a>(&'a MietteHandler, &'a dyn Diagnostic); - impl<'a> Display for Wrapper<'a> { + impl Display for Wrapper<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.debug(self.1, f) } diff --git a/crates/stef/src/buf/decode.rs b/crates/stef/src/buf/decode.rs index 45e212b..2b66f16 100644 --- a/crates/stef/src/buf/decode.rs +++ b/crates/stef/src/buf/decode.rs @@ -378,7 +378,7 @@ where } } -impl<'a, T> Decode for std::borrow::Cow<'a, T> +impl Decode for std::borrow::Cow<'_, T> where T: Copy + Decode, { diff --git a/crates/stef/src/buf/encode.rs b/crates/stef/src/buf/encode.rs index 1af64a2..d7049ef 100644 --- a/crates/stef/src/buf/encode.rs +++ b/crates/stef/src/buf/encode.rs @@ -204,7 +204,7 @@ where } } -impl<'a, T> Encode for &'a [T] +impl Encode for &'_ [T] where T: Encode, { @@ -265,7 +265,7 @@ where } } -impl<'a, T> Encode for std::borrow::Cow<'a, T> +impl Encode for std::borrow::Cow<'_, T> where T: Clone + Encode, {