Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single-file packages (RFC 3424) not working as documented #14868

Closed
alycda opened this issue Nov 28, 2024 · 3 comments
Closed

Single-file packages (RFC 3424) not working as documented #14868

alycda opened this issue Nov 28, 2024 · 3 comments
Labels
C-bug Category: bug Z-script Nightly: cargo script

Comments

@alycda
Copy link

alycda commented Nov 28, 2024

RE: rust-lang/rfcs#3424

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`.

@alycda alycda added the C-bug Category: bug label Nov 28, 2024
@alycda
Copy link
Author

alycda commented Nov 28, 2024

I guess I found the correct/updated documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#script

@jieyouxu jieyouxu removed the C-bug Category: bug label Nov 29, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Nov 29, 2024

AFAICT this is a cargo concern, which should probably be filed against the cargo issue tracker.

@jieyouxu jieyouxu added T-cargo Team: Cargo C-bug Category: bug labels Nov 29, 2024
@weihanglo weihanglo transferred this issue from rust-lang/rust Nov 29, 2024
@weihanglo weihanglo added Z-script Nightly: cargo script and removed T-cargo Team: Cargo labels Nov 29, 2024
@weihanglo
Copy link
Member

The only allowed frontmatter syntax has changed to ---. For more, see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Z-script Nightly: cargo script
Projects
None yet
Development

No branches or pull requests

3 participants