rust-lang / rust-lang/rust-analyzer

clap:Parse throw an error but cargo check or cargo build is OK

Open
#16,414 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

cargo version: 1.75
rustc version:1.75

main.rs:

use clap::Parser;

#[derive(Parser)]
#[clap(
    version = "0.1.0",
    about = "ym",
    long_about = "ym_server"
)]
struct Opts {
    ///web端口
    #[clap(short, long, default_value = "80",env = "YM_PORT")]
    port: u16,
    ///sqlite为数据库路径,mysql为用户名:密码@ip:端口/数据库名(用户名密码需要urlencode)
    #[clap(short, long, default_value = "iot.db",env = "YM_DB")] 
    db: String,
    #[cfg(feature = "sqlite")]
    #[clap(short, long)]
    ///是否初始化,初始化会创建一个空的数据库,feature为sqlite时有效
    init: bool,
    #[clap(short, long, default_value = "ntp.aliyun.com:123")]
    #[cfg(all(target_arch = "arm",target_os = "linux"))]
    ///ntp服务器地址
    ntp:String,
}


fn main(){
    println!("Hello, world!")
}

cargo.toml:
_[package]
name = "tt"
version = "0.1.0"
edition = "2021"

See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = {version = "*", features = ["derive","env"] }_
image
fields are "init" and "ntp" which have "#[cfg]"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report from the provided main.rs and Cargo.toml, focusing on the cfg-gated init and ntp fields and comparing cargo check or cargo build with rust-analyzer diagnostics. Start by identifying the reported clap::Parser error in the editor; done means the diagnostic matches the successful Cargo result or the issue has a clearly documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.