Skip to content

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

Open
@ehuss

Description

@ehuss

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

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

    Issue actions