difftreelog
style fix clippy warnings
in: master
24 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -676,18 +676,18 @@
[[package]]
name = "jrsonnet-gcmodule"
-version = "0.4.1"
+version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c33f4f6cdc60f5ae94ebae3dfe7f484ae79b364225d9b19601b24c804cfd8751"
+checksum = "f95b976a79e4000bb9e07ff0709dca0ea27bcf1952d4c17d91fb7364d6145683"
dependencies = [
"jrsonnet-gcmodule-derive",
]
[[package]]
name = "jrsonnet-gcmodule-derive"
-version = "0.4.1"
+version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2b30c95b285f9bb6709f1b3e6fc69b3a25e39b32ff987587fd108f0f22be5fa3"
+checksum = "51d928626220a310ff0cec815e80cf7fe104697184352ca21c40534e0b0d72d9"
dependencies = [
"proc-macro2",
"quote",
@@ -1602,7 +1602,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.59.0",
+ "windows-sys 0.61.2",
]
[[package]]
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,7 @@
jrsonnet-cli = { path = "./crates/jrsonnet-cli", version = "0.5.0-pre97" }
jrsonnet-types = { path = "./crates/jrsonnet-types", version = "0.5.0-pre97" }
jrsonnet-formatter = { path = "./crates/jrsonnet-formatter", version = "0.5.0-pre97" }
-jrsonnet-gcmodule = { version = "0.4.1" }
+jrsonnet-gcmodule = { version = "0.4.2" }
# Diagnostics.
# hi-doc is my library, which handles text formatting very well, but isn't polished enough yet
# Previous implementation was based on annotate-snippets, which I don't like for many reasons.
bindings/jsonnet/src/import.rsdiffbeforeafterboth--- a/bindings/jsonnet/src/import.rs
+++ b/bindings/jsonnet/src/import.rs
@@ -66,8 +66,8 @@
base.as_ptr(),
rel.as_ptr(),
&mut found_here.cast_const(),
- &mut buf,
- &mut buf_len,
+ &raw mut buf,
+ &raw mut buf_len,
)
};
let buf_slice: &[u8] = unsafe { std::slice::from_raw_parts(buf.cast(), buf_len) };
crates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
@@ -9,6 +9,9 @@
evaluate_method, evaluate_named_param, Context, Pending, Thunk, Val,
};
+#[cfg(feature = "exp-preserve-order")]
+use crate::evaluate;
+
#[allow(clippy::too_many_lines)]
#[allow(unused_variables)]
pub fn destruct<H: BuildHasher>(
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -143,7 +143,7 @@
false,
) {
let fctx = Pending::new();
- let mut new_bindings = FxHashMap::with_capacity(var.capacity_hint());
+ let mut new_bindings = FxHashMap::with_capacity(var.binds_len());
let obj = obj.clone();
let value = Thunk::evaluated(Val::Arr(ArrValue::lazy(vec![
Thunk::evaluated(Val::string(field.clone())),
crates/jrsonnet-evaluator/src/function/builtin.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/builtin.rs
+++ b/crates/jrsonnet-evaluator/src/function/builtin.rs
@@ -98,9 +98,9 @@
fn call(&self, _loc: CallLocation<'_>, args: &[Option<Thunk<Val>>]) -> Result<Val> {
let args = args
- .into_iter()
+ .iter()
.map(|a| a.as_ref().expect("legacy natives have no default params"))
- .map(|a| a.evaluate())
+ .map(Thunk::evaluate)
.collect::<Result<Vec<Val>>>()?;
self.handler.call(&args)
}
crates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj/mod.rs
+++ b/crates/jrsonnet-evaluator/src/obj/mod.rs
@@ -1,12 +1,5 @@
use std::{
- any::Any,
- cell::{Cell, RefCell},
- clone::Clone,
- collections::hash_map::Entry,
- fmt::{self, Debug},
- hash::{Hash, Hasher},
- num::Saturating,
- ops::ControlFlow,
+ any::Any, cell::{Cell, RefCell}, clone::Clone, cmp::Reverse, collections::hash_map::Entry, fmt::{self, Debug}, hash::{Hash, Hasher}, num::Saturating, ops::ControlFlow
};
use educe::Educe;
@@ -39,18 +32,19 @@
use jrsonnet_gcmodule::Trace;
- #[derive(Clone, Copy, Default, Debug, Trace)]
+ #[derive(Clone, Copy, Default, Debug, Trace, PartialEq, Eq, PartialOrd, Ord)]
pub struct FieldIndex(());
impl FieldIndex {
pub fn absolute(_v: u32) -> Self {
Self(())
}
+ #[must_use]
pub const fn next(self) -> Self {
Self(())
}
}
- #[derive(Clone, Copy, Default, Debug, Trace)]
+ #[derive(Clone, Copy, Default, Debug, Trace, PartialEq, Eq, PartialOrd, Ord)]
pub struct SuperDepth(());
impl SuperDepth {
pub(super) fn deepen(self) {}
@@ -59,8 +53,6 @@
#[cfg(feature = "exp-preserve-order")]
pub mod ordering {
- use std::cmp::Reverse;
-
use jrsonnet_gcmodule::Trace;
#[derive(Clone, Copy, Default, Debug, Trace, PartialEq, Eq, PartialOrd, Ord)]
@@ -69,6 +61,7 @@
pub fn absolute(v: u32) -> Self {
Self(v)
}
+ #[must_use]
pub fn next(self) -> Self {
Self(self.0 + 1)
}
@@ -78,22 +71,20 @@
pub struct SuperDepth(u32);
impl SuperDepth {
pub(super) fn deepen(&mut self) {
- self.0 += 1
+ self.0 += 1;
}
}
+}
+
+use ordering::{FieldIndex, SuperDepth};
- #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
- pub struct FieldSortKey(Reverse<SuperDepth>, FieldIndex);
- impl FieldSortKey {
- pub fn new(depth: SuperDepth, index: FieldIndex) -> Self {
- Self(Reverse(depth), index)
- }
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
+pub struct FieldSortKey(Reverse<SuperDepth>, FieldIndex);
+impl FieldSortKey {
+ pub fn new(depth: SuperDepth, index: FieldIndex) -> Self {
+ Self(Reverse(depth), index)
}
}
-
-#[cfg(feature = "exp-preserve-order")]
-use ordering::FieldSortKey;
-use ordering::{FieldIndex, SuperDepth};
// 0 - add
// 12 - visibility
@@ -795,7 +786,7 @@
struct FieldVisibilityData {
omitted_until: Saturating<usize>,
exists_visible: Option<Visibility>,
- #[cfg(feature = "exp-preserve-order")]
+ #[allow(dead_code, reason = "used for exp-object-ordering, ZST otherwise")]
key: FieldSortKey,
}
impl FieldVisibilityData {
@@ -804,7 +795,7 @@
.expect("non-existing fields shall be dropped at the end of fn fields_visibility()")
.is_visible()
}
- #[cfg(feature = "exp-preserve-order")]
+ #[allow(dead_code, reason = "used for exp-object-ordering, ZST otherwise")]
fn sort_key(&self) -> FieldSortKey {
self.key
}
@@ -818,12 +809,11 @@
let mut omit_index = Saturating(0);
for core in self.0.cores.iter().rev() {
core.0
- .enum_fields_core(&mut super_depth, &mut |_depth, _index, name, visibility| {
+ .enum_fields_core(&mut super_depth, &mut |depth, index, name, visibility| {
let entry = out.entry(name);
- let data = entry.or_insert(FieldVisibilityData {
+ let data = entry.or_insert_with(|| FieldVisibilityData {
exists_visible: None,
- #[cfg(feature = "exp-preserve-order")]
- key: FieldSortKey::new(_depth, _index),
+ key: FieldSortKey::new(depth, index),
omitted_until: omit_index,
});
match visibility {
crates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/typed/conversions.rs
+++ b/crates/jrsonnet-evaluator/src/typed/conversions.rs
@@ -61,9 +61,16 @@
}
}
+#[diagnostic::on_unimplemented(
+ note = "don't implement `ParseTypedObj` directly, it is automatically provided by `FromUntyped` derive"
+)]
pub trait ParseTypedObj: Typed {
fn parse(obj: &ObjValue) -> Result<Self>;
}
+
+#[diagnostic::on_unimplemented(
+ note = "don't implement `SerializeTypedObj` directly, it is automatically provided by `IntoUntyped` derive"
+)]
pub trait SerializeTypedObj: Typed {
fn serialize(self, out: &mut ObjValueBuilder) -> Result<()>;
fn into_object(self) -> Result<ObjValue> {
crates/jrsonnet-formatter/src/comments.rsdiffbeforeafterboth--- a/crates/jrsonnet-formatter/src/comments.rs
+++ b/crates/jrsonnet-formatter/src/comments.rs
@@ -136,7 +136,7 @@
}
line = new_line.to_string();
}
- p!(out, string(line.to_string()) nl);
+ p!(out, string(line.clone()) nl);
}
}
if doc {
crates/jrsonnet-formatter/src/lib.rsdiffbeforeafterboth38 items.into_rc_path()38 items.into_rc_path()39 };39 };40 let items =40 let items = new_line_group(pi!(@i; items(o) items(end_comments_items.into()))).into_rc_path();41 new_line_group(pi!(@i; items(o.into()) items(end_comments_items.into()))).into_rc_path();424143 let indented = with_indent(pi!(@i; nl items(items.into())));42 let indented = with_indent(pi!(@i; nl items(items.into())));4443355}354}356impl Printable for ArgsDesc {355impl Printable for ArgsDesc {357 fn print(&self, out: &mut PrintItems) {356 fn print(&self, out: &mut PrintItems) {358 let start = LineNumber::new("args start line");359 let end = LineNumber::new("args end line");360 let multi_line = Rc::new(move |condition_context: &mut ConditionResolverContext| {361 is_multiple_lines(condition_context, start, end)362 });363364 let (children, end_comments) = children_between::<Arg>(365 self.syntax().clone(),366 self.l_paren_token().map(Into::into).as_ref(),367 self.r_paren_token().map(Into::into).as_ref(),368 None,369 );370371 fn gen_args(children: Vec<Child<Arg>>, multi_line: ConditionResolver) -> PrintItems {357 fn gen_args(children: Vec<Child<Arg>>, multi_line: ConditionResolver) -> PrintItems {372 let mut _out = PrintItems::new();358 let mut out = PrintItems::new();373 let out = &mut _out;374359375 let mut args = children.into_iter().peekable();360 let mut args = children.into_iter().peekable();376 while let Some(ele) = args.next() {361 while let Some(ele) = args.next() {377 if ele.should_start_with_newline {362 if ele.should_start_with_newline {378 p!(out, nl);363 p!(out, nl);379 }364 }380 format_comments(&ele.before_trivia, CommentLocation::AboveItem, out);365 format_comments(&ele.before_trivia, CommentLocation::AboveItem, &mut out);381 let arg = ele.value;366 let arg = ele.value;382 if arg.name().is_some() || arg.assign_token().is_some() {367 if arg.name().is_some() || arg.assign_token().is_some() {383 p!(out, {arg.name()} str(" = "));368 p!(&mut out, {arg.name()} str(" = "));384 }369 }385 p!(out, { arg.expr() });370 p!(&mut out, { arg.expr() });386 let has_more = args.peek().is_some();371 let has_more = args.peek().is_some();387 if has_more {372 if has_more {388 p!(out, str(","));373 p!(out, str(","));389 } else {374 } else {390 p!(out, if("trailing comma", multi_line, str(",")));375 p!(out, if("trailing comma", multi_line, str(",")));391 }376 }392 format_comments(&ele.inline_trivia, CommentLocation::ItemInline, out);377 format_comments(&ele.inline_trivia, CommentLocation::ItemInline, &mut out);393 if has_more {378 if has_more {394 p!(out, if_else("arg separator", multi_line, nl)(sonl));379 p!(out, if_else("arg separator", multi_line, nl)(sonl));395 }380 }396 }381 }397 _out382383 out398 }384 }385386 let start = LineNumber::new("args start line");387 let end = LineNumber::new("args end line");388 let multi_line = Rc::new(move |condition_context: &mut ConditionResolverContext| {389 is_multiple_lines(condition_context, start, end)390 });391392 let (children, end_comments) = children_between::<Arg>(393 self.syntax().clone(),394 self.l_paren_token().map(Into::into).as_ref(),395 self.r_paren_token().map(Into::into).as_ref(),396 None,397 );399398400 let args_items = new_line_group(gen_args(children, multi_line.clone())).into_rc_path();399 let args_items = new_line_group(gen_args(children, multi_line.clone())).into_rc_path();401 let args_indented = with_indent(pi!(@i; nl items(args_items.into())));400 let args_indented = with_indent(pi!(@i; nl items(args_items.into())));447}446}448447449impl Printable for ObjBody {448impl Printable for ObjBody {449 #[allow(clippy::too_many_lines)]450 fn print(&self, out: &mut PrintItems) {450 fn print(&self, out: &mut PrintItems) {451 match self {451 match self {452 Self::ObjBodyComp(l) => {452 Self::ObjBodyComp(l) => {507 p!(out, nl <i str("}"));507 p!(out, nl <i str("}"));508 }508 }509 Self::ObjBodyMemberList(l) => {509 Self::ObjBodyMemberList(l) => {510 fn gen_members(511 children: Vec<Child<Member>>,512 multi_line: ConditionResolver,513 ) -> PrintItems {514 let mut out = PrintItems::new();515 let mut members = children.into_iter().peekable();516 while let Some(mem) = members.next() {517 if mem.should_start_with_newline {518 p!(out, nl);519 }520 format_comments(&mem.before_trivia, CommentLocation::AboveItem, &mut out);521 p!(&mut out, { mem.value });522 let has_more = members.peek().is_some();523 if has_more {524 p!(out, str(","));525 } else {526 p!(out, if("trailing comma", multi_line, str(",")));527 }528 format_comments(&mem.inline_trivia, CommentLocation::ItemInline, &mut out);529 p!(out, if_else("member separator", multi_line, nl)(sonl));530 }531 out532 }533510 let (children, end_comments) = children_between::<Member>(534 let (children, end_comments) = children_between::<Member>(511 l.syntax().clone(),535 l.syntax().clone(),531 })555 })532 };556 };533534 fn gen_members(535 children: Vec<Child<Member>>,536 multi_line: ConditionResolver,537 ) -> PrintItems {538 let mut _out = PrintItems::new();539 let out = &mut _out;540 let mut members = children.into_iter().peekable();541 while let Some(mem) = members.next() {542 if mem.should_start_with_newline {543 p!(out, nl);544 }545 format_comments(&mem.before_trivia, CommentLocation::AboveItem, out);546 p!(out, { mem.value });547 let has_more = members.peek().is_some();548 if has_more {549 p!(out, str(","));550 } else {551 p!(out, if("trailing comma", multi_line, str(",")));552 }553 format_comments(&mem.inline_trivia, CommentLocation::ItemInline, out);554 p!(out, if_else("member separator", multi_line, nl)(sonl));555 }556 _out557 }558557559 let members_items =558 let members_items =560 new_line_group(gen_members(children, multi_line.clone())).into_rc_path();559 new_line_group(gen_members(children, multi_line.clone())).into_rc_path();718717719impl Printable for ExprArray {718impl Printable for ExprArray {720 fn print(&self, out: &mut PrintItems) {719 fn print(&self, out: &mut PrintItems) {720 fn gen_elements(children: Vec<Child<Expr>>, multi_line: ConditionResolver) -> PrintItems {721 let mut out = PrintItems::new();722 let mut els = children.into_iter().peekable();723 while let Some(el) = els.next() {724 if el.should_start_with_newline {725 p!(out, nl);726 }727 format_comments(&el.before_trivia, CommentLocation::AboveItem, &mut out);728 p!(&mut out, { el.value });729 let has_more = els.peek().is_some();730 if has_more {731 p!(out, str(","));732 } else {733 p!(out, if("trailing comma", multi_line, str(",")));734 }735 format_comments(&el.inline_trivia, CommentLocation::ItemInline, &mut out);736 p!(out, if_else("element separator", multi_line, nl)(sonl));737 }738 out739 }740721 let (children, end_comments) = children_between::<Expr>(741 let (children, end_comments) = children_between::<Expr>(722 self.syntax().clone(),742 self.syntax().clone(),740 Rc::new(move |ctx: &mut ConditionResolverContext| is_multiple_lines(ctx, start, end))760 Rc::new(move |ctx: &mut ConditionResolverContext| is_multiple_lines(ctx, start, end))741 };761 };742743 fn gen_elements(children: Vec<Child<Expr>>, multi_line: ConditionResolver) -> PrintItems {744 let mut _out = PrintItems::new();745 let out = &mut _out;746 let mut els = children.into_iter().peekable();747 while let Some(el) = els.next() {748 if el.should_start_with_newline {749 p!(out, nl);750 }751 format_comments(&el.before_trivia, CommentLocation::AboveItem, out);752 p!(out, { el.value });753 let has_more = els.peek().is_some();754 if has_more {755 p!(out, str(","));756 } else {757 p!(out, if("trailing comma", multi_line, str(",")));758 }759 format_comments(&el.inline_trivia, CommentLocation::ItemInline, out);760 p!(out, if_else("element separator", multi_line, nl)(sonl))761 }762 _out763 }764762765 let els_items = new_line_group(gen_elements(children, multi_line.clone())).into_rc_path();763 let els_items = new_line_group(gen_elements(children, multi_line.clone())).into_rc_path();766764800 Self::ExprString(s) => p!(out, { s.text() }),798 Self::ExprString(s) => p!(out, { s.text() }),801 Self::ExprNumber(n) => p!(out, { n.number() }),799 Self::ExprNumber(n) => p!(out, { n.number() }),802 Self::ExprArray(a) => {800 Self::ExprArray(a) => {803 p!(out, { a })801 p!(out, { a });804 }802 }805 Self::ExprObject(obj) => {803 Self::ExprObject(obj) => {806 p!(out, { obj.obj_body() });804 p!(out, { obj.obj_body() });861 pub indent: u8,859 pub indent: u8,862}860}861862#[allow(863 clippy::result_large_err,864 reason = "TODO: there should be an intermediate representation for such reports"865)]863pub fn format(input: &str, opts: &FormatOptions) -> Result<String, SnippetBuilder> {866pub fn format(input: &str, opts: &FormatOptions) -> Result<String, SnippetBuilder> {864 let (parsed, errors) = jrsonnet_rowan_parser::parse(input);867 let (parsed, errors) = jrsonnet_rowan_parser::parse(input);865 if !errors.is_empty() {868 if !errors.is_empty() {crates/jrsonnet-macros/src/typed.rsdiffbeforeafterboth--- a/crates/jrsonnet-macros/src/typed.rs
+++ b/crates/jrsonnet-macros/src/typed.rs
@@ -156,7 +156,7 @@
// optional flatten is handled in same way as serde
if self.attr.flatten {
return quote! {
- #ident: <#ty as TypedObj>::parse(&obj).ok(),
+ #ident: <#ty as ParseTypedObj>::parse(&obj).ok(),
};
}
@@ -190,7 +190,7 @@
// optional flatten is handled in same way as serde
if self.attr.flatten {
return quote! {
- #ident: <#ty as TypedObj>::parse(&obj)?,
+ #ident: <#ty as ParseTypedObj>::parse(&obj)?,
};
}
@@ -232,12 +232,12 @@
if self.is_option {
quote! {
if let Some(value) = self.#ident {
- <#ty as TypedObj>::serialize(value, out)?;
+ <#ty as SerializeTypedObj>::serialize(value, out)?;
}
}
} else {
quote! {
- <#ty as TypedObj>::serialize(self.#ident, out)?;
+ <#ty as SerializeTypedObj>::serialize(self.#ident, out)?;
}
}
},
crates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -224,7 +224,8 @@
},
#[cfg(feature = "exp-destruct")]
Object {
- fields: Vec<(IStr, Option<Destruct>, Option<Spanned<Expr>>)>,
+ #[allow(clippy::type_complexity)]
+ fields: Vec<(IStr, Option<Destruct>, Option<Rc<Spanned<Expr>>>)>,
rest: Option<DestructRest>,
},
}
@@ -261,7 +262,7 @@
let mut out = 0;
for (_, into, _) in fields {
match into {
- Some(v) => out += v.capacity_hint(),
+ Some(v) => out += v.binds_len(),
// Field is destructured to default name
None => out += 1,
}
crates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -119,7 +119,7 @@
}
pub rule destruct_object(s: &ParserSettings) -> expr::Destruct
= "{" _
- fields:(name:id() into:(_ ":" _ into:destruct(s) {into})? default:(_ "=" _ v:expr(s) {v})? {(name, into, default)})**comma()
+ fields:(name:id() into:(_ ":" _ into:destruct(s) {into})? default:(_ "=" _ v:expr(s) {v})? {(name, into, default.map(Rc::new))})**comma()
rest:(
comma() rest:destruct_rest()? {rest}
/ comma()? {None}
crates/jrsonnet-rowan-parser/src/ast.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/ast.rs
+++ b/crates/jrsonnet-rowan-parser/src/ast.rs
@@ -2,8 +2,9 @@
use crate::{SyntaxKind, SyntaxNode, SyntaxNodeChildren, SyntaxToken};
-/// The main trait to go from untyped `SyntaxNode` to a typed ast. The
-/// conversion itself has zero runtime cost: ast and syntax nodes have exactly
+/// The main trait to go from untyped `SyntaxNode` to a typed ast.
+///
+/// The conversion itself has zero runtime cost: ast and syntax nodes have exactly
/// the same representation: a pointer to the tree root and a pointer to the
/// node itself.
pub trait AstNode {
crates/jrsonnet-rowan-parser/src/event.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/event.rs
+++ b/crates/jrsonnet-rowan-parser/src/event.rs
@@ -56,7 +56,7 @@
fn text_offset(&self) -> TextSize {
if self.offset == 0 {
return 0.into();
- };
+ }
self.lexemes.get(self.offset).map_or_else(
|| {
self.lexemes
crates/jrsonnet-rowan-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/lib.rs
+++ b/crates/jrsonnet-rowan-parser/src/lib.rs
@@ -26,7 +26,7 @@
use self::{
ast::support,
- generated::nodes::{Expr, ExprBinary, ExprObjExtend},
+ generated::nodes::{Expr, ExprObjExtend},
};
pub fn parse(input: &str) -> (SourceFile, Vec<LocatedSyntaxError>) {
crates/jrsonnet-rowan-parser/src/marker.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/marker.rs
+++ b/crates/jrsonnet-rowan-parser/src/marker.rs
@@ -141,7 +141,7 @@
new_m
}
/// Create new node around existing marker
- /// If previous_pos is set - the wrapping node would not include everything that happened between wrapped node end and the current position of the parser
+ /// If `previous_pos` is set - the wrapping node would not include everything that happened between wrapped node end and the current position of the parser
fn wrap_raw(
self,
p: &mut Parser,
crates/jrsonnet-rowan-parser/src/parser.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/parser.rs
+++ b/crates/jrsonnet-rowan-parser/src/parser.rs
@@ -52,8 +52,7 @@
write!(f, "unexpected {found:?}, expecting {expected}")
}
SyntaxError::Missing { expected } => write!(f, "missing {expected}"),
- SyntaxError::Custom { error } => write!(f, "{error}"),
- SyntaxError::Hint { error } => write!(f, "{error}"),
+ SyntaxError::Custom { error } | SyntaxError::Hint { error } => write!(f, "{error}"),
}
}
}
@@ -492,7 +491,7 @@
} else {
m.complete(p, MEMBER_FIELD_NORMAL)
};
- };
+ }
while p.at_ts(COMPSPEC) {
compspecs.push(compspec(p));
}
@@ -747,7 +746,7 @@
if p.at(T![:]) {
p.bump();
destruct(p);
- };
+ }
if p.at(T![=]) {
p.bump();
expr(p);
crates/jrsonnet-rowan-parser/src/string_block.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/string_block.rs
+++ b/crates/jrsonnet-rowan-parser/src/string_block.rs
@@ -11,7 +11,7 @@
use crate::SyntaxKind;
-pub(crate) fn lex_str_block_test<'d>(lex: &mut Lexer<'d, SyntaxKind>) {
+pub(crate) fn lex_str_block_test(lex: &mut Lexer<'_, SyntaxKind>) {
let _ = lex_str_block(lex);
}
@@ -48,7 +48,7 @@
}
fn eat_if(&mut self, f: impl Fn(char) -> bool) -> usize {
- if self.peek().map(f).unwrap_or(false) {
+ if self.peek().is_some_and(f) {
self.index += 1;
return 1;
}
@@ -141,9 +141,7 @@
}
}
-pub fn collect_lexed_str_block<'s>(
- input: &'s str,
-) -> Result<CollectStrBlock<'s>, StringBlockError> {
+pub fn collect_lexed_str_block(input: &str) -> Result<CollectStrBlock<'_>, StringBlockError> {
let mut collect = CollectStrBlock {
truncate: false,
lines: vec![],
@@ -179,7 +177,7 @@
}
fn mark_line(&mut self, line: &'d str) {
- self.lines.push(line)
+ self.lines.push(line);
}
}
crates/jrsonnet-rowan-parser/src/tests.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/tests.rs
+++ b/crates/jrsonnet-rowan-parser/src/tests.rs
@@ -2,7 +2,6 @@
#![cfg(test)]
use hi_doc::{Formatting, SnippetBuilder, Text};
-use thiserror::Error;
use crate::{parse, AstNode};
@@ -14,7 +13,7 @@
if !errors.is_empty() && !text.is_empty() {
writeln!(out, "===").unwrap();
for err in &errors {
- writeln!(out, "{:?}", err).unwrap();
+ writeln!(out, "{err:?}").unwrap();
}
let mut code = text.to_string();
crates/jrsonnet-stdlib/src/regex.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/regex.rs
+++ b/crates/jrsonnet-stdlib/src/regex.rs
@@ -4,7 +4,7 @@
use jrsonnet_evaluator::{
error::{ErrorKind::*, Result},
rustc_hash::FxBuildHasher,
- typed::Typed,
+ typed::{IntoUntyped, Typed},
val::StrValue,
IStr, ObjValue, ObjValueBuilder,
};
@@ -41,7 +41,7 @@
}
}
-#[derive(Typed)]
+#[derive(Typed, IntoUntyped)]
pub struct RegexMatch {
string: IStr,
captures: Vec<IStr>,
tests/tests/common.rsdiffbeforeafterboth--- a/tests/tests/common.rs
+++ b/tests/tests/common.rs
@@ -41,6 +41,7 @@
}
#[builtin]
+#[allow(dead_code)]
fn assert_throw(lazy: Thunk<Val>, message: String) -> Result<bool> {
match lazy.evaluate() {
Ok(_) => {
@@ -55,6 +56,7 @@
}
#[builtin]
+#[allow(dead_code)]
fn param_names(fun: FuncVal) -> Vec<String> {
fun.params()
.iter()
tests/tests/typed_obj.rsdiffbeforeafterboth--- a/tests/tests/typed_obj.rs
+++ b/tests/tests/typed_obj.rs
@@ -9,7 +9,7 @@
};
use jrsonnet_stdlib::ContextInitializer;
-#[derive(Clone, Typed, PartialEq, Debug)]
+#[derive(Clone, Typed, FromUntyped, IntoUntyped, PartialEq, Debug)]
struct A {
a: u32,
b: u16,
@@ -39,7 +39,7 @@
Ok(())
}
-#[derive(Clone, Typed, PartialEq, Debug)]
+#[derive(Clone, Typed, FromUntyped, IntoUntyped, PartialEq, Debug)]
struct B {
a: u32,
#[typed(rename = "c")]
@@ -62,7 +62,7 @@
Ok(())
}
-#[derive(Clone, Typed, PartialEq, Debug)]
+#[derive(Clone, Typed, FromUntyped, IntoUntyped, PartialEq, Debug)]
struct ObjectKind {
#[typed(rename = "apiVersion")]
api_version: String,
@@ -70,7 +70,7 @@
kind: String,
}
-#[derive(Clone, Typed, PartialEq, Debug)]
+#[derive(Clone, Typed, FromUntyped, IntoUntyped, PartialEq, Debug)]
struct Object {
#[typed(flatten)]
kind: ObjectKind,
@@ -104,7 +104,7 @@
Ok(())
}
-#[derive(Clone, Typed, PartialEq, Debug)]
+#[derive(Clone, Typed, FromUntyped, IntoUntyped, PartialEq, Debug)]
struct C {
a: Option<u32>,
b: u16,
@@ -142,14 +142,14 @@
Ok(())
}
-#[derive(Clone, Typed, PartialEq, Debug)]
+#[derive(Clone, Typed, FromUntyped, IntoUntyped, PartialEq, Debug)]
struct D {
#[typed(flatten(ok))]
e: Option<E>,
b: u16,
}
-#[derive(Clone, Typed, PartialEq, Debug)]
+#[derive(Clone, Typed, FromUntyped, IntoUntyped, PartialEq, Debug)]
struct E {
v: u32,
}
xtask/src/sourcegen/mod.rsdiffbeforeafterboth--- a/xtask/src/sourcegen/mod.rs
+++ b/xtask/src/sourcegen/mod.rs
@@ -65,9 +65,9 @@
is_lexer_error: true,
});
}
- };
+ }
continue;
- };
+ }
let name = to_upper_snake_case(token);
eprintln!("implicit kw: {token}");
kinds.define_token(TokenKind::Keyword {
@@ -447,7 +447,7 @@
let trait_name = format_ident!("{}", trait_name);
let kinds: Vec<_> = nodes
.iter()
- .map(|name| format_ident!("{}", to_upper_snake_case(&name.name.to_string())))
+ .map(|name| format_ident!("{}", to_upper_snake_case(&name.name)))
.collect();
(
@@ -555,10 +555,10 @@
if "{}[]()$".contains(token) {
let c = token.chars().next().unwrap();
quote! { #c }
- } else if token.contains(|v| v == '$') {
+ } else if token.contains('$') {
quote! { #token }
- } else if token.chars().all(|v| ('a'..='z').contains(&v)) {
- let i = Ident::new(&token, Span::call_site());
+ } else if token.chars().all(|v: char| v.is_ascii_lowercase()) {
+ let i = Ident::new(token, Span::call_site());
quote! { #i }
} else {
let cs = token.chars().map(|c| Punct::new(c, Spacing::Joint));