Description
I was following @ChristopherBiscardi 's 2023 Advent of Code and noticed: https://github.com/ChristopherBiscardi/advent-of-code/blob/main/2023/rust/scripts/get-aoc-input.rs . I was following along in the past 2 months on stable rust (<1.81) and since I was not using nightly, I added a Cargo.toml file next to the script. Since the call for testing I have switched to nightly (rustc 1.85.0-nightly (6b6a867ae 2024-11-27)) but I cannot get ANY example to work.
Code
I tried this code:
#!/usr/bin/env -S cargo +nightly -Zscript
//! ```cargo
//! [dependencies]
//! clap = { version = "4.2", features = ["derive"] }
//! ```
use clap::Parser;
#[derive(Parser, Debug)]
#[clap(version)]
struct Args {
#[clap(short, long, help = "Path to config")]
config: Option<std::path::PathBuf>,
}
fn main() {
let args = Args::parse();
println!("{:?}", args);
}
I expected to see this happen: successful compilation
Instead, this happened:
$ ./test.rs --config file.toml
warning: `package.edition` is unspecified, defaulting to `2024`
Compiling test- v0.0.0 (/Users/alycda/Desktop/RFC-3424)
error[E0432]: unresolved import `clap`
--> test.rs:8:5
|
8 | use clap::Parser;
| ^^^^ use of undeclared crate or module `clap`
error: cannot find attribute `clap` in this scope
--> test.rs:11:3
|
11 | #[clap(version)]
| ^^^^
error: cannot find attribute `clap` in this scope
--> test.rs:13:7
|
13 | #[clap(short, long, help = "Path to config")]
| ^^^^
error[E0599]: no function or associated item named `parse` found for struct `Args` in the current scope
--> test.rs:18:22
|
12 | struct Args {
| ----------- function or associated item `parse` not found for this struct
...
18 | let args = Args::parse();
| ^^^^^ function or associated item not found in `Args`
Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `test-` (bin "test-") due to 4 previous errors
Version it worked on
It must have worked on nightly ~December 2023, and even as recently as of april 21: https://github.com/hashintel/hash/blob/a4aee712cbc917ab175bdaf6ddff959eea3b31bb/rust-toolchain.toml#L2.
Version with regression
rustc --version --verbose
:
rustc 1.85.0-nightly (6b6a867ae 2024-11-27)
binary: rustc
commit-hash: 6b6a867ae9eac4e78d041ac4ee84be1072a48cf7
commit-date: 2024-11-27
host: aarch64-apple-darwin
release: 1.85.0-nightly
LLVM version: 19.1.4
Backtrace
Backtrace
warning: `package.edition` is unspecified, defaulting to `2024`
Compiling test- v0.0.0 (/Users/davisa/Desktop/untitled folder)
error[E0432]: unresolved import `clap`
--> test.rs:8:5
|
8 | use clap::Parser;
| ^^^^ use of undeclared crate or module `clap`
error: cannot find attribute `clap` in this scope
--> test.rs:11:3
|
11 | #[clap(version)]
| ^^^^
error: cannot find attribute `clap` in this scope
--> test.rs:13:7
|
13 | #[clap(short, long, help = "Path to config")]
| ^^^^
error[E0599]: no function or associated item named `parse` found for struct `Args` in the current scope
--> test.rs:18:22
|
12 | struct Args {
| ----------- function or associated item `parse` not found for this struct
...
18 | let args = Args::parse();
| ^^^^^ function or associated item not found in `Args`
Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.