Skip to content

Commit c1d4e74

Browse files
committed
style: ran cargo clippy --allow-dirty --fix -- -Wclippy::use_self
1 parent e64a738 commit c1d4e74

34 files changed

Lines changed: 232 additions & 254 deletions

File tree

prqlc/bindings/elixir/native/prql/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn target_from_atom(a: Atom) -> prqlc::Target {
7676
impl From<CompileOptions> for prqlc::Options {
7777
/// Get `prqlc::Options` options from `CompileOptions`
7878
fn from(o: CompileOptions) -> Self {
79-
prqlc::Options {
79+
Self {
8080
format: o.format,
8181
target: target_from_atom(o.target),
8282
signature_comment: o.signature_comment,

prqlc/bindings/prqlc-python/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl CompileOptions {
135135
color: bool,
136136
display: String,
137137
) -> Self {
138-
CompileOptions {
138+
Self {
139139
format,
140140
target,
141141
signature_comment,

prqlc/prqlc-parser/src/error.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub enum Reason {
7272

7373
impl Error {
7474
pub fn new(reason: Reason) -> Self {
75-
Error {
75+
Self {
7676
kind: MessageKind::Error,
7777
span: None,
7878
reason,
@@ -83,19 +83,19 @@ impl Error {
8383
}
8484

8585
pub fn new_simple<S: ToString>(reason: S) -> Self {
86-
Error::new(Reason::Simple(reason.to_string()))
86+
Self::new(Reason::Simple(reason.to_string()))
8787
}
8888

8989
pub fn new_bug(issue_no: i32) -> Self {
90-
Error::new(Reason::Bug {
90+
Self::new(Reason::Bug {
9191
issue: Some(issue_no),
9292
details: None,
9393
})
9494
}
9595

9696
/// Used for things that you *think* should never happen, but are not sure.
9797
pub fn new_assert<S: ToString>(details: S) -> Self {
98-
Error::new(Reason::Bug {
98+
Self::new(Reason::Bug {
9999
issue: None,
100100
details: Some(details.to_string()),
101101
})
@@ -105,8 +105,8 @@ impl Error {
105105
impl std::fmt::Display for Reason {
106106
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107107
match self {
108-
Reason::Simple(text) => f.write_str(text),
109-
Reason::Expected {
108+
Self::Simple(text) => f.write_str(text),
109+
Self::Expected {
110110
who,
111111
expected,
112112
found,
@@ -116,9 +116,9 @@ impl std::fmt::Display for Reason {
116116
}
117117
write!(f, "expected {expected}, but found {found}")
118118
}
119-
Reason::Unexpected { found } => write!(f, "unexpected {found}"),
120-
Reason::NotFound { name, namespace } => write!(f, "{namespace} `{name}` not found"),
121-
Reason::Bug { issue, details } => {
119+
Self::Unexpected { found } => write!(f, "unexpected {found}"),
120+
Self::NotFound { name, namespace } => write!(f, "{namespace} `{name}` not found"),
121+
Self::Bug { issue, details } => {
122122
write!(f, "internal compiler error")?;
123123
if let Some(details) = details {
124124
write!(f, "; {details}")?;
@@ -131,7 +131,7 @@ impl std::fmt::Display for Reason {
131131
}
132132
Ok(())
133133
}
134-
Reason::Internal { message } => {
134+
Self::Internal { message } => {
135135
write!(f, "internal error: {message}")
136136
}
137137
}
@@ -140,7 +140,7 @@ impl std::fmt::Display for Reason {
140140

141141
impl From<Error> for Errors {
142142
fn from(error: Error) -> Self {
143-
Errors(vec![error])
143+
Self(vec![error])
144144
}
145145
}
146146

prqlc/prqlc-parser/src/generic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct Range<T> {
1717

1818
impl<T> Range<T> {
1919
pub const fn unbounded() -> Self {
20-
Range {
20+
Self {
2121
start: None,
2222
end: None,
2323
}

prqlc/prqlc-parser/src/lexer/lr.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub enum Literal {
9393

9494
impl TokenKind {
9595
pub fn range(bind_left: bool, bind_right: bool) -> Self {
96-
TokenKind::Range {
96+
Self::Range {
9797
bind_left,
9898
bind_right,
9999
}
@@ -109,27 +109,27 @@ pub struct ValueAndUnit {
109109
impl std::fmt::Display for Literal {
110110
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
111111
match self {
112-
Literal::Null => write!(f, "null")?,
113-
Literal::Integer(i) => write!(f, "{i}")?,
114-
Literal::Float(i) => write!(f, "{i}")?,
112+
Self::Null => write!(f, "null")?,
113+
Self::Integer(i) => write!(f, "{i}")?,
114+
Self::Float(i) => write!(f, "{i}")?,
115115

116-
Literal::String(s) => {
116+
Self::String(s) => {
117117
write!(f, "{}", quote_string(escape_all_except_quotes(s).as_str()))?;
118118
}
119119

120-
Literal::RawString(s) => {
120+
Self::RawString(s) => {
121121
write!(f, "r{}", quote_string(s))?;
122122
}
123123

124-
Literal::Boolean(b) => {
124+
Self::Boolean(b) => {
125125
f.write_str(if *b { "true" } else { "false" })?;
126126
}
127127

128-
Literal::Date(inner) | Literal::Time(inner) | Literal::Timestamp(inner) => {
128+
Self::Date(inner) | Self::Time(inner) | Self::Timestamp(inner) => {
129129
write!(f, "@{inner}")?;
130130
}
131131

132-
Literal::ValueAndUnit(i) => {
132+
Self::ValueAndUnit(i) => {
133133
write!(f, "{}{}", i.n, i.unit)?;
134134
}
135135
}
@@ -206,36 +206,36 @@ impl std::cmp::Eq for TokenKind {}
206206
impl std::fmt::Display for TokenKind {
207207
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
208208
match self {
209-
TokenKind::NewLine => write!(f, "new line"),
210-
TokenKind::Ident(s) => {
209+
Self::NewLine => write!(f, "new line"),
210+
Self::Ident(s) => {
211211
if s.is_empty() {
212212
// FYI this shows up in errors
213213
write!(f, "an identifier")
214214
} else {
215215
write!(f, "{s}")
216216
}
217217
}
218-
TokenKind::Keyword(s) => write!(f, "keyword {s}"),
219-
TokenKind::Literal(lit) => write!(f, "{lit}"),
220-
TokenKind::Control(c) => write!(f, "{c}"),
221-
222-
TokenKind::ArrowThin => f.write_str("->"),
223-
TokenKind::ArrowFat => f.write_str("=>"),
224-
TokenKind::Eq => f.write_str("=="),
225-
TokenKind::Ne => f.write_str("!="),
226-
TokenKind::Gte => f.write_str(">="),
227-
TokenKind::Lte => f.write_str("<="),
228-
TokenKind::RegexSearch => f.write_str("~="),
229-
TokenKind::And => f.write_str("&&"),
230-
TokenKind::Or => f.write_str("||"),
231-
TokenKind::Coalesce => f.write_str("??"),
232-
TokenKind::DivInt => f.write_str("//"),
233-
TokenKind::Pow => f.write_str("**"),
234-
TokenKind::Annotate => f.write_str("@{"),
235-
236-
TokenKind::Param(id) => write!(f, "${id}"),
237-
238-
TokenKind::Range {
218+
Self::Keyword(s) => write!(f, "keyword {s}"),
219+
Self::Literal(lit) => write!(f, "{lit}"),
220+
Self::Control(c) => write!(f, "{c}"),
221+
222+
Self::ArrowThin => f.write_str("->"),
223+
Self::ArrowFat => f.write_str("=>"),
224+
Self::Eq => f.write_str("=="),
225+
Self::Ne => f.write_str("!="),
226+
Self::Gte => f.write_str(">="),
227+
Self::Lte => f.write_str("<="),
228+
Self::RegexSearch => f.write_str("~="),
229+
Self::And => f.write_str("&&"),
230+
Self::Or => f.write_str("||"),
231+
Self::Coalesce => f.write_str("??"),
232+
Self::DivInt => f.write_str("//"),
233+
Self::Pow => f.write_str("**"),
234+
Self::Annotate => f.write_str("@{"),
235+
236+
Self::Param(id) => write!(f, "${id}"),
237+
238+
Self::Range {
239239
bind_left,
240240
bind_right,
241241
} => write!(
@@ -244,23 +244,23 @@ impl std::fmt::Display for TokenKind {
244244
if *bind_left { "" } else { " " },
245245
if *bind_right { "" } else { " " }
246246
),
247-
TokenKind::Interpolation(c, s) => {
247+
Self::Interpolation(c, s) => {
248248
write!(f, "{c}\"{s}\"")
249249
}
250-
TokenKind::Comment(s) => {
250+
Self::Comment(s) => {
251251
writeln!(f, "#{s}")
252252
}
253-
TokenKind::DocComment(s) => {
253+
Self::DocComment(s) => {
254254
writeln!(f, "#!{s}")
255255
}
256-
TokenKind::LineWrap(comments) => {
256+
Self::LineWrap(comments) => {
257257
write!(f, "\n\\ ")?;
258258
for comment in comments {
259259
write!(f, "{comment}")?;
260260
}
261261
Ok(())
262262
}
263-
TokenKind::Start => write!(f, "start of input"),
263+
Self::Start => write!(f, "start of input"),
264264
}
265265
}
266266
}

prqlc/prqlc-parser/src/parser/perror.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ where
8383
}
8484

8585
impl<'a> From<Rich<'a, crate::lexer::lr::Token, Span>> for Error {
86-
fn from(rich: Rich<'a, crate::lexer::lr::Token, Span>) -> Error {
86+
fn from(rich: Rich<'a, crate::lexer::lr::Token, Span>) -> Self {
8787
rich_error_to_error(
8888
*rich.span(),
8989
rich.reason(),
@@ -94,7 +94,7 @@ impl<'a> From<Rich<'a, crate::lexer::lr::Token, Span>> for Error {
9494
}
9595

9696
impl<'a> From<Rich<'a, TokenKind, Span>> for Error {
97-
fn from(rich: Rich<'a, TokenKind, Span>) -> Error {
97+
fn from(rich: Rich<'a, TokenKind, Span>) -> Self {
9898
rich_error_to_error(
9999
*rich.span(),
100100
rich.reason(),

prqlc/prqlc-parser/src/parser/pr/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{generic, parser::SupportsDocComment};
1212

1313
impl Expr {
1414
pub fn new<K: Into<ExprKind>>(kind: K) -> Self {
15-
Expr {
15+
Self {
1616
kind: kind.into(),
1717
span: None,
1818
alias: None,
@@ -171,12 +171,12 @@ pub type SwitchCase = generic::SwitchCase<Box<Expr>>;
171171

172172
impl From<Literal> for ExprKind {
173173
fn from(value: Literal) -> Self {
174-
ExprKind::Literal(value)
174+
Self::Literal(value)
175175
}
176176
}
177177

178178
impl From<Func> for ExprKind {
179179
fn from(value: Func) -> Self {
180-
ExprKind::Func(Box::new(value))
180+
Self::Func(Box::new(value))
181181
}
182182
}

prqlc/prqlc-parser/src/parser/pr/ident.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct Ident {
1313

1414
impl Ident {
1515
pub fn from_name<S: ToString>(name: S) -> Self {
16-
Ident {
16+
Self {
1717
path: Vec::new(),
1818
name: name.to_string(),
1919
}
@@ -24,7 +24,7 @@ impl Ident {
2424
/// Panics if path is empty.
2525
pub fn from_path<S: ToString>(mut path: Vec<S>) -> Self {
2626
let name = path.pop().unwrap().to_string();
27-
Ident {
27+
Self {
2828
path: path.into_iter().map(|x| x.to_string()).collect(),
2929
name,
3030
}
@@ -42,10 +42,10 @@ impl Ident {
4242
/// Result will generally refer to the parent of this ident.
4343
pub fn pop(self) -> Option<Self> {
4444
let mut path = self.path;
45-
path.pop().map(|name| Ident { path, name })
45+
path.pop().map(|name| Self { path, name })
4646
}
4747

48-
pub fn pop_front(mut self) -> (String, Option<Ident>) {
48+
pub fn pop_front(mut self) -> (String, Option<Self>) {
4949
if self.path.is_empty() {
5050
(self.name, None)
5151
} else {
@@ -54,9 +54,9 @@ impl Ident {
5454
}
5555
}
5656

57-
pub fn prepend(self, mut parts: Vec<String>) -> Ident {
57+
pub fn prepend(self, mut parts: Vec<String>) -> Self {
5858
parts.extend(self);
59-
Ident::from_path(parts)
59+
Self::from_path(parts)
6060
}
6161

6262
pub fn push(&mut self, name: String) {
@@ -73,7 +73,7 @@ impl Ident {
7373
self.path.iter().chain(std::iter::once(&self.name))
7474
}
7575

76-
pub fn starts_with(&self, prefix: &Ident) -> bool {
76+
pub fn starts_with(&self, prefix: &Self) -> bool {
7777
if prefix.len() > self.len() {
7878
return false;
7979
}
@@ -126,11 +126,11 @@ impl IntoIterator for Ident {
126126
}
127127
}
128128

129-
impl std::ops::Add<Ident> for Ident {
130-
type Output = Ident;
129+
impl std::ops::Add<Self> for Ident {
130+
type Output = Self;
131131

132-
fn add(self, rhs: Ident) -> Self::Output {
133-
Ident {
132+
fn add(self, rhs: Self) -> Self::Output {
133+
Self {
134134
path: self.into_iter().chain(rhs.path).collect(),
135135
name: rhs.name,
136136
}
@@ -156,7 +156,7 @@ impl<'de> Deserialize<'de> for Ident {
156156
where
157157
D: Deserializer<'de>,
158158
{
159-
<Vec<String> as Deserialize>::deserialize(deserializer).map(Ident::from_path)
159+
<Vec<String> as Deserialize>::deserialize(deserializer).map(Self::from_path)
160160
}
161161
}
162162

prqlc/prqlc-parser/src/parser/pr/stmt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub struct Stmt {
4141

4242
impl SupportsDocComment for Stmt {
4343
fn with_doc_comment(self, doc_comment: Option<String>) -> Self {
44-
Stmt {
44+
Self {
4545
doc_comment,
4646
..self
4747
}
@@ -91,8 +91,8 @@ pub struct Annotation {
9191
}
9292

9393
impl Stmt {
94-
pub fn new(kind: StmtKind) -> Stmt {
95-
Stmt {
94+
pub fn new(kind: StmtKind) -> Self {
95+
Self {
9696
kind,
9797
span: None,
9898
annotations: Vec::new(),

0 commit comments

Comments
 (0)