From 1b63fbd6df49c8ec509bb9943e824068d046327e Mon Sep 17 00:00:00 2001 From: Liu Dingming Date: Tue, 26 Apr 2022 22:01:44 +0800 Subject: [PATCH] feat(derive): Start `unstable-v4` feature flag This is split out of #3661 as several changes I'm working on need it. --- .github/workflows/ci.yml | 6 +++++- Cargo.toml | 3 ++- Makefile | 4 ++-- clap_derive/Cargo.toml | 1 + tests/derive_ui.rs | 4 ++++ tests/derive_ui/{ => next}/tuple_struct.rs | 0 tests/derive_ui/next/tuple_struct.stderr | 20 +++++++++++++++++++ tests/derive_ui/stable/tuple_struct.rs | 18 +++++++++++++++++ .../{ => stable}/tuple_struct.stderr | 0 9 files changed, 52 insertions(+), 4 deletions(-) rename tests/derive_ui/{ => next}/tuple_struct.rs (100%) create mode 100644 tests/derive_ui/next/tuple_struct.stderr create mode 100644 tests/derive_ui/stable/tuple_struct.rs rename tests/derive_ui/{ => stable}/tuple_struct.stderr (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f2de4e9ab8..bacec0041a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -112,6 +112,10 @@ jobs: ui: name: UI Tests runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + features: [default, next] steps: - name: Checkout repository uses: actions/checkout@v3 @@ -123,7 +127,7 @@ jobs: override: true - uses: Swatinem/rust-cache@v1 - name: UI Tests - run: make test-ui + run: make test-ui-${{ matrix.features }} docs: name: Docs runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index f9e9d56c64a..37fda9e2c70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,7 +82,8 @@ unicode = ["textwrap/unicode-width", "unicase"] # Support for unicode character unstable-replace = [] unstable-multicall = [] unstable-grouped = [] -unstable-v4 = [] +# note: this will always enable clap_derive, change this to `clap_derive?/unstable-v4` when MSRV is bigger than 1.60 +unstable-v4 = ["clap_derive/unstable-v4"] [lib] bench = false diff --git a/Makefile b/Makefile index d428be77c37..a8a1acc54f6 100644 --- a/Makefile +++ b/Makefile @@ -33,5 +33,5 @@ test-%: clippy-%: cargo clippy ${_FEATURES_${@:clippy-%=%}} ${ARGS} --all-targets -- -D warnings -A deprecated -test-ui: - cargo +${MSRV} test --test derive_ui --features derive +test-ui-%: + cargo +${MSRV} test --test derive_ui --features derive ${_FEATURES_${@:test-ui-%=%}} diff --git a/clap_derive/Cargo.toml b/clap_derive/Cargo.toml index ba2ffc7b729..47234ea1089 100644 --- a/clap_derive/Cargo.toml +++ b/clap_derive/Cargo.toml @@ -44,6 +44,7 @@ proc-macro-error = "1" [features] default = [] debug = [] +unstable-v4 = [] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/tests/derive_ui.rs b/tests/derive_ui.rs index 1d2aadb92d9..c253a54ec16 100644 --- a/tests/derive_ui.rs +++ b/tests/derive_ui.rs @@ -11,4 +11,8 @@ fn ui() { let t = trybuild::TestCases::new(); t.compile_fail("tests/derive_ui/*.rs"); + #[cfg(feature = "unstable-v4")] + t.compile_fail("tests/derive_ui/next/*.rs"); + #[cfg(not(feature = "unstable-v4"))] + t.compile_fail("tests/derive_ui/stable/*.rs"); } diff --git a/tests/derive_ui/tuple_struct.rs b/tests/derive_ui/next/tuple_struct.rs similarity index 100% rename from tests/derive_ui/tuple_struct.rs rename to tests/derive_ui/next/tuple_struct.rs diff --git a/tests/derive_ui/next/tuple_struct.stderr b/tests/derive_ui/next/tuple_struct.stderr new file mode 100644 index 00000000000..a6f160fe89b --- /dev/null +++ b/tests/derive_ui/next/tuple_struct.stderr @@ -0,0 +1,20 @@ +error: `#[derive(Parser)]` only supports non-tuple structs and enums + --> tests/derive_ui/next/tuple_struct.rs:11:10 + | +11 | #[derive(Parser, Debug)] + | ^^^^^^ + | + = note: this error originates in the derive macro `Parser` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0599]: no function or associated item named `parse` found for struct `Opt` in the current scope + --> tests/derive_ui/next/tuple_struct.rs:16:20 + | +13 | struct Opt(u32); + | ---------------- function or associated item `parse` not found for this +... +16 | let opt = Opt::parse(); + | ^^^^^ function or associated item not found in `Opt` + | + = help: items from traits can only be used if the trait is implemented and in scope + = note: the following trait defines an item `parse`, perhaps you need to implement it: + candidate #1: `StructOpt` diff --git a/tests/derive_ui/stable/tuple_struct.rs b/tests/derive_ui/stable/tuple_struct.rs new file mode 100644 index 00000000000..18da78b9267 --- /dev/null +++ b/tests/derive_ui/stable/tuple_struct.rs @@ -0,0 +1,18 @@ +// Copyright 2018 Guillaume Pinot (@TeXitoi) +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use clap::Parser; + +#[derive(Parser, Debug)] +#[clap(name = "basic")] +struct Opt(u32); + +fn main() { + let opt = Opt::parse(); + println!("{:?}", opt); +} diff --git a/tests/derive_ui/tuple_struct.stderr b/tests/derive_ui/stable/tuple_struct.stderr similarity index 100% rename from tests/derive_ui/tuple_struct.stderr rename to tests/derive_ui/stable/tuple_struct.stderr