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

cargo fix fails, having introduced compilation warnings #83315

Closed
jimblandy opened this issue Mar 20, 2021 · 3 comments
Closed

cargo fix fails, having introduced compilation warnings #83315

jimblandy opened this issue Mar 20, 2021 · 3 comments
Labels
A-edition-2018-lints Area: Lints supporting the 2018 edition A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jimblandy
Copy link
Contributor

jimblandy commented Mar 20, 2021

I tried to use cargo fix --edition-idioms, but it printed a lot of errors and declined to fix some things.

I've attached the output.
output.txt

Meta

rustc --version --verbose:

cargo 1.52.0-nightly (90691f2bf 2021-03-16)
release: 1.52.0
commit-hash: 90691f2bfe9a50291a98983b1ed2feab51d5ca55
commit-date: 2021-03-16
@jimblandy jimblandy added the C-bug Category: This is a bug. label Mar 20, 2021
@jimblandy
Copy link
Contributor Author

jimblandy commented Mar 20, 2021

I was able to get cargo fix --edition-idioms to succeed by fixing the following code manually.

The only change I made was to add an anonymous lifetime <'_> after std::fmt::Formatter in the Display impl.

macro_rules! stringy_enum {
    (pub enum $type:ident (parse error $error_type:ident :: $error_variant:ident) {
        $( $variant:ident = $name:tt ),* ,
    }) => {
        #[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
        pub enum $type {
            $( $variant ),*
        }

        impl $type {
            pub fn as_str(&self) -> &'static str {
                match self {
                    $( $type :: $variant => $name ),*
                }
            }
        }

        impl std::fmt::Display for $type {
            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
                f.write_str(self.as_str())
            }
        }

        impl std::str::FromStr for $type {
            type Err = $error_type;
            fn from_str(s: &str) -> std::result::Result<$type, $error_type> {
                Ok(match s {
                    $( $name => $type :: $variant ),* ,
                    _ => return Err($error_type :: $error_variant(s.to_string())),
                })
            }
        }
    }
}

Here's a sample use of the stringy_enum macro, if that helps:

stringy_enum! {
    pub enum SectionKind (parse error TreeError::ParseSectionKind) {
        Preface = "preface",
        Chapter = "chapter",
        Sect1 = "sect1",
        Sect2 = "sect2",
    }
}

@ehuss
Copy link
Contributor

ehuss commented Mar 20, 2021

Hi! I think this is a duplicate of #55768. I believe the issue is that when a macro is invoked multiple times, rustc is issuing a warning for each invocation, and cargo fix is applying all the duplicate suggestions.

@fmease fmease added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` A-edition-2018-lints Area: Lints supporting the 2018 edition T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. needs-triage-legacy labels Jan 26, 2024
@fmease
Copy link
Member

fmease commented Jan 26, 2024

Closing as duplicate of #55768 which was fixed by #90446.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018-lints Area: Lints supporting the 2018 edition A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants