Skip to content

cargo fix fails, having introduced compilation warnings #83315

Not planned
@jimblandy

Description

@jimblandy
Contributor

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

Activity

jimblandy

jimblandy commented on Mar 20, 2021

@jimblandy
ContributorAuthor

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

ehuss commented on Mar 20, 2021

@ehuss
Contributor

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.

added
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
and removed
C-bugCategory: This is a bug.
on Jan 26, 2024
fmease

fmease commented on Jan 26, 2024

@fmease
Member

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

added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
and removed on Dec 21, 2024
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-edition-2018Area: The 2018 editionA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@jimblandy@ChrisDenton@fmease

        Issue actions

          cargo fix fails, having introduced compilation warnings · Issue #83315 · rust-lang/rust