Skip to content

dependency_on_unit_never_type_fallback bad suggestion with APIT generics #133842

Closed
@ehuss

Description

@ehuss

The dependency_on_unit_never_type_fallback lint seems to provide a bad suggestion to include too many generic arguments when the function being called uses APIT. Example:

#![warn(rust_2024_compatibility)]

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

pub fn bar() -> Result<(), ()> {
    foo(|| {})?;
    Ok(())
}

Here this suggests the following change:

@@ -5,6 +5,6 @@
 }
 
 pub fn bar() -> Result<(), ()> {
-    foo(|| {})?;
+    foo::<(), _>(|| {})?;
     Ok(())
 }

However, this fails to compile because the function only takes one generic argument. The correct suggestion would be just ::<()>.

Meta

rustc 1.85.0-nightly (c44b3d50f 2024-12-03)
binary: rustc
commit-hash: c44b3d50fea96a3e0417e8264c16ea21a0a3fca2
commit-date: 2024-12-03
host: aarch64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.4

Metadata

Metadata

Labels

A-edition-2024Area: The 2024 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`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.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