Closed
Description
The dependency_on_unit_never_type_fallback
lint seems to suggest to add a ::<()>
type annotation inside a format string in some cases.
Example:
fn create_ok_default<C>() -> Result<C, ()>
where
C: Default,
{
Ok(C::default())
}
fn main() -> Result<(), ()> {
let (returned_value, _) = (|| {
let created = create_ok_default()?;
Ok((created, ()))
})()?;
let _ = format_args!("{:?}", returned_value);
Ok(())
}
Suggests the following changes
@@ -11,6 +11,6 @@ fn main() -> Result<(), ()> {
Ok((created, ()))
})()?;
- let _ = format_args!("{:?}", returned_value);
+ let _ = format_args!("{:?}::<()>", returned_value);
Ok(())
}
Raw Output
warning: this function depends on never type fallback being `()`
--> src/main.rs:8:1
|
8 | fn main() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: std::default::Default` will fail
--> src/main.rs:10:23
|
10 | let created = create_ok_default()?;
| ^^^^^^^^^^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default
help: use `()` annotations to avoid fallback changes
|
14 | let _ = format_args!("{:?}::<()>::<()>", returned_value);
| ++++++
warning: this let-binding has unit value
--> src/main.rs:10:9
|
10 | let created = create_ok_default()?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
= note: `#[warn(clippy::let_unit_value)]` on by default
help: omit the `let` binding
|
10 | create_ok_default()?;
|
help: variable `created` of type `()` can be replaced with explicit `()`
|
11 | Ok(((), ()))
| ~~
warning: `tmp` (bin "tmp") generated 2 warnings (run `cargo clippy --fix --bin "tmp"` to apply 2 suggestions)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
Meta
rustc --version --verbose
:
rustc 1.84.1 (e71f9a9a9 2025-01-27)
binary: rustc
commit-hash: e71f9a9a98b0faf423844bf0ba7438f29dc27d58
commit-date: 2025-01-27
host: aarch64-apple-darwin
release: 1.84.1
LLVM version: 19.1.5
This suggestion is not given on 1.83.0
Metadata
Metadata
Assignees
Labels
Area: Lints (warnings about flaws in source code) such as unused_mut.Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: Suggestions generated by the compiler applied by `cargo fix`Diagnostics: A structured suggestion resulting in incorrect code.Lint: dependency_on_unit_never_type_fallbackRelevant to the compiler team, which will review and decide on the PR/issue.