Skip to content

E0308 for Unit as Associated Type in a function that returns the Associated Type. #16987

@ghost

Description

What I saw:

expected <UnitVariableCollector as Visitor<'tcx>>::Result, found ()rust-analyzer[E0308](https://doc.rust-lang.org/stable/error_codes/E0308.html)

What I expected: Nothing

Why did I expect that: The program compiles. The trait has associated type Result, which is set to unit / ().

rust-analyzer version: rust-analyzer version: 0.4.1904-standalone (f5a9250 2024-03-29)

rustc version: rustc 1.79.0-nightly (1388d7a 2024-03-20)

editor or extension: VSCode / v0.4.1904 (pre-release)

relevant settings: ?

repository link (if public, optional): https://github.com/rust-lang/rust-clippy/blob/005b05f441b3082e9923e44f9dedcf416b1288e7/clippy_lints/src/unit_types/let_unit_value.rs#L114-L124

code snippet to reproduce:

struct UnitVariableCollector {
    id: HirId,
    spans: Vec<rustc_span::Span>,
}

impl UnitVariableCollector {
    fn new(id: HirId) -> Self {
        Self { id, spans: vec![] }
    }
}

impl<'tcx> Visitor<'tcx> for UnitVariableCollector {
    fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) -> Self::Result {
        if let ExprKind::Path(QPath::Resolved(None, path)) = ex.kind
            && let Res::Local(id) = path.res
            && id == self.id
        {
            self.spans.push(path.span);
        }
        rustc_hir::intravisit::walk_expr(self, ex);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions