diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a117259 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,128 @@ +name: CI + +on: + schedule: + - cron: '0 0 1 * *' + push: + pull_request: + +jobs: + rustfmt: + strategy: + fail-fast: false + matrix: + # Breaking changes like this might be mixed into the future stable versions. + # https://github.com/rust-lang/rustfmt/pull/3632 + channel: + - 1.38.0 + - stable + + name: Rustfmt (${{ matrix.channel }}) + runs-on: ubuntu-18.04 + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: rust-toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.channel }}-x86_64-unknown-linux-gnu + override: true + profile: default + + - name: '`cargo fmt -- --check`' + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + build: + strategy: + fail-fast: false + matrix: + toolchain: + # `x86_64-pc-windows-msvc` is tier 1 **for now**. + - 1.38.0-x86_64-pc-windows-msvc + - 1.38.0-x86_64-pc-windows-gnu + - 1.38.0-x86_64-apple-darwin + - 1.38.0-x86_64-unknown-linux-gnu + - stable-x86_64-pc-windows-msvc + - stable-x86_64-pc-windows-gnu + - stable-x86_64-apple-darwin + - stable-x86_64-unknown-linux-gnu + - beta-x86_64-pc-windows-msvc + - beta-x86_64-pc-windows-gnu + - beta-x86_64-apple-darwin + - beta-x86_64-unknown-linux-gnu + include: + - toolchain: 1.38.0-x86_64-pc-windows-msvc + os: windows-latest + - toolchain: 1.38.0-x86_64-pc-windows-gnu + os: windows-latest + - toolchain: 1.38.0-x86_64-apple-darwin + os: macOS-latest + - toolchain: 1.38.0-x86_64-unknown-linux-gnu + os: ubuntu-18.04 + - toolchain: stable-x86_64-pc-windows-msvc + os: windows-latest + - toolchain: stable-x86_64-pc-windows-gnu + os: windows-latest + - toolchain: stable-x86_64-apple-darwin + os: macOS-latest + - toolchain: stable-x86_64-unknown-linux-gnu + os: ubuntu-18.04 + - toolchain: beta-x86_64-pc-windows-msvc + os: windows-latest + - toolchain: beta-x86_64-pc-windows-gnu + os: windows-latest + - toolchain: beta-x86_64-apple-darwin + os: macOS-latest + - toolchain: beta-x86_64-unknown-linux-gnu + os: ubuntu-18.04 + + name: ${{ matrix.toolchain }} + runs-on: ${{ matrix.os }} + + steps: + - name: '`git config --global core.autocrlf false`' + run: git config --global core.autocrlf false + if: matrix.os == 'windows-latest' + + - name: Checkout + uses: actions/checkout@v1 + + - name: rust-toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.toolchain }} + override: true + profile: default + + - name: Determine features + id: features + run: | + if ${{ matrix.os == 'windows-latest' }}; then + echo '::set-output name=features::--no-default-features' + else + echo '::set-output name=features::--all-features' + fi + shell: bash + + - name: '`cargo clippy`' + uses: actions-rs/cargo@v1 + with: + command: clippy + args: ${{ steps.features.outputs.features }} -- -D warnings + + - name: '`cargo test`' + uses: actions-rs/cargo@v1 + with: + command: test + args: ${{ steps.features.outputs.features }} --no-fail-fast + + - name: '`cargo run --release`' + uses: actions-rs/cargo@v1 + with: + command: run + args: ${{ steps.features.outputs.features }} --release diff --git a/README.md b/README.md index 34f1e29..c1220cc 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ # AtCoder Rust Base (`ja-all-enabled`) +[![CI](https://github.com/rust-lang-ja/atcoder-rust-base/workflows/CI/badge.svg)](https://github.com/rust-lang-ja/atcoder-rust-base/actions?workflow=CI) + このリポジトリには[AtCoder][atcoder]コンテスト(競技プログラミング)にRustで参加するためのCargoパッケージテンプレートが用意されています。 パッケージは[cargo-generate][cargo-generate-crate]で作成します。 diff --git a/src/main.rs b/src/main.rs index c688830..b4f212c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,7 +225,7 @@ fn run_ascii() -> UnitResult { use std::str::FromStr; let s = AsciiString::from_str("2019-07-01")?; - let mut ix = s.as_str().match_indices("-"); + let mut ix = s.as_str().match_indices('-'); let (i0, _) = ix.next().ok_or_else(|| "got none")?; let (i1, _) = ix.next().ok_or_else(|| "got none")?; @@ -255,7 +255,7 @@ fn run_bitset_fixed() { use rand::prelude::*; use rand_distr::Uniform; - let rng = StdRng::seed_from_u64(114514); + let rng = StdRng::seed_from_u64(114_514); let dist = Uniform::from(0..2000); let n = rng @@ -345,9 +345,9 @@ fn run_rustc_hash() { let mut map = [('c', "Cindy"), ('a', "Alice"), ('b', "Bob")] .iter() - .map(|(c, s)| (*c, s.to_string())) + .map(|&(c, s)| (c, s.to_string())) .collect::>(); - map.entry('d').or_insert("Denis".to_string()); + map.entry('d').or_insert_with(|| "Denis".to_string()); map.insert('a', "Alexa".to_string()); assert_eq!(map.len(), 4); } @@ -417,6 +417,7 @@ fn calc_mean>(rng: &mut impl rand::Rng, distr: // regex and lazy_static // these codes were taken from examples on: https://docs.rs/regex/1.1.7/regex/ +#[allow(clippy::trivial_regex)] fn run_regex() -> UnitResult { use lazy_static::lazy_static; use regex::{Regex, RegexSet}; diff --git a/tests/test_jemallocator.rs b/tests/test_jemallocator.rs index c7badfa..63ab9ba 100644 --- a/tests/test_jemallocator.rs +++ b/tests/test_jemallocator.rs @@ -21,7 +21,7 @@ fn do_allocate_heap() -> UnitResult { use jemalloc_ctl::{epoch, stats}; use rand::prelude::*; - const SIZE: usize = 100000; + const SIZE: usize = 100_000; let mut rng = SmallRng::from_rng(thread_rng())?;