Skip to content

Commit 32f29b4

Browse files
committed
Fix 1.74 clippy lints
1 parent 4db8ed0 commit 32f29b4

File tree

7 files changed

+35
-67
lines changed

7 files changed

+35
-67
lines changed

crates/cli/src/subcommands/repl.rs

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,20 @@ use syntect::highlighting::{Theme, ThemeSet};
1717
use syntect::parsing::{SyntaxDefinition, SyntaxSet, SyntaxSetBuilder};
1818
use syntect::util::LinesWithEndings;
1919

20-
static SQL_SYNTAX: &str = include_str!("../../tools/sublime/SpaceTimeDbSQL.sublime-syntax");
21-
static SYNTAX_NAME: &str = "SQL (SpaceTimeDb)";
22-
23-
static AUTO_COMPLETE: &str = "\
24-
true
25-
false
26-
select
27-
from
28-
insert
29-
into
30-
values
31-
update,
32-
delete,
33-
create,
34-
where
35-
join
36-
sort by
37-
.exit
38-
.clear
39-
";
20+
const SQL_SYNTAX: &str = include_str!("../../tools/sublime/SpaceTimeDbSQL.sublime-syntax");
21+
const SYNTAX_NAME: &str = "SQL (SpaceTimeDb)";
22+
23+
const AUTO_COMPLETE: &[&str] = &[
24+
"true", "false", "select", "from", "insert", "into", "values", "update,", "delete,", "create,", "where", "join",
25+
"sort by", ".exit", ".clear",
26+
];
4027

4128
pub async fn exec(con: Connection) -> Result<(), anyhow::Error> {
4229
let database = con.database.clone();
43-
let mut rl = Editor::<ReplHelper, DefaultHistory>::new().unwrap();
30+
let rl_config = rustyline::Config::builder()
31+
.completion_type(rustyline::config::CompletionType::List)
32+
.build();
33+
let mut rl = Editor::<ReplHelper, DefaultHistory>::with_config(rl_config)?;
4434
let history = home_dir().unwrap_or_else(temp_dir).join(".stdb.history.txt");
4535
if rl.load_history(&history).is_err() {
4636
eprintln!("No previous history.");
@@ -121,33 +111,22 @@ impl ReplHelper {
121111
impl Helper for ReplHelper {}
122112

123113
impl Completer for ReplHelper {
124-
type Candidate = String;
114+
type Candidate = &'static str;
125115

126116
fn complete(
127117
&self,
128118
line: &str,
129119
pos: usize,
130120
_: &rustyline::Context<'_>,
131121
) -> rustyline::Result<(usize, Vec<Self::Candidate>)> {
132-
let mut name = String::new();
133-
let mut name_pos = pos;
134-
while let Some(char) = line
135-
.chars()
136-
.nth(name_pos.wrapping_sub(1))
137-
.filter(|c| c.is_ascii_alphanumeric() || ['_', '.'].contains(c))
138-
{
139-
name.push(char);
140-
name_pos -= 1;
141-
}
142-
if name.is_empty() {
143-
return Ok((0, vec![]));
144-
}
145-
name = name.chars().rev().collect();
122+
let (name_pos, name) = rustyline::completion::extract_word(line, pos, None, |c| {
123+
!(c.is_ascii_alphanumeric() || matches!(c, '_' | '.'))
124+
});
146125

147-
let mut completions: Vec<_> = AUTO_COMPLETE.split('\n').map(str::to_string).collect();
148-
completions = completions
126+
let completions: Vec<_> = AUTO_COMPLETE
149127
.iter()
150-
.filter_map(|it| it.starts_with(&name).then(|| it.clone()))
128+
.copied()
129+
.filter(|completion| completion.starts_with(name))
151130
.collect();
152131

153132
Ok((name_pos, completions))
@@ -161,19 +140,11 @@ impl Hinter for ReplHelper {
161140
if line.len() > pos {
162141
return None;
163142
}
164-
if let Ok((mut completion_pos, completions)) = self.complete(line, pos, ctx) {
165-
if completions.is_empty() {
166-
return None;
167-
}
168-
let mut hint = completions[0].clone();
169-
while completion_pos < pos {
170-
if hint.is_empty() {
171-
return None;
172-
}
173-
hint.remove(0);
174-
completion_pos += 1;
143+
if let Ok((completion_pos, completions)) = self.complete(line, pos, ctx) {
144+
match &completions[..] {
145+
[completion] => Some(completion[pos - completion_pos..].to_owned()),
146+
_ => None,
175147
}
176-
Some(hint)
177148
} else {
178149
None
179150
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
// TODO: change the triple-slash comments to normal comments in the .proto
2+
#![allow(clippy::four_forward_slashes)]
3+
14
include!(concat!(env!("OUT_DIR"), "/protobuf.rs"));

crates/core/src/db/datastore/locking_tx_datastore/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl TxState {
295295
}
296296

297297
pub fn get_or_create_delete_table(&mut self, table_id: TableId) -> &mut BTreeSet<RowId> {
298-
self.delete_tables.entry(table_id).or_insert_with(BTreeSet::new)
298+
self.delete_tables.entry(table_id).or_default()
299299
}
300300

301301
/// When there's an index on `cols`,

crates/core/src/sql/ast.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,13 @@ impl From {
176176
pub fn find_field(&self, f: &str) -> Result<Vec<FieldDef>, RelationError> {
177177
let field = extract_table_field(f)?;
178178
let fields = self.iter_tables().flat_map(|t| {
179-
t.columns.iter().filter_map(|column| {
180-
(column.col_name == field.field).then(|| FieldDef {
179+
t.columns
180+
.iter()
181+
.filter(|column| column.col_name == field.field)
182+
.map(|column| FieldDef {
181183
column: column.clone(),
182184
table_name: field.table.unwrap_or(&t.table_name).to_string(),
183185
})
184-
})
185186
});
186187

187188
Ok(fields.collect())

crates/data-structures/src/slim_slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ impl Ord for SlimStr<'_> {
14061406
impl PartialOrd for SlimStr<'_> {
14071407
#[inline]
14081408
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
1409-
self.deref().partial_cmp(other.deref())
1409+
Some(self.cmp(other))
14101410
}
14111411
}
14121412
impl PartialOrd<str> for SlimStr<'_> {
@@ -1585,7 +1585,7 @@ impl Ord for SlimStrMut<'_> {
15851585
impl PartialOrd for SlimStrMut<'_> {
15861586
#[inline]
15871587
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
1588-
self.deref().partial_cmp(other.deref())
1588+
Some(self.cmp(other))
15891589
}
15901590
}
15911591
impl PartialOrd<str> for SlimStrMut<'_> {

crates/lib/src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,8 @@ impl TableDef {
155155
}
156156

157157
// Multi-column indexes cannot be unique (yet), so just add them.
158-
let multi_col_indexes = table.indexes.iter().filter_map(|index| {
159-
(index.cols.len() > 1).then(|| {
160-
spacetimedb_sats::db::def::IndexDef::new_cols(
161-
index.name.clone(),
162-
AUTO_TABLE_ID,
163-
false,
164-
index.cols.clone(),
165-
)
166-
})
158+
let multi_col_indexes = table.indexes.iter().filter(|index| index.cols.len() > 1).map(|index| {
159+
spacetimedb_sats::db::def::IndexDef::new_cols(index.name.clone(), AUTO_TABLE_ID, false, index.cols.clone())
167160
});
168161
indexes.extend(multi_col_indexes);
169162

crates/sats/src/typespace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl IndexMut<AlgebraicTypeRef> for Typespace {
4949
}
5050

5151
impl Typespace {
52-
pub const EMPTY: &Typespace = &Self::new(Vec::new());
52+
pub const EMPTY: &'static Typespace = &Self::new(Vec::new());
5353

5454
/// Returns a context ([`Typespace`]) with the given `types`.
5555
pub const fn new(types: Vec<AlgebraicType>) -> Self {

0 commit comments

Comments
 (0)