diff --git a/prqlc/bindings/elixir/native/prql/src/lib.rs b/prqlc/bindings/elixir/native/prql/src/lib.rs index 186bb24c8a53..9885fa0af874 100644 --- a/prqlc/bindings/elixir/native/prql/src/lib.rs +++ b/prqlc/bindings/elixir/native/prql/src/lib.rs @@ -76,7 +76,7 @@ fn target_from_atom(a: Atom) -> prqlc::Target { impl From for prqlc::Options { /// Get `prqlc::Options` options from `CompileOptions` fn from(o: CompileOptions) -> Self { - prqlc::Options { + Self { format: o.format, target: target_from_atom(o.target), signature_comment: o.signature_comment, diff --git a/prqlc/bindings/prqlc-python/src/lib.rs b/prqlc/bindings/prqlc-python/src/lib.rs index 181805b18e6a..ae591bed198b 100644 --- a/prqlc/bindings/prqlc-python/src/lib.rs +++ b/prqlc/bindings/prqlc-python/src/lib.rs @@ -135,7 +135,7 @@ impl CompileOptions { color: bool, display: String, ) -> Self { - CompileOptions { + Self { format, target, signature_comment, diff --git a/prqlc/prqlc-parser/src/error.rs b/prqlc/prqlc-parser/src/error.rs index 58b6838251a6..3d55d96e754f 100644 --- a/prqlc/prqlc-parser/src/error.rs +++ b/prqlc/prqlc-parser/src/error.rs @@ -72,7 +72,7 @@ pub enum Reason { impl Error { pub fn new(reason: Reason) -> Self { - Error { + Self { kind: MessageKind::Error, span: None, reason, @@ -83,11 +83,11 @@ impl Error { } pub fn new_simple(reason: S) -> Self { - Error::new(Reason::Simple(reason.to_string())) + Self::new(Reason::Simple(reason.to_string())) } pub fn new_bug(issue_no: i32) -> Self { - Error::new(Reason::Bug { + Self::new(Reason::Bug { issue: Some(issue_no), details: None, }) @@ -95,7 +95,7 @@ impl Error { /// Used for things that you *think* should never happen, but are not sure. pub fn new_assert(details: S) -> Self { - Error::new(Reason::Bug { + Self::new(Reason::Bug { issue: None, details: Some(details.to_string()), }) @@ -105,8 +105,8 @@ impl Error { impl std::fmt::Display for Reason { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Reason::Simple(text) => f.write_str(text), - Reason::Expected { + Self::Simple(text) => f.write_str(text), + Self::Expected { who, expected, found, @@ -116,9 +116,9 @@ impl std::fmt::Display for Reason { } write!(f, "expected {expected}, but found {found}") } - Reason::Unexpected { found } => write!(f, "unexpected {found}"), - Reason::NotFound { name, namespace } => write!(f, "{namespace} `{name}` not found"), - Reason::Bug { issue, details } => { + Self::Unexpected { found } => write!(f, "unexpected {found}"), + Self::NotFound { name, namespace } => write!(f, "{namespace} `{name}` not found"), + Self::Bug { issue, details } => { write!(f, "internal compiler error")?; if let Some(details) = details { write!(f, "; {details}")?; @@ -131,7 +131,7 @@ impl std::fmt::Display for Reason { } Ok(()) } - Reason::Internal { message } => { + Self::Internal { message } => { write!(f, "internal error: {message}") } } @@ -140,7 +140,7 @@ impl std::fmt::Display for Reason { impl From for Errors { fn from(error: Error) -> Self { - Errors(vec![error]) + Self(vec![error]) } } diff --git a/prqlc/prqlc-parser/src/generic.rs b/prqlc/prqlc-parser/src/generic.rs index 859ba028874e..ecaf391740c6 100644 --- a/prqlc/prqlc-parser/src/generic.rs +++ b/prqlc/prqlc-parser/src/generic.rs @@ -17,7 +17,7 @@ pub struct Range { impl Range { pub const fn unbounded() -> Self { - Range { + Self { start: None, end: None, } diff --git a/prqlc/prqlc-parser/src/lexer/lr.rs b/prqlc/prqlc-parser/src/lexer/lr.rs index a33bac1c8574..86841f669f59 100644 --- a/prqlc/prqlc-parser/src/lexer/lr.rs +++ b/prqlc/prqlc-parser/src/lexer/lr.rs @@ -93,7 +93,7 @@ pub enum Literal { impl TokenKind { pub fn range(bind_left: bool, bind_right: bool) -> Self { - TokenKind::Range { + Self::Range { bind_left, bind_right, } @@ -109,27 +109,27 @@ pub struct ValueAndUnit { impl std::fmt::Display for Literal { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Literal::Null => write!(f, "null")?, - Literal::Integer(i) => write!(f, "{i}")?, - Literal::Float(i) => write!(f, "{i}")?, + Self::Null => write!(f, "null")?, + Self::Integer(i) => write!(f, "{i}")?, + Self::Float(i) => write!(f, "{i}")?, - Literal::String(s) => { + Self::String(s) => { write!(f, "{}", quote_string(escape_all_except_quotes(s).as_str()))?; } - Literal::RawString(s) => { + Self::RawString(s) => { write!(f, "r{}", quote_string(s))?; } - Literal::Boolean(b) => { + Self::Boolean(b) => { f.write_str(if *b { "true" } else { "false" })?; } - Literal::Date(inner) | Literal::Time(inner) | Literal::Timestamp(inner) => { + Self::Date(inner) | Self::Time(inner) | Self::Timestamp(inner) => { write!(f, "@{inner}")?; } - Literal::ValueAndUnit(i) => { + Self::ValueAndUnit(i) => { write!(f, "{}{}", i.n, i.unit)?; } } @@ -206,8 +206,8 @@ impl std::cmp::Eq for TokenKind {} impl std::fmt::Display for TokenKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - TokenKind::NewLine => write!(f, "new line"), - TokenKind::Ident(s) => { + Self::NewLine => write!(f, "new line"), + Self::Ident(s) => { if s.is_empty() { // FYI this shows up in errors write!(f, "an identifier") @@ -215,27 +215,27 @@ impl std::fmt::Display for TokenKind { write!(f, "{s}") } } - TokenKind::Keyword(s) => write!(f, "keyword {s}"), - TokenKind::Literal(lit) => write!(f, "{lit}"), - TokenKind::Control(c) => write!(f, "{c}"), - - TokenKind::ArrowThin => f.write_str("->"), - TokenKind::ArrowFat => f.write_str("=>"), - TokenKind::Eq => f.write_str("=="), - TokenKind::Ne => f.write_str("!="), - TokenKind::Gte => f.write_str(">="), - TokenKind::Lte => f.write_str("<="), - TokenKind::RegexSearch => f.write_str("~="), - TokenKind::And => f.write_str("&&"), - TokenKind::Or => f.write_str("||"), - TokenKind::Coalesce => f.write_str("??"), - TokenKind::DivInt => f.write_str("//"), - TokenKind::Pow => f.write_str("**"), - TokenKind::Annotate => f.write_str("@{"), - - TokenKind::Param(id) => write!(f, "${id}"), - - TokenKind::Range { + Self::Keyword(s) => write!(f, "keyword {s}"), + Self::Literal(lit) => write!(f, "{lit}"), + Self::Control(c) => write!(f, "{c}"), + + Self::ArrowThin => f.write_str("->"), + Self::ArrowFat => f.write_str("=>"), + Self::Eq => f.write_str("=="), + Self::Ne => f.write_str("!="), + Self::Gte => f.write_str(">="), + Self::Lte => f.write_str("<="), + Self::RegexSearch => f.write_str("~="), + Self::And => f.write_str("&&"), + Self::Or => f.write_str("||"), + Self::Coalesce => f.write_str("??"), + Self::DivInt => f.write_str("//"), + Self::Pow => f.write_str("**"), + Self::Annotate => f.write_str("@{"), + + Self::Param(id) => write!(f, "${id}"), + + Self::Range { bind_left, bind_right, } => write!( @@ -244,23 +244,23 @@ impl std::fmt::Display for TokenKind { if *bind_left { "" } else { " " }, if *bind_right { "" } else { " " } ), - TokenKind::Interpolation(c, s) => { + Self::Interpolation(c, s) => { write!(f, "{c}\"{s}\"") } - TokenKind::Comment(s) => { + Self::Comment(s) => { writeln!(f, "#{s}") } - TokenKind::DocComment(s) => { + Self::DocComment(s) => { writeln!(f, "#!{s}") } - TokenKind::LineWrap(comments) => { + Self::LineWrap(comments) => { write!(f, "\n\\ ")?; for comment in comments { write!(f, "{comment}")?; } Ok(()) } - TokenKind::Start => write!(f, "start of input"), + Self::Start => write!(f, "start of input"), } } } diff --git a/prqlc/prqlc-parser/src/parser/perror.rs b/prqlc/prqlc-parser/src/parser/perror.rs index 0100de6deb26..ca5b874e3950 100644 --- a/prqlc/prqlc-parser/src/parser/perror.rs +++ b/prqlc/prqlc-parser/src/parser/perror.rs @@ -83,7 +83,7 @@ where } impl<'a> From> for Error { - fn from(rich: Rich<'a, crate::lexer::lr::Token, Span>) -> Error { + fn from(rich: Rich<'a, crate::lexer::lr::Token, Span>) -> Self { rich_error_to_error( *rich.span(), rich.reason(), @@ -94,7 +94,7 @@ impl<'a> From> for Error { } impl<'a> From> for Error { - fn from(rich: Rich<'a, TokenKind, Span>) -> Error { + fn from(rich: Rich<'a, TokenKind, Span>) -> Self { rich_error_to_error( *rich.span(), rich.reason(), diff --git a/prqlc/prqlc-parser/src/parser/pr/expr.rs b/prqlc/prqlc-parser/src/parser/pr/expr.rs index cd6f6e81bff9..11c056b0163a 100644 --- a/prqlc/prqlc-parser/src/parser/pr/expr.rs +++ b/prqlc/prqlc-parser/src/parser/pr/expr.rs @@ -12,7 +12,7 @@ use crate::{generic, parser::SupportsDocComment}; impl Expr { pub fn new>(kind: K) -> Self { - Expr { + Self { kind: kind.into(), span: None, alias: None, @@ -171,12 +171,12 @@ pub type SwitchCase = generic::SwitchCase>; impl From for ExprKind { fn from(value: Literal) -> Self { - ExprKind::Literal(value) + Self::Literal(value) } } impl From for ExprKind { fn from(value: Func) -> Self { - ExprKind::Func(Box::new(value)) + Self::Func(Box::new(value)) } } diff --git a/prqlc/prqlc-parser/src/parser/pr/ident.rs b/prqlc/prqlc-parser/src/parser/pr/ident.rs index c9c226f3f16c..b0811ecea1d6 100644 --- a/prqlc/prqlc-parser/src/parser/pr/ident.rs +++ b/prqlc/prqlc-parser/src/parser/pr/ident.rs @@ -13,7 +13,7 @@ pub struct Ident { impl Ident { pub fn from_name(name: S) -> Self { - Ident { + Self { path: Vec::new(), name: name.to_string(), } @@ -24,7 +24,7 @@ impl Ident { /// Panics if path is empty. pub fn from_path(mut path: Vec) -> Self { let name = path.pop().unwrap().to_string(); - Ident { + Self { path: path.into_iter().map(|x| x.to_string()).collect(), name, } @@ -42,10 +42,10 @@ impl Ident { /// Result will generally refer to the parent of this ident. pub fn pop(self) -> Option { let mut path = self.path; - path.pop().map(|name| Ident { path, name }) + path.pop().map(|name| Self { path, name }) } - pub fn pop_front(mut self) -> (String, Option) { + pub fn pop_front(mut self) -> (String, Option) { if self.path.is_empty() { (self.name, None) } else { @@ -54,9 +54,9 @@ impl Ident { } } - pub fn prepend(self, mut parts: Vec) -> Ident { + pub fn prepend(self, mut parts: Vec) -> Self { parts.extend(self); - Ident::from_path(parts) + Self::from_path(parts) } pub fn push(&mut self, name: String) { @@ -73,7 +73,7 @@ impl Ident { self.path.iter().chain(std::iter::once(&self.name)) } - pub fn starts_with(&self, prefix: &Ident) -> bool { + pub fn starts_with(&self, prefix: &Self) -> bool { if prefix.len() > self.len() { return false; } @@ -126,11 +126,11 @@ impl IntoIterator for Ident { } } -impl std::ops::Add for Ident { - type Output = Ident; +impl std::ops::Add for Ident { + type Output = Self; - fn add(self, rhs: Ident) -> Self::Output { - Ident { + fn add(self, rhs: Self) -> Self::Output { + Self { path: self.into_iter().chain(rhs.path).collect(), name: rhs.name, } @@ -156,7 +156,7 @@ impl<'de> Deserialize<'de> for Ident { where D: Deserializer<'de>, { - as Deserialize>::deserialize(deserializer).map(Ident::from_path) + as Deserialize>::deserialize(deserializer).map(Self::from_path) } } diff --git a/prqlc/prqlc-parser/src/parser/pr/stmt.rs b/prqlc/prqlc-parser/src/parser/pr/stmt.rs index dbdc92f6d485..b017fe635662 100644 --- a/prqlc/prqlc-parser/src/parser/pr/stmt.rs +++ b/prqlc/prqlc-parser/src/parser/pr/stmt.rs @@ -41,7 +41,7 @@ pub struct Stmt { impl SupportsDocComment for Stmt { fn with_doc_comment(self, doc_comment: Option) -> Self { - Stmt { + Self { doc_comment, ..self } @@ -91,8 +91,8 @@ pub struct Annotation { } impl Stmt { - pub fn new(kind: StmtKind) -> Stmt { - Stmt { + pub fn new(kind: StmtKind) -> Self { + Self { kind, span: None, annotations: Vec::new(), diff --git a/prqlc/prqlc-parser/src/parser/pr/types.rs b/prqlc/prqlc-parser/src/parser/pr/types.rs index a9565ad28edc..a7f5c650f694 100644 --- a/prqlc/prqlc-parser/src/parser/pr/types.rs +++ b/prqlc/prqlc-parser/src/parser/pr/types.rs @@ -35,7 +35,7 @@ pub enum TyKind { } impl TyKind { - pub fn into_ty(self: TyKind, span: Span) -> Ty { + pub fn into_ty(self, span: Span) -> Ty { Ty { kind: self, span: Some(span), @@ -92,8 +92,8 @@ pub struct TyFunc { } impl Ty { - pub fn new>(kind: K) -> Ty { - Ty { + pub fn new>(kind: K) -> Self { + Self { kind: kind.into(), span: None, name: None, @@ -101,8 +101,8 @@ impl Ty { } pub fn relation(tuple_fields: Vec) -> Self { - let tuple = Ty::new(TyKind::Tuple(tuple_fields)); - Ty::new(TyKind::Array(Some(Box::new(tuple)))) + let tuple = Self::new(TyKind::Tuple(tuple_fields)); + Self::new(TyKind::Array(Some(Box::new(tuple)))) } pub fn as_relation(&self) -> Option<&Vec> { @@ -130,20 +130,20 @@ impl Ty { impl TyTupleField { pub fn ty(&self) -> Option<&Ty> { match self { - TyTupleField::Single(_, ty) => ty.as_ref(), - TyTupleField::Wildcard(ty) => ty.as_ref(), + Self::Single(_, ty) => ty.as_ref(), + Self::Wildcard(ty) => ty.as_ref(), } } } impl From for TyKind { fn from(value: PrimitiveSet) -> Self { - TyKind::Primitive(value) + Self::Primitive(value) } } impl From for TyKind { fn from(value: TyFunc) -> Self { - TyKind::Function(Some(value)) + Self::Function(Some(value)) } } diff --git a/prqlc/prqlc-parser/src/span.rs b/prqlc/prqlc-parser/src/span.rs index 6ec3dd17c896..f2405f003256 100644 --- a/prqlc/prqlc-parser/src/span.rs +++ b/prqlc/prqlc-parser/src/span.rs @@ -21,7 +21,7 @@ impl chumsky::span::Span for Span { type Offset = usize; fn new(context: Self::Context, range: Range) -> Self { - Span { + Self { start: range.start, end: range.end, source_id: context, @@ -41,7 +41,7 @@ impl chumsky::span::Span for Span { } fn to_end(&self) -> Self { - Span { + Self { start: self.end, end: self.end, source_id: self.source_id, @@ -141,9 +141,9 @@ impl<'de> Deserialize<'de> for Span { } impl Add for Span { - type Output = Span; + type Output = Self; - fn add(self, rhs: usize) -> Span { + fn add(self, rhs: usize) -> Self { Self { start: self.start + rhs, end: self.end + rhs, @@ -153,9 +153,9 @@ impl Add for Span { } impl Sub for Span { - type Output = Span; + type Output = Self; - fn sub(self, rhs: usize) -> Span { + fn sub(self, rhs: usize) -> Self { Self { start: self.start - rhs, end: self.end - rhs, diff --git a/prqlc/prqlc/src/cli/mod.rs b/prqlc/prqlc/src/cli/mod.rs index 65aee158fc15..2a0544e50252 100644 --- a/prqlc/prqlc/src/cli/mod.rs +++ b/prqlc/prqlc/src/cli/mod.rs @@ -290,11 +290,11 @@ impl Command { /// Entrypoint called by [`main`] pub fn run(&mut self) -> Result<()> { match self { - Command::Watch(command) => watch::run(command), - Command::ListTargets => self.list_targets(), + Self::Watch(command) => watch::run(command), + Self::ListTargets => self.list_targets(), // Format is handled differently to the other IO commands, since it // always writes to the same output. - Command::Format { input } => { + Self::Format { input } => { let sources = read_files(input)?; let root = sources.root; @@ -309,27 +309,25 @@ impl Command { break; } - let path_buf = root - .as_ref() - .map_or_else(|| path.clone(), |root| root.join(&path)); - let path_str = path_buf.to_str().ok_or_else(|| { - anyhow!("Path `{}` is not valid UTF-8", path_buf.display()) - })?; + let path_buf = root.as_ref().map_or_else(|| path.clone(), |root| root.join(&path)); + let path_str = path_buf + .to_str() + .ok_or_else(|| anyhow!("Path `{}` is not valid UTF-8", path_buf.display()))?; let mut output: Output = Output::new(path_str)?; output.write_all(&pl_to_prql(&ast)?.into_bytes())?; } Ok(()) } - Command::ShellCompletion { shell } => { + Self::ShellCompletion { shell } => { shell.generate(&mut Cli::command(), &mut std::io::stdout()); Ok(()) } - Command::Debug(DebugCommand::Ast) => { + Self::Debug(DebugCommand::Ast) => { prqlc::ir::pl::print_mem_sizes(); Ok(()) } - Command::Debug(DebugCommand::JsonSchema { ir_type }) => { + Self::Debug(DebugCommand::JsonSchema { ir_type }) => { let schema = match ir_type { IntermediateRepr::Pl => schema_for!(pl::ModuleDef), IntermediateRepr::Rq => schema_for!(rq::RelationalQuery), @@ -367,14 +365,14 @@ impl Command { .collect_vec(); Ok(match self { - Command::Parse { format, .. } => { + Self::Parse { format, .. } => { let ast = prql_to_pl_tree(sources)?; match format { Format::Json => serde_json::to_string_pretty(&ast)?.into_bytes(), Format::Yaml => serde_yaml::to_string(&ast)?.into_bytes(), } } - Command::Lex { format, .. } => { + Self::Lex { format, .. } => { let s = sources.sources.values().exactly_one().or_else(|_| { // TODO: allow multiple sources bail!("Currently `lex` only works with a single source, but found multiple sources") @@ -385,24 +383,26 @@ impl Command { Format::Yaml => serde_yaml::to_string(&tokens)?.into_bytes(), } } - Command::Collect(_) => { + Self::Collect(_) => { let mut root_module_def = prql_to_pl_tree(sources)?; drop_module_def(&mut root_module_def.stmts, "std"); pl_to_prql(&root_module_def)?.into_bytes() } - Command::Debug(DebugCommand::Annotate(_)) => { - let (_, source) = sources.sources.clone().into_iter().exactly_one().or_else( - |_| bail!( + Self::Debug(DebugCommand::Annotate(_)) => { + let (_, source) = sources.sources.clone().into_iter().exactly_one().or_else(|_| { + bail!( "Currently `annotate` only works with a single source, but found multiple sources: {:?}", - sources.sources.keys() + sources + .sources + .keys() .map(|x| x.display().to_string()) .sorted() .map(|x| format!("`{x}`")) .join(", ") ) - )?; + })?; // TODO: potentially if there is code performing a role beyond // presentation, it should be a library function; and we could @@ -413,8 +413,7 @@ impl Command { let ctx = semantic::resolve(root_mod)?; let frames = if let Ok((main, _)) = ctx.find_main_rel(&[]) { - semantic::reporting::collect_frames(*main.clone().into_relation_var().unwrap()) - .frames + semantic::reporting::collect_frames(*main.clone().into_relation_var().unwrap()).frames } else { vec![] }; @@ -422,7 +421,7 @@ impl Command { // combine with source combine_prql_and_frames(&source, frames).as_bytes().to_vec() } - Command::Debug(DebugCommand::Lineage { format, .. }) => { + Self::Debug(DebugCommand::Lineage { format, .. }) => { let stmts = prql_to_pl_tree(sources)?; let fc = pl_to_lineage(stmts)?; @@ -431,19 +430,15 @@ impl Command { Format::Yaml => serde_yaml::to_string(&fc)?.into_bytes(), } } - Command::Experimental(ExperimentalCommand::GenerateDocs { format, .. }) => { + Self::Experimental(ExperimentalCommand::GenerateDocs { format, .. }) => { let module_ref = prql_to_pl_tree(sources)?; match format { - DocsFormat::Html => { - docs_generator::generate_html_docs(module_ref.stmts).into_bytes() - } - DocsFormat::Markdown => { - docs_generator::generate_markdown_docs(module_ref.stmts).into_bytes() - } + DocsFormat::Html => docs_generator::generate_html_docs(module_ref.stmts).into_bytes(), + DocsFormat::Markdown => docs_generator::generate_markdown_docs(module_ref.stmts).into_bytes(), } } - Command::Experimental(ExperimentalCommand::Highlight(_)) => { + Self::Experimental(ExperimentalCommand::Highlight(_)) => { let s = sources.sources.values().exactly_one().or_else(|_| { // TODO: allow multiple sources bail!("Currently `highlight` only works with a single source, but found multiple sources") @@ -452,7 +447,7 @@ impl Command { maybe_strip_colors(&highlight::highlight(&tokens)).into_bytes() } - Command::Compile { + Self::Compile { signature_comment, format, target, @@ -469,9 +464,7 @@ impl Command { .with_format(*format); let res = prql_to_pl_tree(sources) - .and_then(|pl| { - pl_to_rq_tree(pl, &main_path, &[semantic::NS_DEFAULT_DB.to_string()]) - }) + .and_then(|pl| pl_to_rq_tree(pl, &main_path, &[semantic::NS_DEFAULT_DB.to_string()])) .and_then(|rq| rq_to_sql(rq, &opts)) .map_err(|e| e.composed(sources)); @@ -496,9 +489,7 @@ impl Command { | Lex { io_args, .. } | Collect(io_args) | Compile { io_args, .. } - | Debug(DebugCommand::Annotate(io_args) | DebugCommand::Lineage { io_args, .. }) => { - io_args - } + | Debug(DebugCommand::Annotate(io_args) | DebugCommand::Lineage { io_args, .. }) => io_args, Experimental(ExperimentalCommand::GenerateDocs { io_args, .. }) => io_args, Experimental(ExperimentalCommand::Highlight(io_args)) => io_args, _ => unreachable!(), @@ -532,12 +523,8 @@ impl Command { | Lex { io_args, .. } | Collect(io_args) | Compile { io_args, .. } - | Debug(DebugCommand::Annotate(io_args) | DebugCommand::Lineage { io_args, .. }) => { - io_args.output.clone() - } - Experimental(ExperimentalCommand::GenerateDocs { io_args, .. }) => { - io_args.output.clone() - } + | Debug(DebugCommand::Annotate(io_args) | DebugCommand::Lineage { io_args, .. }) => io_args.output.clone(), + Experimental(ExperimentalCommand::GenerateDocs { io_args, .. }) => io_args.output.clone(), Experimental(ExperimentalCommand::Highlight(io_args)) => io_args.output.clone(), _ => unreachable!(), }; @@ -546,13 +533,7 @@ impl Command { } fn has_debug_log(cli: &Cli) -> bool { - matches!( - cli.command, - Some(Command::Compile { - debug_log: Some(_), - .. - }) - ) + matches!(cli.command, Some(Command::Compile { debug_log: Some(_), .. })) } pub fn write_log(path: &std::path::Path) -> Result<()> { @@ -725,10 +706,7 @@ sort full &mut SourceTree::new( [ ("Project.prql".into(), "orders.x | select y".to_string()), - ( - "orders.prql".into(), - "let x = (from z | select {y, u})".to_string(), - ), + ("orders.prql".into(), "let x = (from z | select {y, u})".to_string()), ], None, ), diff --git a/prqlc/prqlc/src/codegen/mod.rs b/prqlc/prqlc/src/codegen/mod.rs index b69d349498a5..73cdbd83beb1 100644 --- a/prqlc/prqlc/src/codegen/mod.rs +++ b/prqlc/prqlc/src/codegen/mod.rs @@ -102,10 +102,10 @@ impl Default for WriteOpt { impl WriteOpt { fn new_width(max_width: u16) -> Self { - WriteOpt { + Self { max_width, rem_width: max_width, - ..WriteOpt::default() + ..Self::default() } } diff --git a/prqlc/prqlc/src/debug/log.rs b/prqlc/prqlc/src/debug/log.rs index 239d18ec410a..20d67ad447f5 100644 --- a/prqlc/prqlc/src/debug/log.rs +++ b/prqlc/prqlc/src/debug/log.rs @@ -128,9 +128,9 @@ impl Stage { pub(super) fn sub_stage(&self) -> Option<&'_ str> { match self { - Stage::Parsing => None, - Stage::Semantic(s) => Some(s.as_ref()), - Stage::Sql(s) => Some(s.as_ref()), + Self::Parsing => None, + Self::Semantic(s) => Some(s.as_ref()), + Self::Sql(s) => Some(s.as_ref()), } } } @@ -157,7 +157,7 @@ impl LogSuppressLock { if let Some(log) = lock.as_mut() { log.suppress_count += 1; - Some(LogSuppressLock(PhantomData)) + Some(Self(PhantomData)) } else { None } diff --git a/prqlc/prqlc/src/error_message.rs b/prqlc/prqlc/src/error_message.rs index 58105d4065be..495664c86039 100644 --- a/prqlc/prqlc/src/error_message.rs +++ b/prqlc/prqlc/src/error_message.rs @@ -73,7 +73,7 @@ impl Debug for ErrorMessage { impl From for ErrorMessage { fn from(e: Error) -> Self { log::debug!("{e:#?}"); - ErrorMessage { + Self { code: e.code.map(str::to_string), kind: e.kind, reason: e.reason.to_string(), @@ -87,7 +87,7 @@ impl From for ErrorMessage { impl From> for ErrorMessages { fn from(errors: Vec) -> Self { - ErrorMessages { inner: errors } + Self { inner: errors } } } @@ -99,13 +99,13 @@ impl StdError for ErrorMessages {} impl From for ErrorMessages { fn from(e: ErrorMessage) -> Self { - ErrorMessages { inner: vec![e] } + Self { inner: vec![e] } } } impl From for ErrorMessages { fn from(e: Error) -> Self { - ErrorMessages { + Self { inner: vec![ErrorMessage::from(e)], } } @@ -113,7 +113,7 @@ impl From for ErrorMessages { impl From for ErrorMessages { fn from(errs: Errors) -> Self { - ErrorMessages { + Self { inner: errs.0.into_iter().map(ErrorMessage::from).collect(), } } diff --git a/prqlc/prqlc/src/ir/decl.rs b/prqlc/prqlc/src/ir/decl.rs index a859af7881f8..cd027838a1e6 100644 --- a/prqlc/prqlc/src/ir/decl.rs +++ b/prqlc/prqlc/src/ir/decl.rs @@ -160,13 +160,13 @@ impl std::fmt::Debug for DebugNames<'_> { impl Default for DeclKind { fn default() -> Self { - DeclKind::Module(Module::default()) + Self::Module(Module::default()) } } impl From for Decl { fn from(kind: DeclKind) -> Self { - Decl { + Self { kind, declared_at: None, order: 0, diff --git a/prqlc/prqlc/src/ir/generic.rs b/prqlc/prqlc/src/ir/generic.rs index 1f8a4c8ec721..9f110d6dcd6d 100644 --- a/prqlc/prqlc/src/ir/generic.rs +++ b/prqlc/prqlc/src/ir/generic.rs @@ -32,7 +32,7 @@ impl WindowFrame { pub(crate) fn is_default(&self) -> bool { matches!( self, - WindowFrame { + Self { kind: WindowKind::Rows, range: generic::Range { start: None, diff --git a/prqlc/prqlc/src/ir/pl/expr.rs b/prqlc/prqlc/src/ir/pl/expr.rs index 68ddb810ad76..1f96ea7bd3b0 100644 --- a/prqlc/prqlc/src/ir/pl/expr.rs +++ b/prqlc/prqlc/src/ir/pl/expr.rs @@ -136,19 +136,19 @@ pub type SwitchCase = generic::SwitchCase>; impl From for ExprKind { fn from(value: Literal) -> Self { - ExprKind::Literal(value) + Self::Literal(value) } } impl From for ExprKind { fn from(value: Ident) -> Self { - ExprKind::Ident(value) + Self::Ident(value) } } impl From for ExprKind { fn from(value: Func) -> Self { - ExprKind::Func(Box::new(value)) + Self::Func(Box::new(value)) } } diff --git a/prqlc/prqlc/src/ir/pl/extra.rs b/prqlc/prqlc/src/ir/pl/extra.rs index 2fd5cd265738..10165cbac671 100644 --- a/prqlc/prqlc/src/ir/pl/extra.rs +++ b/prqlc/prqlc/src/ir/pl/extra.rs @@ -8,7 +8,7 @@ use crate::pr::Ty; impl FuncCall { pub fn new_simple(name: Expr, args: Vec) -> Self { - FuncCall { + Self { name: Box::new(name), args, named_args: Default::default(), @@ -117,7 +117,7 @@ pub enum JoinSide { impl Expr { pub fn new(kind: impl Into) -> Self { - Expr { + Self { id: None, kind: kind.into(), span: None, diff --git a/prqlc/prqlc/src/ir/rq/ids.rs b/prqlc/prqlc/src/ir/rq/ids.rs index e37fa4776c0f..748a0e0481c3 100644 --- a/prqlc/prqlc/src/ir/rq/ids.rs +++ b/prqlc/prqlc/src/ir/rq/ids.rs @@ -13,7 +13,7 @@ impl CId { impl From for CId { fn from(id: usize) -> Self { - CId(id) + Self(id) } } @@ -35,7 +35,7 @@ impl TId { impl From for TId { fn from(id: usize) -> Self { - TId(id) + Self(id) } } diff --git a/prqlc/prqlc/src/lib.rs b/prqlc/prqlc/src/lib.rs index d9b86fba9c54..374c7fe2b984 100644 --- a/prqlc/prqlc/src/lib.rs +++ b/prqlc/prqlc/src/lib.rs @@ -242,14 +242,14 @@ impl Target { impl FromStr for Target { type Err = Error; - fn from_str(s: &str) -> Result { + fn from_str(s: &str) -> Result { if let Some(dialect) = s.strip_prefix("sql.") { if dialect == "any" { - return Ok(Target::Sql(None)); + return Ok(Self::Sql(None)); } if let Ok(dialect) = sql::Dialect::from_str(dialect) { - return Ok(Target::Sql(Some(dialect))); + return Ok(Self::Sql(Some(dialect))); } } @@ -455,7 +455,7 @@ pub struct SourceTree { impl SourceTree { pub fn single(path: PathBuf, content: String) -> Self { - SourceTree { + Self { sources: [(path.clone(), content)].into(), source_ids: [(1, path)].into(), root: None, @@ -466,7 +466,7 @@ impl SourceTree { where I: IntoIterator, { - let mut res = SourceTree { + let mut res = Self { sources: HashMap::new(), source_ids: HashMap::new(), root, @@ -492,7 +492,7 @@ impl SourceTree { impl From for SourceTree { fn from(source: S) -> Self { - SourceTree::single(PathBuf::from(""), source.to_string()) + Self::single(PathBuf::from(""), source.to_string()) } } diff --git a/prqlc/prqlc/src/semantic/lowering.rs b/prqlc/prqlc/src/semantic/lowering.rs index de68306dbfc9..19588d53a094 100644 --- a/prqlc/prqlc/src/semantic/lowering.rs +++ b/prqlc/prqlc/src/semantic/lowering.rs @@ -196,7 +196,7 @@ enum LoweredTarget { impl Lowerer { fn new(root_mod: RootModule, database_module_path: &[String]) -> Self { - Lowerer { + Self { root_mod, database_module_path: database_module_path.to_vec(), @@ -1184,7 +1184,7 @@ struct TableExtractor { impl TableExtractor { /// Finds table declarations in a module, recursively. fn extract(root_module: &Module) -> Vec<(Ident, (decl::TableDecl, Option))> { - let mut te = TableExtractor::default(); + let mut te = Self::default(); te.extract_from_module(root_module); te.tables } @@ -1248,7 +1248,7 @@ struct TableDepsCollector { impl TableDepsCollector { fn collect(expr: pl::Expr) -> Vec { - let mut c = TableDepsCollector::default(); + let mut c = Self::default(); c.fold_expr(expr).unwrap(); c.deps } diff --git a/prqlc/prqlc/src/semantic/mod.rs b/prqlc/prqlc/src/semantic/mod.rs index 15402110cf9c..1e4268ce775f 100644 --- a/prqlc/prqlc/src/semantic/mod.rs +++ b/prqlc/prqlc/src/semantic/mod.rs @@ -112,8 +112,8 @@ pub const NS_INFER: &str = "_infer"; pub const NS_INFER_MODULE: &str = "_infer_module"; impl Stmt { - pub fn new(kind: StmtKind) -> Stmt { - Stmt { + pub fn new(kind: StmtKind) -> Self { + Self { id: None, kind, span: None, @@ -141,7 +141,7 @@ impl pl::Expr { Error::new(Reason::Expected { who: who.map(|s| s.to_string()), expected: expected.to_string(), - found: format!("`{}`", write_pl(pl::Expr::new(i))), + found: format!("`{}`", write_pl(Self::new(i))), }) .with_span(self.span) }) diff --git a/prqlc/prqlc/src/semantic/module.rs b/prqlc/prqlc/src/semantic/module.rs index 08fe6fbce490..9d48712b55c0 100644 --- a/prqlc/prqlc/src/semantic/module.rs +++ b/prqlc/prqlc/src/semantic/module.rs @@ -12,21 +12,21 @@ use crate::Error; use crate::Result; impl Module { - pub fn singleton(name: S, entry: Decl) -> Module { - Module { + pub fn singleton(name: S, entry: Decl) -> Self { + Self { names: HashMap::from([(name.to_string(), entry)]), ..Default::default() } } - pub fn new_root() -> Module { + pub fn new_root() -> Self { // Each module starts with a default namespace that contains a wildcard // and the standard library. - Module { + Self { names: HashMap::from([ ( NS_DEFAULT_DB.to_string(), - Decl::from(DeclKind::Module(Module::new_database())), + Decl::from(DeclKind::Module(Self::new_database())), ), (NS_STD.to_string(), Decl::from(DeclKind::default())), ]), @@ -40,7 +40,7 @@ impl Module { } } - pub fn new_database() -> Module { + pub fn new_database() -> Self { let names = HashMap::from([ ( NS_INFER.to_string(), @@ -51,14 +51,14 @@ impl Module { ), ( NS_INFER_MODULE.to_string(), - Decl::from(DeclKind::Infer(Box::new(DeclKind::Module(Module { + Decl::from(DeclKind::Infer(Box::new(DeclKind::Module(Self { names: HashMap::new(), redirects: vec![], shadowed: None, })))), ), ]); - Module { + Self { names, shadowed: None, redirects: vec![], @@ -218,7 +218,7 @@ impl Module { let order = lineage.inputs.iter().position(|i| i.id == input.id); let order = order.unwrap(); - let mut sub_ns = Module::default(); + let mut sub_ns = Self::default(); let self_ty = lin_ty.clone().kind.into_tuple().unwrap(); let self_ty = self_ty @@ -303,7 +303,7 @@ impl Module { pub fn shadow(&mut self, ident: &str) { let shadowed = self.names.remove(ident).map(Box::new); - let entry = DeclKind::Module(Module { + let entry = DeclKind::Module(Self { shadowed, ..Default::default() }); @@ -320,7 +320,7 @@ impl Module { } } - pub fn stack_push(&mut self, ident: &str, namespace: Module) { + pub fn stack_push(&mut self, ident: &str, namespace: Self) { let entry = self .names .entry(ident.to_string()) @@ -330,7 +330,7 @@ impl Module { stack.push(namespace); } - pub fn stack_pop(&mut self, ident: &str) -> Option { + pub fn stack_pop(&mut self, ident: &str) -> Option { (self.names.get_mut(ident)) .and_then(|e| e.kind.as_layered_modules_mut()) .and_then(|stack| stack.pop()) @@ -343,8 +343,8 @@ impl Module { .collect() } - pub(crate) fn from_exprs(exprs: HashMap) -> Module { - Module { + pub(crate) fn from_exprs(exprs: HashMap) -> Self { + Self { names: exprs .into_iter() .map(|(key, expr)| { diff --git a/prqlc/prqlc/src/semantic/resolver/flatten.rs b/prqlc/prqlc/src/semantic/resolver/flatten.rs index 2a3506624b9f..bda50a86c772 100644 --- a/prqlc/prqlc/src/semantic/resolver/flatten.rs +++ b/prqlc/prqlc/src/semantic/resolver/flatten.rs @@ -44,7 +44,7 @@ pub struct Flattener { impl Flattener { pub fn fold(expr: Expr) -> Expr { - let mut f = Flattener::default(); + let mut f = Self::default(); f.fold_expr(expr).unwrap() } } diff --git a/prqlc/prqlc/src/semantic/resolver/transforms.rs b/prqlc/prqlc/src/semantic/resolver/transforms.rs index a8401851e82b..11a854a23d0d 100644 --- a/prqlc/prqlc/src/semantic/resolver/transforms.rs +++ b/prqlc/prqlc/src/semantic/resolver/transforms.rs @@ -856,11 +856,11 @@ impl Lineage { pub fn apply_assign(&mut self, expr: &Expr, inline_refs: bool) { // special case: all except if let ExprKind::All { within, except } = &expr.kind { - let mut within_lineage = Lineage::default(); + let mut within_lineage = Self::default(); within_lineage.inputs.extend(self.inputs.clone()); within_lineage.apply_assigns(within, true); - let mut except_lineage = Lineage::default(); + let mut except_lineage = Self::default(); except_lineage.inputs.extend(self.inputs.clone()); except_lineage.apply_assigns(except, true); diff --git a/prqlc/prqlc/src/sql/dialect.rs b/prqlc/prqlc/src/sql/dialect.rs index 03b0190b7c53..b8bfa654d143 100644 --- a/prqlc/prqlc/src/sql/dialect.rs +++ b/prqlc/prqlc/src/sql/dialect.rs @@ -67,31 +67,31 @@ pub enum Dialect { impl Dialect { pub(super) fn handler(&self) -> Box { match self { - Dialect::MsSql => Box::new(MsSqlDialect), - Dialect::MySql => Box::new(MySqlDialect), - Dialect::BigQuery => Box::new(BigQueryDialect), - Dialect::SQLite => Box::new(SQLiteDialect), - Dialect::ClickHouse => Box::new(ClickHouseDialect), - Dialect::Snowflake => Box::new(SnowflakeDialect), - Dialect::DuckDb => Box::new(DuckDbDialect), - Dialect::Postgres => Box::new(PostgresDialect), - Dialect::Redshift => Box::new(RedshiftDialect), - Dialect::GlareDb => Box::new(GlareDbDialect), - Dialect::Ansi | Dialect::Generic => Box::new(GenericDialect), + Self::MsSql => Box::new(MsSqlDialect), + Self::MySql => Box::new(MySqlDialect), + Self::BigQuery => Box::new(BigQueryDialect), + Self::SQLite => Box::new(SQLiteDialect), + Self::ClickHouse => Box::new(ClickHouseDialect), + Self::Snowflake => Box::new(SnowflakeDialect), + Self::DuckDb => Box::new(DuckDbDialect), + Self::Postgres => Box::new(PostgresDialect), + Self::Redshift => Box::new(RedshiftDialect), + Self::GlareDb => Box::new(GlareDbDialect), + Self::Ansi | Self::Generic => Box::new(GenericDialect), } } pub fn support_level(&self) -> SupportLevel { match self { - Dialect::DuckDb - | Dialect::SQLite - | Dialect::Postgres - | Dialect::Redshift - | Dialect::MySql - | Dialect::Generic - | Dialect::GlareDb - | Dialect::ClickHouse => SupportLevel::Supported, - Dialect::MsSql | Dialect::Ansi | Dialect::BigQuery | Dialect::Snowflake => { + Self::DuckDb + | Self::SQLite + | Self::Postgres + | Self::Redshift + | Self::MySql + | Self::Generic + | Self::GlareDb + | Self::ClickHouse => SupportLevel::Supported, + Self::MsSql | Self::Ansi | Self::BigQuery | Self::Snowflake => { SupportLevel::Unsupported } } @@ -99,7 +99,7 @@ impl Dialect { #[deprecated(note = "Use `Dialect::VARIANTS` instead")] pub fn names() -> &'static [&'static str] { - Dialect::VARIANTS + Self::VARIANTS } } diff --git a/prqlc/prqlc/src/sql/gen_expr.rs b/prqlc/prqlc/src/sql/gen_expr.rs index 21af752baee5..2c9387577e63 100644 --- a/prqlc/prqlc/src/sql/gen_expr.rs +++ b/prqlc/prqlc/src/sql/gen_expr.rs @@ -957,12 +957,12 @@ pub enum Associativity { impl Associativity { /// Returns true iff `a + b + c = (a + b) + c` fn left_associative(&self) -> bool { - matches!(self, Associativity::Left | Associativity::Both) + matches!(self, Self::Left | Self::Both) } /// Returns true iff `a + b + c = a + (b + c)` fn right_associative(&self) -> bool { - matches!(self, Associativity::Right | Associativity::Both) + matches!(self, Self::Right | Self::Both) } } @@ -983,13 +983,13 @@ impl SQLExpression for sql_ast::Expr { // Strength of an expression depends only on the top-level operator, because all // other nested expressions can only have lower strength match self { - sql_ast::Expr::BinaryOp { op, .. } => op.binding_strength(), + Self::BinaryOp { op, .. } => op.binding_strength(), - sql_ast::Expr::UnaryOp { op, .. } => op.binding_strength(), + Self::UnaryOp { op, .. } => op.binding_strength(), - sql_ast::Expr::Like { .. } | sql_ast::Expr::ILike { .. } => 7, + Self::Like { .. } | Self::ILike { .. } => 7, - sql_ast::Expr::IsNull(_) | sql_ast::Expr::IsNotNull(_) => 5, + Self::IsNull(_) | Self::IsNotNull(_) => 5, // all other items types bind stronger (function calls, literals, ...) _ => 20, @@ -997,8 +997,8 @@ impl SQLExpression for sql_ast::Expr { } fn associativity(&self) -> Associativity { match self { - sql_ast::Expr::BinaryOp { op, .. } => op.associativity(), - sql_ast::Expr::UnaryOp { op, .. } => op.associativity(), + Self::BinaryOp { op, .. } => op.associativity(), + Self::UnaryOp { op, .. } => op.associativity(), _ => Associativity::Both, } } @@ -1030,8 +1030,8 @@ impl SQLExpression for BinaryOperator { impl SQLExpression for UnaryOperator { fn binding_strength(&self) -> i32 { match self { - UnaryOperator::Minus | UnaryOperator::Plus => 13, - UnaryOperator::Not => 4, + Self::Minus | Self::Plus => 13, + Self::Not => 4, _ => 9, } } @@ -1056,8 +1056,8 @@ pub struct SourceExpr { impl ExprOrSource { pub fn into_ast(self) -> sql_ast::Expr { match self { - ExprOrSource::Expr(ast) => *ast, - ExprOrSource::Source(SourceExpr { text: source, .. }) => { + Self::Expr(ast) => *ast, + Self::Source(SourceExpr { text: source, .. }) => { // The s-string hack sql_ast::Expr::Identifier(sql_ast::Ident::new(source)) } @@ -1066,19 +1066,19 @@ impl ExprOrSource { pub fn into_source(self) -> String { match self { - ExprOrSource::Expr(e) => e.to_string(), - ExprOrSource::Source(SourceExpr { text, .. }) => text, + Self::Expr(e) => e.to_string(), + Self::Source(SourceExpr { text, .. }) => text, } } fn wrap_in_parenthesis(self) -> Self { match self { - ExprOrSource::Expr(expr) => ExprOrSource::Expr(Box::new(sql_ast::Expr::Nested(expr))), - ExprOrSource::Source(SourceExpr { + Self::Expr(expr) => Self::Expr(Box::new(sql_ast::Expr::Nested(expr))), + Self::Source(SourceExpr { text, window_frame, .. }) => { let text = format!("({text})"); - ExprOrSource::Source(SourceExpr { + Self::Source(SourceExpr { text, binding_strength: 100, window_frame, @@ -1091,8 +1091,8 @@ impl ExprOrSource { impl SQLExpression for ExprOrSource { fn binding_strength(&self) -> i32 { match self { - ExprOrSource::Expr(expr) => expr.binding_strength(), - ExprOrSource::Source(SourceExpr { + Self::Expr(expr) => expr.binding_strength(), + Self::Source(SourceExpr { binding_strength, .. }) => *binding_strength, } @@ -1101,7 +1101,7 @@ impl SQLExpression for ExprOrSource { impl From for ExprOrSource { fn from(value: sql_ast::Expr) -> Self { - ExprOrSource::Expr(Box::new(value)) + Self::Expr(Box::new(value)) } } diff --git a/prqlc/prqlc/src/sql/mod.rs b/prqlc/prqlc/src/sql/mod.rs index 7d48988efbda..d7c637c24845 100644 --- a/prqlc/prqlc/src/sql/mod.rs +++ b/prqlc/prqlc/src/sql/mod.rs @@ -100,7 +100,7 @@ struct QueryOpts { impl Default for QueryOpts { fn default() -> Self { - QueryOpts { + Self { omit_ident_prefix: false, pre_projection: false, allow_ctes: true, @@ -112,7 +112,7 @@ impl Default for QueryOpts { impl Context { fn new(dialect: Dialect, anchor: AnchorContext) -> Self { - Context { + Self { dialect: dialect.handler(), dialect_enum: dialect, anchor, diff --git a/prqlc/prqlc/src/sql/pq/anchor.rs b/prqlc/prqlc/src/sql/pq/anchor.rs index 38938bb98812..1a597479de7f 100644 --- a/prqlc/prqlc/src/sql/pq/anchor.rs +++ b/prqlc/prqlc/src/sql/pq/anchor.rs @@ -441,11 +441,11 @@ impl fmt::Debug for Requirements { impl Requirements { /// Turns a list of `CId` into requirements with the least allowed complexity /// and unselected by default. - pub fn from_cids<'a, I>(cids: I) -> Requirements + pub fn from_cids<'a, I>(cids: I) -> Self where I: Iterator, { - Requirements( + Self( cids.cloned() .map(|col| Requirement { col, @@ -458,14 +458,14 @@ impl Requirements { /// Collect columns from the given `Expr` into requirements with /// the least allowed complexity and unselected by default. - pub fn from_expr(expr: &Expr) -> Requirements { + pub fn from_expr(expr: &Expr) -> Self { let cids = CidCollector::collect(expr.clone()); - Requirements::from_cids(cids.iter()) + Self::from_cids(cids.iter()) } /// Moves all the elements of `other` into `self`, leaving `other` empty, /// then return `self` for chainability. - pub fn append(mut self, mut other: Requirements) -> Requirements { + pub fn append(mut self, mut other: Self) -> Self { self.0.append(&mut other.0); self } @@ -641,13 +641,13 @@ pub struct CidCollector { impl CidCollector { pub fn collect(expr: Expr) -> Vec { - let mut collector = CidCollector::default(); + let mut collector = Self::default(); collector.fold_expr(expr).unwrap(); collector.cids } pub fn collect_t(t: Transform) -> (Transform, Vec) { - let mut collector = CidCollector::default(); + let mut collector = Self::default(); let t = collector.fold_transform(t).unwrap(); (t, collector.cids) } diff --git a/prqlc/prqlc/src/sql/pq/ast.rs b/prqlc/prqlc/src/sql/pq/ast.rs index d6422b15bfdf..060811461b26 100644 --- a/prqlc/prqlc/src/sql/pq/ast.rs +++ b/prqlc/prqlc/src/sql/pq/ast.rs @@ -117,7 +117,7 @@ pub enum SqlTransform { impl SqlTransform { pub fn as_str(&self) -> &str { match self { - SqlTransform::Super(t) => t.as_ref(), + Self::Super(t) => t.as_ref(), _ => self.as_ref(), } } diff --git a/prqlc/prqlc/src/sql/pq/context.rs b/prqlc/prqlc/src/sql/pq/context.rs index 15ce29f97166..5b7c54ec3e9d 100644 --- a/prqlc/prqlc/src/sql/pq/context.rs +++ b/prqlc/prqlc/src/sql/pq/context.rs @@ -79,8 +79,8 @@ pub struct RelationInstance { impl RelationStatus { /// Analogous to [Option::take] - pub fn take_to_define(&mut self) -> RelationStatus { - std::mem::replace(self, RelationStatus::Defined) + pub fn take_to_define(&mut self) -> Self { + std::mem::replace(self, Self::Defined) } } @@ -94,13 +94,13 @@ pub enum RelationAdapter { impl From for RelationAdapter { fn from(rel: SqlRelation) -> Self { - RelationAdapter::Pq(rel) + Self::Pq(rel) } } impl From for RelationAdapter { fn from(rel: Relation) -> Self { - RelationAdapter::Rq(rel) + Self::Rq(rel) } } @@ -110,7 +110,7 @@ pub struct RIId(usize); impl From for RIId { fn from(id: usize) -> Self { - RIId(id) + Self(id) } } @@ -127,7 +127,7 @@ impl AnchorContext { pub fn of(query: RelationalQuery) -> (Self, Relation) { let (cid, tid, query) = IdGenerator::load(query); - let context = AnchorContext { + let context = Self { cid, tid, riid: IdGenerator::new(), @@ -290,7 +290,7 @@ struct QueryLoader { impl QueryLoader { fn load(context: AnchorContext, query: RelationalQuery) -> (AnchorContext, Relation) { - let mut loader = QueryLoader { context }; + let mut loader = Self { context }; for t in query.tables { loader.load_table(t).unwrap(); diff --git a/prqlc/prqlc/src/utils/id_gen.rs b/prqlc/prqlc/src/utils/id_gen.rs index b12ac953f3f5..6c06433fd2a2 100644 --- a/prqlc/prqlc/src/utils/id_gen.rs +++ b/prqlc/prqlc/src/utils/id_gen.rs @@ -26,8 +26,8 @@ impl> IdGenerator { } impl> Default for IdGenerator { - fn default() -> IdGenerator { - IdGenerator { + fn default() -> Self { + Self { next_id: 0, phantom: PhantomData, } @@ -72,7 +72,7 @@ pub struct NameGenerator { impl NameGenerator { pub fn new(prefix: &'static str) -> Self { - NameGenerator { + Self { prefix, id: IdGenerator::new(), } diff --git a/prqlc/prqlc/src/utils/mod.rs b/prqlc/prqlc/src/utils/mod.rs index 83ff7b2e5139..e54556c1ea39 100644 --- a/prqlc/prqlc/src/utils/mod.rs +++ b/prqlc/prqlc/src/utils/mod.rs @@ -44,7 +44,7 @@ impl Pluck for Vec { F: Fn(T) -> Result, { let mut matched = Vec::new(); - let mut not_matched = Vec::new(); + let mut not_matched = Self::new(); for transform in self.drain(..) { match f(transform) { @@ -69,7 +69,7 @@ pub trait BreakUp { } impl BreakUp for Vec { - fn break_up(mut self, f: F) -> (Vec, Vec) + fn break_up(mut self, f: F) -> (Self, Self) where F: FnMut(&T) -> bool, {