From 35b010fac6443f07f11f979b86ecad8b6ed14fb3 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Sun, 8 Dec 2024 10:16:47 +0100 Subject: [PATCH] Add error message when using `cfg(docsrs)` with `RUSTFLAGS` --- .github/docsrs-error-1.60.txt | 2 ++ .github/docsrs-error-nightly.txt | 1 + .github/docsrs-error-stable.txt | 1 + .github/workflows/build.yaml | 54 ++++++++++++++++++++++++++++++++ src/lib.rs | 9 ++++-- src/time/system_time.rs | 6 ++-- 6 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 .github/docsrs-error-1.60.txt create mode 100644 .github/docsrs-error-nightly.txt create mode 100644 .github/docsrs-error-stable.txt diff --git a/.github/docsrs-error-1.60.txt b/.github/docsrs-error-1.60.txt new file mode 100644 index 0000000..09fa7ff --- /dev/null +++ b/.github/docsrs-error-1.60.txt @@ -0,0 +1,2 @@ +`--cfg docsrs` must only be used via `RUSTDOCFLAGS`, not `RUSTFLAGS` +aborting due to previous error diff --git a/.github/docsrs-error-nightly.txt b/.github/docsrs-error-nightly.txt new file mode 100644 index 0000000..3027533 --- /dev/null +++ b/.github/docsrs-error-nightly.txt @@ -0,0 +1 @@ +`--cfg docsrs` must only be used via `RUSTDOCFLAGS`, not `RUSTFLAGS` diff --git a/.github/docsrs-error-stable.txt b/.github/docsrs-error-stable.txt new file mode 100644 index 0000000..3027533 --- /dev/null +++ b/.github/docsrs-error-stable.txt @@ -0,0 +1 @@ +`--cfg docsrs` must only be used via `RUSTDOCFLAGS`, not `RUSTFLAGS` diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 69ef5c1..3196e7e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -204,3 +204,57 @@ jobs: cargo update -p syn --precise 2.0.67 - name: Build run: cargo build ${{ matrix.features.features }} --target ${{ matrix.target.target }} + + docsrs-error: + name: | + `cfg(docsrs)` error message ${{ matrix.target.description }} ${{ matrix.rust.description }} ${{ matrix.features.description }} + + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + target: + - { target: x86_64-unknown-linux-gnu, description: Native } + - { target: wasm32-unknown-unknown, description: Web } + - { target: wasm32v1-none, description: Wasm v1 } + rust: + - { version: "1.60", description: MSRV } + - { version: stable } + - { version: nightly } + # We don't check `serde` because it fails on the dependency itself already. + features: + - { features: "", no_std: false } + - { features: --no-default-features, no_std: true, description: (`no_std`) } + exclude: + - target: { target: x86_64-unknown-linux-gnu, description: Native } + rust: { version: nightly } + - target: { target: wasm32-unknown-unknown, description: Web } + rust: { version: nightly } + - target: { target: wasm32v1-none, description: Wasm v1 } + rust: { version: "1.60" } + - target: { target: wasm32v1-none, description: Wasm v1 } + rust: { version: stable } + - target: { target: wasm32v1-none, description: Wasm v1 } + features: { no_std: false } + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Rust + run: | + rustup toolchain install ${{ matrix.rust.version }} --profile minimal --target ${{ matrix.target.target }} + rustup default ${{ matrix.rust.version }} + - name: Fix MSRV dependencies + if: matrix.rust.version == '1.60' + run: | + cargo update -p bumpalo --precise 3.14.0 + cargo update -p serde --precise 1.0.210 + cargo update -p syn --precise 2.0.67 + - name: Build + env: + RUSTFLAGS: --cfg docsrs + run: + diff <(cargo build --target ${{ matrix.target.target }} ${{ matrix.features.features }} + --message-format json | jq -r "select(.reason == \"compiler-message\") | + .message.message") .github/docsrs-error-${{ matrix.rust.version }}.txt diff --git a/src/lib.rs b/src/lib.rs index 8526ee5..51a0641 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -153,7 +153,7 @@ #![cfg_attr(all(target_family = "wasm", not(feature = "std")), no_std)] #![cfg_attr(all(test, target_family = "wasm"), no_main)] -#![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(all(doc, docsrs), feature(doc_cfg))] #![cfg_attr(wasm_bindgen_unstable_test_coverage, feature(coverage_attribute))] #![cfg_attr( all( @@ -173,9 +173,9 @@ mod time; any(target_os = "unknown", target_os = "none"), feature = "std" ), - docsrs + all(doc, docsrs) ))] -#[cfg_attr(docsrs, doc(cfg(all(Web, feature = "std"))))] +#[cfg_attr(all(doc, docsrs), doc(cfg(all(Web, feature = "std"))))] pub mod web; #[cfg(not(all(target_family = "wasm", any(target_os = "unknown", target_os = "none"))))] @@ -187,6 +187,9 @@ use tests_web as _; #[cfg(all(target_family = "wasm", any(target_os = "unknown", target_os = "none")))] pub use self::time::*; +#[cfg(all(not(doc), docsrs))] +compile_error!("`--cfg docsrs` must only be used via `RUSTDOCFLAGS`, not `RUSTFLAGS`"); + #[cfg(all(test, target_family = "wasm"))] wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); diff --git a/src/time/system_time.rs b/src/time/system_time.rs index f73adad..866277f 100644 --- a/src/time/system_time.rs +++ b/src/time/system_time.rs @@ -6,7 +6,7 @@ doc = "[`std::time::SystemTime`]: https://doc.rust-lang.org/std/time/struct.SystemTime.html" )] -#[cfg(all(doc, not(feature = "std")))] +#[cfg(all(all(doc, docsrs), not(feature = "std")))] use core::error::Error; use core::fmt::{self, Display, Formatter}; use core::ops::{Add, AddAssign, Sub, SubAssign}; @@ -162,6 +162,6 @@ impl Display for SystemTimeError { } } -#[cfg(any(feature = "std", docsrs))] -#[cfg_attr(docsrs, doc(cfg(feature = "std")))] +#[cfg(any(feature = "std", all(doc, docsrs)))] +#[cfg_attr(all(doc, docsrs), doc(cfg(feature = "std")))] impl Error for SystemTimeError {}