summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--macros/src/element.rs2
-rw-r--r--macros/src/func.rs2
-rw-r--r--src/eval/func.rs2
-rw-r--r--src/eval/methods.rs4
-rw-r--r--src/eval/mod.rs4
-rw-r--r--src/eval/module.rs2
-rw-r--r--src/eval/str.rs2
-rw-r--r--src/eval/symbol.rs2
-rw-r--r--src/eval/value.rs17
-rw-r--r--src/ide/complete.rs12
-rw-r--r--src/ide/tooltip.rs2
-rw-r--r--src/model/introspect.rs4
-rw-r--r--src/model/styles.rs4
-rw-r--r--src/syntax/lexer.rs6
-rw-r--r--src/syntax/reparser.rs4
-rw-r--r--src/syntax/source.rs2
-rw-r--r--src/util/mod.rs2
17 files changed, 32 insertions, 41 deletions
diff --git a/macros/src/element.rs b/macros/src/element.rs
index 9d6b5c88..dd837754 100644
--- a/macros/src/element.rs
+++ b/macros/src/element.rs
@@ -138,7 +138,7 @@ fn prepare(stream: TokenStream, body: &syn::ItemStruct) -> Result<Elem> {
.collect();
let docs = documentation(&body.attrs);
- let mut lines = docs.split("\n").collect();
+ let mut lines = docs.split('\n').collect();
let category = meta_line(&mut lines, "Category")?.into();
let display = meta_line(&mut lines, "Display")?.into();
let docs = lines.join("\n").trim().into();
diff --git a/macros/src/func.rs b/macros/src/func.rs
index 07ecdd78..386ed7c4 100644
--- a/macros/src/func.rs
+++ b/macros/src/func.rs
@@ -73,7 +73,7 @@ fn prepare(item: &syn::ItemFn) -> Result<Func> {
}
let docs = documentation(&item.attrs);
- let mut lines = docs.split("\n").collect();
+ let mut lines = docs.split('\n').collect();
let returns = meta_line(&mut lines, "Returns")?
.split(" or ")
.map(Into::into)
diff --git a/src/eval/func.rs b/src/eval/func.rs
index 08296320..e1472cca 100644
--- a/src/eval/func.rs
+++ b/src/eval/func.rs
@@ -115,7 +115,7 @@ impl Func {
}
Repr::With(arc) => {
args.items = arc.1.items.iter().cloned().chain(args.items).collect();
- return arc.0.call_vm(vm, args);
+ arc.0.call_vm(vm, args)
}
}
}
diff --git a/src/eval/methods.rs b/src/eval/methods.rs
index 72245fb0..bfe9b0e4 100644
--- a/src/eval/methods.rs
+++ b/src/eval/methods.rs
@@ -27,7 +27,7 @@ pub fn call(
},
Value::Str(string) => match method {
- "len" => Value::Int(string.len() as i64),
+ "len" => Value::Int(string.len()),
"first" => Value::Str(string.first().at(span)?),
"last" => Value::Str(string.last().at(span)?),
"at" => Value::Str(string.at(args.expect("index")?).at(span)?),
@@ -73,7 +73,7 @@ pub fn call(
Value::Content(content) => match method {
"func" => content.func().into(),
"has" => Value::Bool(content.has(&args.expect::<EcoString>("field")?)),
- "at" => content.at(&args.expect::<EcoString>("field")?).at(span)?.clone(),
+ "at" => content.at(&args.expect::<EcoString>("field")?).at(span)?,
"location" => content
.location()
.ok_or("this method can only be called on content returned by query(..)")
diff --git a/src/eval/mod.rs b/src/eval/mod.rs
index f19e4305..8790bc18 100644
--- a/src/eval/mod.rs
+++ b/src/eval/mod.rs
@@ -652,7 +652,7 @@ impl Eval for ast::MathIdent {
type Output = Value;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
- Ok(vm.scopes.get_in_math(self).cloned().at(self.span())?)
+ vm.scopes.get_in_math(self).cloned().at(self.span())
}
}
@@ -700,7 +700,7 @@ impl Eval for ast::Ident {
type Output = Value;
fn eval(&self, vm: &mut Vm) -> SourceResult<Self::Output> {
- Ok(vm.scopes.get(self).cloned().at(self.span())?)
+ vm.scopes.get(self).cloned().at(self.span())
}
}
diff --git a/src/eval/module.rs b/src/eval/module.rs
index e911d859..feb5a14b 100644
--- a/src/eval/module.rs
+++ b/src/eval/module.rs
@@ -60,7 +60,7 @@ impl Module {
/// Try to access a definition in the module.
pub fn get(&self, name: &str) -> StrResult<&Value> {
- self.scope().get(&name).ok_or_else(|| {
+ self.scope().get(name).ok_or_else(|| {
eco_format!("module `{}` does not contain `{name}`", self.name())
})
}
diff --git a/src/eval/str.rs b/src/eval/str.rs
index b1551564..d867e19c 100644
--- a/src/eval/str.rs
+++ b/src/eval/str.rs
@@ -118,7 +118,7 @@ impl Str {
/// The text of the pattern's first match in this string.
pub fn find(&self, pattern: StrPattern) -> Option<Self> {
match pattern {
- StrPattern::Str(pat) => self.0.contains(pat.as_str()).then(|| pat),
+ StrPattern::Str(pat) => self.0.contains(pat.as_str()).then_some(pat),
StrPattern::Regex(re) => re.find(self).map(|m| m.as_str().into()),
}
}
diff --git a/src/eval/symbol.rs b/src/eval/symbol.rs
index d15d5a79..5c8951b1 100644
--- a/src/eval/symbol.rs
+++ b/src/eval/symbol.rs
@@ -70,7 +70,7 @@ impl Symbol {
modifiers.push('.');
}
modifiers.push_str(modifier);
- if find(list.variants(), &modifiers).is_some() {
+ if find(list.variants(), modifiers).is_some() {
return Ok(self);
}
}
diff --git a/src/eval/value.rs b/src/eval/value.rs
index bf1dd18a..517cadc5 100644
--- a/src/eval/value.rs
+++ b/src/eval/value.rs
@@ -17,9 +17,10 @@ use crate::model::Styles;
use crate::syntax::{ast, Span};
/// A computational value.
-#[derive(Clone)]
+#[derive(Clone, Default)]
pub enum Value {
/// The value that indicates the absence of a meaningful value.
+ #[default]
None,
/// A value that indicates some smart default behaviour.
Auto,
@@ -122,10 +123,10 @@ impl Value {
/// Try to access a field on the value.
pub fn field(&self, field: &str) -> StrResult<Value> {
match self {
- Self::Symbol(symbol) => symbol.clone().modified(&field).map(Self::Symbol),
- Self::Dict(dict) => dict.at(&field).cloned(),
- Self::Content(content) => content.at(&field),
- Self::Module(module) => module.get(&field).cloned(),
+ Self::Symbol(symbol) => symbol.clone().modified(field).map(Self::Symbol),
+ Self::Dict(dict) => dict.at(field).cloned(),
+ Self::Content(content) => content.at(field),
+ Self::Module(module) => module.get(field).cloned(),
v => Err(eco_format!("cannot access fields on type {}", v.type_name())),
}
}
@@ -168,12 +169,6 @@ impl Value {
}
}
-impl Default for Value {
- fn default() -> Self {
- Value::None
- }
-}
-
impl Debug for Value {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
diff --git a/src/ide/complete.rs b/src/ide/complete.rs
index 4dacc2b2..27b199fd 100644
--- a/src/ide/complete.rs
+++ b/src/ide/complete.rs
@@ -122,7 +122,7 @@ fn complete_markup(ctx: &mut CompletionContext) -> bool {
}
// Directly after a raw block.
- let mut s = Scanner::new(&ctx.text);
+ let mut s = Scanner::new(ctx.text);
s.jump(ctx.leaf.offset());
if s.eat_if("```") {
s.eat_while('`');
@@ -651,7 +651,7 @@ fn param_completions(
kind: CompletionKind::Param,
label: param.name.into(),
apply: Some(eco_format!("{}: ${{}}", param.name)),
- detail: Some(plain_docs_sentence(param.docs).into()),
+ detail: Some(plain_docs_sentence(param.docs)),
});
}
@@ -896,8 +896,8 @@ impl<'a> CompletionContext<'a> {
frames,
library,
source,
- global: &library.global.scope(),
- math: &library.math.scope(),
+ global: library.global.scope(),
+ math: library.math.scope(),
text,
before: &text[..cursor],
after: &text[cursor..],
@@ -1002,9 +1002,7 @@ impl<'a> CompletionContext<'a> {
let detail = docs.map(Into::into).or_else(|| match value {
Value::Symbol(_) => None,
- Value::Func(func) => {
- func.info().map(|info| plain_docs_sentence(info.docs).into())
- }
+ Value::Func(func) => func.info().map(|info| plain_docs_sentence(info.docs)),
v => Some(v.repr().into()),
});
diff --git a/src/ide/tooltip.rs b/src/ide/tooltip.rs
index b17a1acc..35125e92 100644
--- a/src/ide/tooltip.rs
+++ b/src/ide/tooltip.rs
@@ -126,7 +126,7 @@ fn ref_tooltip(
let target = leaf.text().trim_start_matches('@');
for (label, detail) in analyze_labels(world, frames).0 {
if label.0 == target {
- return Some(Tooltip::Text(detail?.into()));
+ return Some(Tooltip::Text(detail?));
}
}
diff --git a/src/model/introspect.rs b/src/model/introspect.rs
index 2bd44ce1..f0ff1169 100644
--- a/src/model/introspect.rs
+++ b/src/model/introspect.rs
@@ -43,7 +43,7 @@ cast_from_value! {
}
/// Provides stable identities to elements.
-#[derive(Clone)]
+#[derive(Clone, Default)]
pub struct StabilityProvider {
hashes: Vec<u128>,
checkpoints: Vec<usize>,
@@ -52,7 +52,7 @@ pub struct StabilityProvider {
impl StabilityProvider {
/// Create a new stability provider.
pub fn new() -> Self {
- Self { hashes: vec![], checkpoints: vec![] }
+ Self::default()
}
}
diff --git a/src/model/styles.rs b/src/model/styles.rs
index db2b2053..82ec2ed5 100644
--- a/src/model/styles.rs
+++ b/src/model/styles.rs
@@ -71,8 +71,8 @@ impl Styles {
pub fn interruption<T: Element>(&self) -> Option<Option<Span>> {
let func = T::func();
self.0.iter().find_map(|entry| match entry {
- Style::Property(property) => property.is_of(func).then(|| property.span),
- Style::Recipe(recipe) => recipe.is_of(func).then(|| Some(recipe.span)),
+ Style::Property(property) => property.is_of(func).then_some(property.span),
+ Style::Recipe(recipe) => recipe.is_of(func).then_some(Some(recipe.span)),
})
}
}
diff --git a/src/syntax/lexer.rs b/src/syntax/lexer.rs
index 43a4872b..a5e4a9e0 100644
--- a/src/syntax/lexer.rs
+++ b/src/syntax/lexer.rs
@@ -284,10 +284,8 @@ impl Lexer<'_> {
self.s.eat_while(char::is_ascii_digit);
let read = self.s.from(start);
- if self.s.eat_if('.') && self.space_or_end() {
- if read.parse::<usize>().is_ok() {
- return SyntaxKind::EnumMarker;
- }
+ if self.s.eat_if('.') && self.space_or_end() && read.parse::<usize>().is_ok() {
+ return SyntaxKind::EnumMarker;
}
self.text()
diff --git a/src/syntax/reparser.rs b/src/syntax/reparser.rs
index 75a5cc27..18960941 100644
--- a/src/syntax/reparser.rs
+++ b/src/syntax/reparser.rs
@@ -72,7 +72,7 @@ fn try_reparse(
return node
.replace_children(i..i + 1, vec![newborn])
.is_ok()
- .then(|| new_range);
+ .then_some(new_range);
}
}
}
@@ -157,7 +157,7 @@ fn try_reparse(
return node
.replace_children(start..end, newborns)
.is_ok()
- .then(|| new_range);
+ .then_some(new_range);
}
}
}
diff --git a/src/syntax/source.rs b/src/syntax/source.rs
index e8553b1e..233fb367 100644
--- a/src/syntax/source.rs
+++ b/src/syntax/source.rs
@@ -212,7 +212,7 @@ impl Source {
k += c.len_utf16();
}
- (k == utf16_idx).then(|| self.text.len())
+ (k == utf16_idx).then_some(self.text.len())
}
/// Return the byte position at which the given line starts.
diff --git a/src/util/mod.rs b/src/util/mod.rs
index 3e0e7aa2..c2b23273 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -205,7 +205,7 @@ pub fn pretty_comma_list(pieces: &[impl AsRef<str>], trailing_comma: bool) -> St
/// Tries to format horizontally, but falls back to vertical formatting if the
/// pieces are too long.
pub fn pretty_array_like(parts: &[impl AsRef<str>], trailing_comma: bool) -> String {
- let list = pretty_comma_list(&parts, trailing_comma);
+ let list = pretty_comma_list(parts, trailing_comma);
let mut buf = String::new();
buf.push('(');
if list.contains('\n') {