Skip to content

Clap derive expansion no longer works on stable #79503

Closed
@pksunkara

Description

@pksunkara
Contributor

Code

Clap has the following test at clap_derive/tests/nested.rs:

use clap::Clap;

#[test]
fn use_option() {
    macro_rules! expand_ty {
        ($name:ident: $ty:ty) => {
            #[derive(Clap)]
            struct Outer {
                #[clap(short, long)]
                #[allow(dead_code)]
                $name: $ty,
            }
        };
    }

    expand_ty!(my_field: Option<String>);
}

As you can see from the latest master CI, it fails to compile on stable

Version it worked on

It most recently worked on: Successfully compiles and runs on 1.46.0

Version with regression

rustc --version --verbose:

rustc 1.48.0 (7eac88abb 2020-11-16)

Activity

pksunkara

pksunkara commented on Nov 28, 2020

@pksunkara
ContributorAuthor

Weirdly, when I use my mac to test this locally, it works.

→ rustup show active-toolchain
stable-x86_64-apple-darwin (default)
→ cargo test -p clap_derive --test nested --features "wrap_help yaml regex"
   Compiling ....
    Finished test [unoptimized + debuginfo] target(s) in 55.55s
     Running target/debug/deps/nested-55411ec307e7b9f1

running 1 test
test use_option ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

NOTE: macos stable fails on CI, so I don't think this is an OS issue.

On EC2, it fails with the above error from the CI:

→ rustup show active-toolchain
stable-x86_64-unknown-linux-gnu (default)
→ cargo test -p clap_derive --test nested --features "wrap_help yaml regex"
error[E0425]: cannot find value `arg_matches` in this scope
Error:   --> clap_derive/tests/nested.rs:32:26
   |
32 |     expand_ty!(my_field: Option<String>);
   |                          ^^^^^^ not found in this scope
added
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
regression-untriagedUntriaged performance or correctness regression.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Nov 28, 2020
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Nov 28, 2020
pksunkara

pksunkara commented on Nov 28, 2020

@pksunkara
ContributorAuthor

Pinging @petrochenkov because I suspect this is an issue with macro expansion. I tried cargo expand on the EC2 instance to check the output, but the code it had generated had no issues at all and successfully compiled.

Which is also the reason I couldn't generate a minimal reproducible example. I have no idea what's causing this.

added
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
on Nov 28, 2020
added
A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
on Nov 28, 2020
added
regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
and removed
regression-untriagedUntriaged performance or correctness regression.
on Nov 28, 2020
jyn514

jyn514 commented on Nov 28, 2020

@jyn514
Member

This works on 1.47 and breaks on 1.48.

added
E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
on Nov 28, 2020
jyn514

jyn514 commented on Nov 28, 2020

@jyn514
Member

searched nightlies: from nightly-2020-07-11 to nightly-2020-11-28
regressed nightly: nightly-2020-09-12
searched commits: from a1947b3 to 9911160
regressed commit: 94b4de0

bisected with cargo-bisect-rustc v0.5.2

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc -v --script ./test.sh --preserve --start 2020-07-11 

where test.sh is

#!/bin/sh
cargo test -p clap_derive --test nested
jyn514

jyn514 commented on Nov 28, 2020

@jyn514
Member

cc @Aaron1011 - #75800 broke clap.

Aaron1011

Aaron1011 commented on Nov 28, 2020

@Aaron1011
Member

This is due to a bug in how clap uses quote_spanned!. When #75800 was merged, we started preserving hygiene information in more cases, exposing the bug,

I've opened clap-rs/clap#2231 to fix the issue

Aaron1011

Aaron1011 commented on Nov 28, 2020

@Aaron1011
Member

@pksunkara: Do you know if this test was failing on nightlies prior to the stable release that broke this?

jyn514

jyn514 commented on Nov 28, 2020

@jyn514
Member

@Aaron1011 no, it was broken in #75800: #79503 (comment). That searched nightlies, not stable releases.

Aaron1011

Aaron1011 commented on Nov 28, 2020

@Aaron1011
Member

I mean, did the Clap CI tests start failing on nightly after that rust PR was merged?

pksunkara

pksunkara commented on Nov 28, 2020

@pksunkara
ContributorAuthor
pksunkara

pksunkara commented on Nov 28, 2020

@pksunkara
ContributorAuthor

To see a passing nightly CI run, check this, https://github.com/clap-rs/clap/runs/1393825395

pksunkara

pksunkara commented on Nov 28, 2020

@pksunkara
ContributorAuthor

I am closing this since the regression is not one. It looks like the original PR did a crater run, but the bugged code was in a test file. Thanks for help @Aaron1011

I am not sure why one of the nightlies wasn't failing, but that's a separate issue altogether.

removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Feb 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyE-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcE-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pksunkara@Aaron1011@jyn514@LeSeulArtichaut@rustbot

        Issue actions

          Clap derive expansion no longer works on stable · Issue #79503 · rust-lang/rust