Skip to content

Bad suggestion for dependency_on_unit_never_type_fallback for wildcard assignment expression #133688

Closed
@ehuss

Description

@ehuss

The dependency_on_unit_never_type_fallback lint seems to provide a bad suggestion for an assignment to a wildcard pattern. Example (sorry, not minimized further, this is based on serde):

#![deny(dependency_on_unit_never_type_fallback)]

pub trait Deserialize: Sized {
    fn deserialize<D>(deserializer: D) -> Result<Self, ()>
    where
        D: Deserializer;
}

pub trait Deserializer: Sized {}

pub trait MapAccess {
    fn next_value<V>(&mut self) -> Result<V, ()>
    where
        V: Deserialize;
}

impl Deserialize for () {
    fn deserialize<D>(_: D) -> Result<Self, ()>
    where
        D: Deserializer,
    {
        Ok(())
    }
}

fn visit_map<A>(mut map: A) -> Result<i32, ()>
where
    A: MapAccess,
{
    _ = map.next_value()?;
    Ok(1)
}

This gives a suggestion to modify it with:

@@ -29,7 +29,7 @@
 where
     A: MapAccess,
 {
-    _ = map.next_value()?;
+    _: () = map.next_value()?;
     Ok(1)
 }

This is not valid syntax, as an assignment expression does not allow qualifying with types.

In this case, I'm uncertain if the fallback can actually be a problem? If not, then maybe the lint shouldn't fire? Or if a type annotation is needed, then maybe use fully-qualified syntax?

cc @WaffleLapkin

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`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