Skip to content

Commit

Permalink
Merge pull request clap-rs#3702 from epage/derive
Browse files Browse the repository at this point in the history
feat(derive): Start `unstable-v4` feature flag
  • Loading branch information
epage committed May 6, 2022
2 parents 36f8e47 + 1b63fbd commit 630dde7
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -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-%=%}}
1 change: 1 addition & 0 deletions clap_derive/Cargo.toml
Expand Up @@ -44,6 +44,7 @@ proc-macro-error = "1"
[features]
default = []
debug = []
unstable-v4 = []

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
4 changes: 4 additions & 0 deletions tests/derive_ui.rs
Expand Up @@ -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");
}
File renamed without changes.
20 changes: 20 additions & 0 deletions 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`
18 changes: 18 additions & 0 deletions tests/derive_ui/stable/tuple_struct.rs
@@ -0,0 +1,18 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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);
}
File renamed without changes.

0 comments on commit 630dde7

Please sign in to comment.