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

Sometimes RA reports errors that rustc doesn't agree exist #18542

Open
Lokathor opened this issue Nov 21, 2024 · 9 comments
Open

Sometimes RA reports errors that rustc doesn't agree exist #18542

Lokathor opened this issue Nov 21, 2024 · 9 comments
Labels
A-chalk chalk related issue A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@Lokathor
Copy link

Lately, in various places in my project I get errors like

parsing.rs
expected 2 arguments, found 1 [Ln 176, Col 6]

but the thing is: there's not a wrong number of arguments. the project builds with cargo build and runs with cargo run and even shows correct output. So why the heck is RA telling me about fake errors. I thought it was something to do with like, bad cached data or something, but even after deleting the target/ directory the same problem happened a few days later.

  • rust-analyzer version: rust-analyzer version: 0.3.2188-standalone (ba56d9b 2024-11-17) [c:\Users\Daniel.vscode\extensions\rust-lang.rust-analyzer-0.3.2188-win32-x64\server\rust-analyzer.exe]
  • rustc version: rustc 1.82.0-nightly (6de928dce 2024-08-18)
  • editor or extension: VSCode rust-analyzer extension
  • relevant settings: ??? I've no clue what could be related here.
  • repository link (if public, optional): https://github.com/Lokathor/yagbas/tree/1e2e182548b144c1d47de03126d3fc49d8f9d89b
@Lokathor Lokathor added the C-bug Category: bug label Nov 21, 2024
@lnicola
Copy link
Member

lnicola commented Nov 21, 2024

Can you post a screenshot of the error? r-a has its own diagnostics, which sometimes have false positives. It happens with Into, for example.

@Lokathor
Copy link
Author

Image

@lnicola
Copy link
Member

lnicola commented Nov 21, 2024

Yeah, given the bounds on that function, I'm not really surprised. Adding explicit type annotations usually works around this.

@Lokathor
Copy link
Author

uh, where? to the closure?

@lnicola
Copy link
Member

lnicola commented Nov 21, 2024

Maybe, or to what fn_body returns (splitting the chain at that point).

@Lokathor
Copy link
Author

Lokathor commented Nov 21, 2024

the type of fn_body is...

let fn_body: Labelled<NestedIn<Collect<SeparatedBy<MapWith<impl Parser<'_, I, Statement, Full<Rich<'_, TokenTree, FileSpan>, (), ()>> + 
Clone, Statement, impl Fn(Statement, &mut MapExtra<'_, '_, I, Full<Rich<'_, TokenTree, FileSpan>, (), ()>>) -> FileSpanned<Statement>>, 
Repeated<impl Parser<'_, I, (), Full<Rich<'_, TokenTree, FileSpan>, (), ()>> + Clone, (), I, Full<Rich<'_, TokenTree, FileSpan>, (), ()>>, 
FileSpanned<Statement>, (), I, Full<Rich<'_, TokenTree, FileSpan>, (), ()>>, FileSpanned<Statement>, {unknown}>, impl Parser<'_, I, I, 
Full<Rich<'_, TokenTree, FileSpan>, (), ()>> + Clone, I, Full<Rich<'_, TokenTree, FileSpan>, (), ()>, {unknown}, Full<Rich<'_, TokenTree, 
FileSpan>, (), ()>>, &str>

@lnicola
Copy link
Member

lnicola commented Nov 21, 2024

Try Go to definitions on those methods in the chain, one will probably be from the wrong trait.

@Lokathor
Copy link
Author

Lokathor commented Nov 21, 2024

I didn't write the chumsky library i'm using here, but all the steps in the chain seem to go to the right traits. (using Ctrl+clicking)

@lnicola
Copy link
Member

lnicola commented Nov 21, 2024

Ouch, we're so slow on that file. The problem is on map, we pick the wrong one:

Image

Explicitly choosing the trait fixes the false positive:

  let x = Parser::map(
    kw_fn_p().ignore_then(name).then(args).then(fn_body),
    |((name, arguments), statements)| Function { name, arguments, statements },
  )
  .labelled("function")
  .as_context();

@lnicola lnicola added A-ty type system / type inference / traits / method resolution A-chalk chalk related issue labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-chalk chalk related issue A-ty type system / type inference / traits / method resolution C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants