Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Closed
m-rph opened this issue Apr 1, 2024 · 4 comments
Closed
Labels
C-bug Category: bug

Comments

@m-rph
Copy link

m-rph commented Apr 1, 2024

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 (1388d7a06 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);
    }
}
@m-rph m-rph added the C-bug Category: bug label Apr 1, 2024
@Veykril
Copy link
Member

Veykril commented Apr 1, 2024

This is due to the use of assoc type defaults here https://github.com/rust-lang/rust/blob/3d5528c287860b918e178a34f04ff903325571b3/compiler/rustc_hir/src/intravisit.rs#L221 which iirc we can't support without the new trait solver.

The diagnostic will be silenced by #16968

@roife
Copy link
Contributor

roife commented Apr 2, 2024

This issue has been resolved in #16968, so it can be closed now.

@Veykril Veykril closed this as completed Apr 2, 2024
@RalfJung
Copy link
Member

RalfJung commented Apr 4, 2024

I see a similar issue that does not involve a defaulted associated type; can I expect that to be the same problem?

expected <Result<{unknown}, InterpErrorInfo<'static>> as Try>::Output, found ()

That's for this code here. Notice the lack of a semicolon in the first arm. (That's an accident but rustc accepts it.)

@Veykril
Copy link
Member

Veykril commented Apr 4, 2024

#16968 will silence that error as well. Unsure what the problem there for the {unknown} is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

4 participants