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

Invoking derived default() for tuple struct declared in function produces "Expected 1 argument, found 0" #7256

Closed
TedDriggs opened this issue Jan 12, 2021 · 5 comments
Labels
A-diagnostics diagnostics / error reporting S-actionable Someone could pick this issue up and work on it right now

Comments

@TedDriggs
Copy link

rust-analyzer version: 0.2.449

fn repro() {
    #[derive(Default)]
    struct EvidenceVisitor(String);
    let mut evidence_visitor = EvidenceVisitor::default();
}

This puts an error spanning EvidenceVisitor::default() which says "Expected 1 argument, found 0"

Adding a second member updates the error to "Expected 2 arguments, found 0"

Changing to an explicit impl Default for EvidenceVisitor doesn't change the error.

Changing to a unit struct or named struct makes the error disappear.

Moving the struct declaration outside the function body makes the error disappear. In the real code, I have the struct inside the function declaration because the whole function is cfg-gated, but the repro doesn't depend on conditional compilation.

@lnicola
Copy link
Member

lnicola commented Jan 12, 2021

Duplicate of #1559.

@lnicola lnicola closed this as completed Jan 12, 2021
@TedDriggs
Copy link
Author

Ah, sorry. I looked for the error I got and found #5502 but didn't find that one.

@flodiebold flodiebold reopened this Jan 12, 2021
@flodiebold
Copy link
Member

flodiebold commented Jan 12, 2021

Hmm there seems to be something going wrong with the name resolution there though, i.e. it looks like we resolve the EvidenceVisitor::default to the EvidenceVisitor constructor? We do have some basic support for function-local things which may be going wrong here, so I think it's worth checking whether there's something additional going on.

I.e. I'd expect EvidenceVisitor::default to not resolve at all, but then we wouldn't be emitting an error. It'd be interesting to see if the bug happens if the type is defined outside the function, but doesn't derive Default at all.

@flodiebold flodiebold added A-diagnostics diagnostics / error reporting S-actionable Someone could pick this issue up and work on it right now labels Jan 12, 2021
@jonas-schievink
Copy link
Contributor

This no longer occurs, but we still don't support local impls properly

@jonas-schievink
Copy link
Contributor

This is all fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

4 participants