Skip to content

Commit 6928bb3

Browse files
committed
fix: compatibility with older versions of rust compiler
1 parent 0742f9e commit 6928bb3

File tree

6 files changed

+56
-53
lines changed

6 files changed

+56
-53
lines changed

.github/workflows/sqlformat.yml

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,57 @@ jobs:
1414
strategy:
1515
matrix:
1616
conf:
17+
- minimum
1718
- latest-stable
1819
- latest-beta
1920
- latest-nightly
2021
include:
22+
- conf: minimum
23+
toolchain: 1.62.0
2124
- conf: latest-stable
2225
toolchain: stable
2326
- conf: latest-beta
2427
toolchain: beta
2528
- conf: latest-nightly
2629
toolchain: nightly
2730
steps:
28-
- uses: actions/checkout@v2
29-
- name: Install ${{ matrix.toolchain }}
30-
uses: actions-rs/toolchain@v1
31-
with:
32-
profile: minimal
33-
toolchain: ${{ matrix.toolchain }}
34-
override: true
35-
components: clippy, rustfmt
36-
- name: Cache cargo registry
37-
uses: actions/cache@v1
38-
with:
39-
path: ~/.cargo/registry/cache
40-
key: ${{ runner.os }}-${{ matrix.conf }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
41-
restore-keys: |
42-
${{ runner.os }}-${{ matrix.conf }}-cargo-registry-
43-
- name: Run rustfmt
44-
if: matrix.toolchain == 'stable'
45-
uses: actions-rs/cargo@v1
46-
with:
47-
command: fmt
48-
args: -- --check
49-
- name: Run clippy
50-
if: matrix.toolchain == 'stable'
51-
uses: actions-rs/clippy-check@v1
52-
with:
53-
token: ${{ secrets.GITHUB_TOKEN }}
54-
args: -- -D warnings
55-
- name: Run tests
56-
run: cargo test
57-
- name: Build benchmarks
58-
if: matrix.toolchain == 'stable'
59-
run: cargo bench --no-run
60-
- name: Build docs
61-
run: cargo doc --no-deps
31+
- uses: actions/checkout@v2
32+
- name: Install ${{ matrix.toolchain }}
33+
uses: actions-rs/toolchain@v1
34+
with:
35+
profile: minimal
36+
toolchain: ${{ matrix.toolchain }}
37+
override: true
38+
components: clippy, rustfmt
39+
- name: Cache cargo registry
40+
uses: actions/cache@v1
41+
with:
42+
path: ~/.cargo/registry/cache
43+
key: ${{ runner.os }}-${{ matrix.conf }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
44+
restore-keys: |
45+
${{ runner.os }}-${{ matrix.conf }}-cargo-registry-
46+
- name: Run rustfmt
47+
if: matrix.toolchain == 'stable'
48+
uses: actions-rs/cargo@v1
49+
with:
50+
command: fmt
51+
args: -- --check
52+
- name: Run clippy
53+
if: matrix.toolchain == 'stable'
54+
uses: actions-rs/clippy-check@v1
55+
with:
56+
token: ${{ secrets.GITHUB_TOKEN }}
57+
args: -- -D warnings
58+
# FIXME: criterion and its dependencies require a newer version than 1.62, but it is only used for benchmarks.
59+
# Is there a way to not have criterion built when we run tests?
60+
- name: Run cargo check
61+
if: matrix.toolchain == '1.62.0'
62+
run: cargo check
63+
- name: Run tests
64+
if: matrix.toolchain != '1.62.0'
65+
run: cargo test
66+
- name: Build benchmarks
67+
if: matrix.toolchain == 'stable'
68+
run: cargo bench --no-run
69+
- name: Build docs
70+
run: cargo doc --no-deps

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### Version 0.2.5
1+
### Version 0.2.6
22

33
- fix: ON UPDATE with two many blank formatted incorrectly (#46)
44
- fix: `EXCEPT` not handled well

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "sqlformat"
3-
version = "0.2.5"
3+
version = "0.2.6"
44
authors = ["Josh Holmer <[email protected]>"]
55
edition = "2021"
6-
rust-version = "1.56"
6+
rust-version = "1.62"
77
license = "MIT OR Apache-2.0"
88
homepage = "https://github.com/shssoichiro/sqlformat-rs"
99
repository = "https://github.com/shssoichiro/sqlformat-rs"
@@ -17,7 +17,7 @@ nom = "7.0.0"
1717
unicode_categories = "0.1.1"
1818

1919
[dev-dependencies]
20-
criterion = "0.5"
20+
criterion = "0.4"
2121
indoc = "2.0"
2222

2323
[[bench]]

benches/bench.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ fn issue_633(c: &mut Criterion) {
7777
const SIZE: usize = 1000;
7878

7979
pub struct UserData {
80-
pub id: i64,
8180
pub first_name: String,
8281
pub last_name: String,
8382
pub address: String,
@@ -87,7 +86,6 @@ fn issue_633(c: &mut Criterion) {
8786

8887
fn sample() -> UserData {
8988
UserData {
90-
id: -1,
9189
first_name: "FIRST_NAME".to_string(),
9290
last_name: "LAST_NAME".to_string(),
9391
address: "SOME_ADDRESS".to_string(),

src/formatter.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,14 @@ impl<'a> Formatter<'a> {
136136
}
137137

138138
fn format_with_spaces(&self, token: &Token<'_>, query: &mut String) {
139-
let value = if token.kind == TokenKind::Reserved {
140-
&self.equalize_whitespace(&self.format_reserved_word(token.value))
139+
if token.kind == TokenKind::Reserved {
140+
let value = self.equalize_whitespace(&self.format_reserved_word(token.value));
141+
query.push_str(&value);
142+
query.push(' ');
141143
} else {
142-
token.value
144+
query.push_str(token.value);
145+
query.push(' ');
143146
};
144-
query.push_str(value);
145-
query.push(' ');
146147
}
147148

148149
// Opening parentheses increase the block indent level and start a new line
@@ -248,7 +249,7 @@ impl<'a> Formatter<'a> {
248249
}
249250

250251
fn trim_spaces_end(&self, query: &mut String) {
251-
query.truncate(query.trim_end_matches(|c| c == ' ' || c == '\t').len());
252+
query.truncate(query.trim_end_matches([' ', '\t']).len());
252253
}
253254

254255
fn trim_all_spaces_end(&self, query: &mut String) {

src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,14 @@ pub enum Indent {
5555
Tabs,
5656
}
5757

58-
#[derive(Debug, Clone)]
58+
#[derive(Debug, Clone, Default)]
5959
pub enum QueryParams {
6060
Named(Vec<(String, String)>),
6161
Indexed(Vec<String>),
62+
#[default]
6263
None,
6364
}
6465

65-
impl Default for QueryParams {
66-
fn default() -> Self {
67-
QueryParams::None
68-
}
69-
}
70-
7166
#[cfg(test)]
7267
mod tests {
7368
use super::*;

0 commit comments

Comments
 (0)