Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

refactor(core): callee should construct `Box`

Elijah Pottera99f5f17c9db
diff --git a/harper-core/src/linting/back_in_the_day.rs b/harper-core/src/linting/back_in_the_day.rs
index 814a5d335..c28cd5c9d 100644
--- a/harper-core/src/linting/back_in_the_day.rs
+++ b/harper-core/src/linting/back_in_the_day.rs
@@ -20,7 +20,7 @@ impl Default for BackInTheDay {
.then(phrase.clone())
.then_whitespace()
.then(exceptions.clone())
- .or(Box::new(phrase));
+ .or(phrase);
Self {
pattern: Box::new(pattern),
diff --git a/harper-core/src/linting/confident.rs b/harper-core/src/linting/confident.rs
index 7150131a0..c7e7a7681 100644
--- a/harper-core/src/linting/confident.rs
+++ b/harper-core/src/linting/confident.rs
@@ -14,7 +14,7 @@ impl Default for Confident {
let pattern = SequencePattern::default()
.then(
(|tok: &Token, _source: &[char]| tok.kind.is_verb() || tok.kind.is_determiner())
- .or(Box::new(Word::new("very"))),
+ .or(Word::new("very")),
)
.then_whitespace()
.t_aco("confidant");
diff --git a/harper-core/src/linting/else_possessive.rs b/harper-core/src/linting/else_possessive.rs
index b93bd3550..8bc7f5c96 100644
--- a/harper-core/src/linting/else_possessive.rs
+++ b/harper-core/src/linting/else_possessive.rs
@@ -19,9 +19,7 @@ impl Default for ElsePossessive {
"everyone",
"nobody",
])
- .or(Box::new(
- SequencePattern::aco("no").then_whitespace().t_aco("one"),
- ));
+ .or(SequencePattern::aco("no").then_whitespace().t_aco("one"));
let pattern = SequencePattern::default()
.then(pronouns)
diff --git a/harper-core/src/linting/for_noun.rs b/harper-core/src/linting/for_noun.rs
index 6e17f710e..92fbad9d3 100644
--- a/harper-core/src/linting/for_noun.rs
+++ b/harper-core/src/linting/for_noun.rs
@@ -13,7 +13,7 @@ impl Default for ForNoun {
fn default() -> Self {
let pattern = SequencePattern::aco("fro")
.then_whitespace()
- .then(NominalPhrase.or(Box::new(Word::new("sure"))));
+ .then(NominalPhrase.or(Word::new("sure")));
Self {
pattern: Box::new(pattern),
diff --git a/harper-core/src/linting/it_would_be.rs b/harper-core/src/linting/it_would_be.rs
index 098f83ae5..d47966602 100644
--- a/harper-core/src/linting/it_would_be.rs
+++ b/harper-core/src/linting/it_would_be.rs
@@ -50,9 +50,9 @@ impl Default for ItWouldBe {
};
let combined = branch(false, false)
- .or(Box::new(branch(false, true)))
- .or(Box::new(branch(true, false)))
- .or(Box::new(branch(true, true)));
+ .or(branch(false, true))
+ .or(branch(true, false))
+ .or(branch(true, true));
Self {
pattern: Box::new(combined),
diff --git a/harper-core/src/linting/oxford_comma.rs b/harper-core/src/linting/oxford_comma.rs
index fc4444ba5..6d58ec9f3 100644
--- a/harper-core/src/linting/oxford_comma.rs
+++ b/harper-core/src/linting/oxford_comma.rs
@@ -17,7 +17,7 @@ impl Default for OxfordComma {
.then_determiner()
.then_whitespace()
.then_nominal()
- .or(Box::new(SequencePattern::default().then_nominal())),
+ .or(SequencePattern::default().then_nominal()),
);
let item_chunk = SequencePattern::default()
diff --git a/harper-core/src/linting/save_to_safe.rs b/harper-core/src/linting/save_to_safe.rs
index 2da392635..caa8bd8f1 100644
--- a/harper-core/src/linting/save_to_safe.rs
+++ b/harper-core/src/linting/save_to_safe.rs
@@ -11,7 +11,7 @@ pub struct SaveToSafe {
impl Default for SaveToSafe {
fn default() -> Self {
let pattern = SequencePattern::default()
- .then(InflectionOfBe::new().or(Box::new(Word::new("it"))))
+ .then(InflectionOfBe::new().or(Word::new("it")))
.then_whitespace()
.t_aco("save")
.then_whitespace()
diff --git a/harper-core/src/linting/win_prize.rs b/harper-core/src/linting/win_prize.rs
index 3a52ae1dc..821f62fc3 100644
--- a/harper-core/src/linting/win_prize.rs
+++ b/harper-core/src/linting/win_prize.rs
@@ -19,12 +19,10 @@ impl Default for WinPrize {
.then_determiner()
.then_whitespace()
.then(miss.clone())
- .or(Box::new(
- SequencePattern::default()
- .then(verbs)
- .then_whitespace()
- .then(miss),
- ));
+ .or(SequencePattern::default()
+ .then(verbs)
+ .then_whitespace()
+ .then(miss));
Self {
pattern: Box::new(pattern),
diff --git a/harper-core/src/patterns/mod.rs b/harper-core/src/patterns/mod.rs
index 40c858d98..73842d97d 100644
--- a/harper-core/src/patterns/mod.rs
+++ b/harper-core/src/patterns/mod.rs
@@ -120,15 +120,15 @@ where
}
pub trait OwnedPatternExt {
- fn or(self, other: Box<dyn Pattern>) -> EitherPattern;
+ fn or(self, other: impl Pattern + 'static) -> EitherPattern;
}
impl<P> OwnedPatternExt for P
where
P: Pattern + 'static,
{
- fn or(self, other: Box<dyn Pattern>) -> EitherPattern {
- EitherPattern::new(vec![Box::new(self), other])
+ fn or(self, other: impl Pattern + 'static) -> EitherPattern {
+ EitherPattern::new(vec![Box::new(self), Box::new(other)])
}
}