Skip to content

Bad suggestion in dependency_on_unit_never_type_fallback for fragment coming from a macro input #133766

Open
@ehuss

Description

@ehuss
Contributor

The following in 2021:

#![warn(dependency_on_unit_never_type_fallback)]

pub fn foo<T: Default>() -> Result<T, ()> {
    Err(())
}

macro_rules! m {
    ($x: ident) => {
        pub fn test() -> Result<(), ()> {
            $x()?;
            Ok(())
        }
    };
}

m!(foo);

produces a suggestion that results in the following change:

@@ -13,6 +13,6 @@
     };
 }
 
-m!(foo);
+m!(foo::<()>);

However, this is not valid because foo::<()> is not an ident, and you get an error about no rules matching.

Possible solutions

I don't know if this is fixable, since I can't think of a suggestion that would actually be valid in this scenario. At a minimum, I would say that it should not give a suggestion in this scenario (or at least make it MaybeIncorrect).

Meta

rustc 1.85.0-nightly (7442931d4 2024-11-30)
binary: rustc
commit-hash: 7442931d49b199ad0a1cc0f8ca54e327b5139b66
commit-date: 2024-11-30
host: aarch64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.4

Activity

added
C-bugCategory: This is a bug.
D-editionDiagnostics: An error or lint that should account for edition differences.
D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
on Dec 2, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Dec 2, 2024
added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Dec 2, 2024
traviscross

traviscross commented on Dec 17, 2024

@traviscross
Contributor
WaffleLapkin

WaffleLapkin commented on Dec 21, 2024

@WaffleLapkin
Member

The suggestion would work, if x would be defined as $x:path, so I would be against removing it. Making it MaybeIncorrect if macros are involved seems reasonable.

added
I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team.
on Jan 28, 2025
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-2024Area: The 2024 editionA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-editionDiagnostics: An error or lint that should account for edition differences.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team.L-dependency_on_unit_never_type_fallbackLint: dependency_on_unit_never_type_fallbackT-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@traviscross@WaffleLapkin@jieyouxu@rustbot

        Issue actions

          Bad suggestion in dependency_on_unit_never_type_fallback for fragment coming from a macro input · Issue #133766 · rust-lang/rust