Skip to content

dependency_on_unit_never_type_fallback bad suggestion with APIT generics #133842

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
ehuss opened this issue Dec 4, 2024 · 1 comment · Fixed by #134144
Closed

dependency_on_unit_never_type_fallback bad suggestion with APIT generics #133842

ehuss opened this issue Dec 4, 2024 · 1 comment · Fixed by #134144
Assignees
Labels
A-edition-2024 Area: The 2024 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-edition Diagnostics: An error or lint that should account for edition differences. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-dependency_on_unit_never_type_fallback Lint: dependency_on_unit_never_type_fallback T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Dec 4, 2024

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
@ehuss ehuss added A-edition-2024 Area: The 2024 edition C-bug Category: This is a bug. D-edition Diagnostics: An error or lint that should account for edition differences. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-dependency_on_unit_never_type_fallback Lint: dependency_on_unit_never_type_fallback labels Dec 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 4, 2024
@jieyouxu jieyouxu added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 4, 2024
@traviscross
Copy link
Contributor

@compiler-errors compiler-errors self-assigned this Dec 10, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 12, 2024
…affleLapkin

Properly consider APITs for never type fallback ascription fix

Fixes rust-lang#133842
@bors bors closed this as completed in 296e0ba Dec 12, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 12, 2024
Rollup merge of rust-lang#134144 - compiler-errors:fallback-apit, r=WaffleLapkin

Properly consider APITs for never type fallback ascription fix

Fixes rust-lang#133842
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-edition-2024 Area: The 2024 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-edition Diagnostics: An error or lint that should account for edition differences. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. L-dependency_on_unit_never_type_fallback Lint: dependency_on_unit_never_type_fallback T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants