Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce rustfmt and clippy on all Rust code #7636

Merged
merged 9 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ resolver = "2"
debug = true
lto = true

[workspace.lints]
[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(never)'] }
6 changes: 3 additions & 3 deletions edb/edgeql-parser/edgeql-parser-python/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use edgeql_parser::tokenizer::Error;
use pyo3::prelude::*;
use pyo3::{create_exception, exceptions};
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyList};
use pyo3::{create_exception, exceptions};

use crate::tokenizer::OpaqueToken;

Expand All @@ -26,7 +26,7 @@ impl ParserResult {
let token: &PyCell<OpaqueToken> = token.downcast()?;
rv.push(token.borrow().inner.clone());
}
let mut buf = vec![0u8]; // type and version
let mut buf = vec![0u8]; // type and version
bincode::serialize_into(&mut buf, &rv)
.map_err(|e| PyValueError::new_err(format!("Failed to pack: {e}")))?;
Ok(PyBytes::new(py, buf.as_slice()).into())
Expand Down
26 changes: 13 additions & 13 deletions edb/edgeql-parser/edgeql-parser-python/src/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ pub struct PackedEntry {
pub first_arg: Option<usize>,
}

impl Into<PackedEntry> for Entry {
fn into(self) -> PackedEntry {
impl From<Entry> for PackedEntry {
fn from(val: Entry) -> Self {
PackedEntry {
tokens: self.tokens,
variables: self.variables,
named_args: self.named_args,
first_arg: self.first_arg,
tokens: val.tokens,
variables: val.variables,
named_args: val.named_args,
first_arg: val.first_arg,
}
}
}

impl Into<Entry> for PackedEntry {
fn into(self) -> Entry {
let processed_source = serialize_tokens(&self.tokens[..]);
impl From<PackedEntry> for Entry {
fn from(val: PackedEntry) -> Self {
let processed_source = serialize_tokens(&val.tokens[..]);
Entry {
hash: hash(&processed_source),
processed_source,
tokens: self.tokens,
variables: self.variables,
named_args: self.named_args,
first_arg: self.first_arg,
tokens: val.tokens,
variables: val.variables,
named_args: val.named_args,
first_arg: val.first_arg,
}
}
}
Expand Down
23 changes: 10 additions & 13 deletions edb/edgeql-parser/edgeql-parser-python/src/pynormalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyDict, PyFloat, PyList, PyLong, PyString};

use crate::errors::SyntaxError;
use crate::normalize::{normalize as _normalize, Error, Variable, PackedEntry};
use crate::normalize::{normalize as _normalize, Error, PackedEntry, Variable};
use crate::tokenizer::tokens_to_py;

#[pyfunction]
pub fn normalize(py: Python<'_>, text: &PyString) -> PyResult<Entry> {
let text = text.to_string();
match _normalize(&text) {
Ok(entry) => Entry::new(py, entry),
Err(Error::Tokenizer(msg, pos)) => {
Err(SyntaxError::new_err((
msg,
(pos, py.None()),
py.None(),
py.None(),
)))
}
Err(Error::Tokenizer(msg, pos)) => Err(SyntaxError::new_err((
msg,
(pos, py.None()),
py.None(),
py.None(),
))),
Err(Error::Assertion(msg, pos)) => {
Err(PyAssertionError::new_err(format!("{}: {}", pos, msg)))
}
Expand Down Expand Up @@ -57,8 +55,7 @@ pub struct Entry {

impl Entry {
pub fn new(py: Python, entry: crate::normalize::Entry) -> PyResult<Self> {
let blobs =
serialize_all(py, &entry.variables).map_err(PyAssertionError::new_err)?;
let blobs = serialize_all(py, &entry.variables).map_err(PyAssertionError::new_err)?;
let counts: Vec<_> = entry
.variables
.iter()
Expand Down Expand Up @@ -98,7 +95,7 @@ impl Entry {
}

fn pack(&self, py: Python) -> PyResult<PyObject> {
let mut buf = vec![1u8]; // type and version
let mut buf = vec![1u8]; // type and version
bincode::serialize_into(&mut buf, &self.entry_pack)
.map_err(|e| PyValueError::new_err(format!("Failed to pack: {e}")))?;
Ok(PyBytes::new(py, buf.as_slice()).into())
Expand Down Expand Up @@ -128,7 +125,7 @@ pub fn serialize_extra(variables: &[Variable]) -> Result<Bytes, String> {
}
Value::Float(ref v) => {
codec::Float64
.encode(&mut buf, &P::Float64(v.clone()))
.encode(&mut buf, &P::Float64(*v))
.map_err(|e| format!("float cannot be encoded: {}", e))?;
}
Value::BigInt(ref v) => {
Expand Down
7 changes: 5 additions & 2 deletions edb/edgeql-parser/edgeql-parser-python/src/unpack.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use edgeql_parser::tokenizer::Token;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use pyo3::types::PyBytes;
use edgeql_parser::tokenizer::Token;

use crate::normalize::PackedEntry;
use crate::pynormalize::Entry;
Expand All @@ -22,6 +22,9 @@ pub fn unpack(py: Python<'_>, serialized: &PyBytes) -> PyResult<PyObject> {
let entry = Entry::new(py, pack.into())?;
Ok(entry.into_py(py))
}
_ => Err(PyValueError::new_err(format!("Invalid type/version byte: {}", buf[0]))),
_ => Err(PyValueError::new_err(format!(
"Invalid type/version byte: {}",
buf[0]
))),
}
}
Loading
Loading