diff --git a/.github/workflows/deploy-rust.yml b/.github/workflows/deploy-rust.yml index 8a00ff5..8df40ac 100644 --- a/.github/workflows/deploy-rust.yml +++ b/.github/workflows/deploy-rust.yml @@ -7,11 +7,13 @@ on: env: CARGO_TERM_COLOR: always - RUSTC_BOOTSTRAP: 1 jobs: quality-check: - uses: ./.github/workflows/rust.yml + permissions: + contents: read + issues: write + uses: ./.github/workflows/rust-stability.yml publish: environment: crates.io @@ -23,4 +25,4 @@ jobs: env: CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} run: - cargo publish + cargo +nightly publish diff --git a/.github/workflows/rust-stability.yml b/.github/workflows/rust-stability.yml index 466a245..2319ccb 100644 --- a/.github/workflows/rust-stability.yml +++ b/.github/workflows/rust-stability.yml @@ -2,6 +2,7 @@ name: Monthly stability checks on: workflow_dispatch: + workflow_call: pull_request: schedule: - cron: '0 3 6 * *' @@ -15,7 +16,6 @@ env: RUSTC_BOOTSTRAP: 1 jobs: - test: strategy: @@ -25,11 +25,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: ${{ matrix.channel }} + - name: update rust + run: rustup update - name: Run tests - run: cargo test --no-fail-fast + run: cargo +${{ matrix.channel }} test --no-fail-fast lint: strategy: @@ -39,12 +38,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: ${{ matrix.channel }} - components: "clippy" + - name: update rust + run: rustup update && rustup component add --toolchain ${{ matrix.channel }} clippy - name: clippy - run: cargo clippy -- --deny warnings + run: cargo +${{ matrix.channel }} clippy -- --deny warnings report: if: ${{ always() }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 01b9e28..10efa09 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -46,8 +46,6 @@ jobs: - uses: actions/checkout@v6 - name: clippy run: cargo clippy -- --deny warnings - - name: clippy the tests - run: cargo clippy --tests -- --deny warnings fmt: needs: skip_check diff --git a/build.rs b/build.rs index 23817e3..dd4c335 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,57 @@ -extern crate autocfg; +use autocfg::AutoCfg; fn main() { let ac = autocfg::new(); - ac.emit_path_cfg("std::assert_matches", "stable_assert_matches"); + stable_feature(&ac, "assert_matches"); + assert_matches_in_module(&ac); + assert_matches_in_root(&ac); +} + +fn stable_feature(ac: &AutoCfg, feature: &'static str) { + let cfg = format!("stable_{feature}"); + let code = format!( + r#" + #![deny(stable_features)] + #![feature({feature})] + "# + ); + + autocfg::emit_possibility(&cfg); + if ac.probe_raw(&code).is_err() { + autocfg::emit(&cfg); + } +} + +fn assert_matches_in_root(ac: &AutoCfg) { + let cfg = "assert_matches_in_root"; + let code = r#" + #![allow(stable_features)] + #![feature(assert_matches)] + use std::assert_matches; + + fn main() { + assert_matches!(Some(4), Some(_)); + } + "#; + autocfg::emit_possibility(cfg); + if ac.probe_raw(code).is_ok() { + autocfg::emit(cfg); + } +} + +fn assert_matches_in_module(ac: &AutoCfg) { + let cfg = "assert_matches_in_module"; + let code = r#" + #![allow(stable_features)] + #![feature(assert_matches)] + use std::assert_matches::assert_matches; + + fn main() { + assert_matches!(Some(4), Some(_)); + } + "#; + autocfg::emit_possibility(cfg); + if ac.probe_raw(code).is_ok() { + autocfg::emit(cfg); + } } diff --git a/src/lib.rs b/src/lib.rs index b8f4c47..0f98fe7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -603,10 +603,10 @@ impl From for TokenStream1 { #[cfg(test)] mod tests { - #[cfg(not(stable_assert_matches))] + #[cfg(assert_matches_in_module)] use std::assert_matches::assert_matches; - #[cfg(stable_assert_matches)] + #[cfg(assert_matches_in_root)] use std::assert_matches; use super::*;