Skip to content

Nonsensical suggested type using chumsky select! (E0284) #123630

@schrottkatze

Description

@schrottkatze

Code

https://forge.katzen.cafe/schrottkatze/iowo/src/commit/bfd4b3765f35a98112b691d2f29c2c3446fe4d5c/crates/lang/src/parser.rs#L41-L44

Current output

error[E0284]: type annotations needed for `Select<{closure@/home/jade/.cargo/registry/src/index.crates.io-6f17d22bba15001f/chumsky-1.0.0-alpha.6/src/lib.rs:2782:13: 2782:28}, I, Expression<'_>, E>`
  --> crates/lang/src/parser.rs:41:13
   |
41 |         let lit = select! {
   |             ^^^
42 |             Token::Int(i) = e => Expression::new(Expr::Lit(ast::Lit::Int(i.parse().unwrap())), e.span()),
   |                                                                                                  ---- type must be known at this point
   |
   = note: cannot satisfy `<_ as chumsky::input::Input<'_>>::Span == SimpleSpan`
help: consider giving `lit` an explicit type, where the type for type parameter `I` is specified
   |
41 |         let lit: Select<{closure@/home/jade/.cargo/registry/src/index.crates.io-6f17d22bba15001f/chumsky-1.0.0-alpha.6/src/lib.rs:2782:13: 2782:28}, I, Expression<'_>, E> = select! {
   |                +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Desired output

No response

Rationale and extra context

This error is very confusing and unreadable, and the compiler even proposes adding a type containing a local path into the code.

That seems very problematic and incorrect.

Other cases

No response

Rust Version

rustc 1.77.0-nightly (190f4c961 2024-01-09)
binary: rustc
commit-hash: 190f4c96116a3b59b7de4881cfec544be0246d84
commit-date: 2024-01-09
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Anything else?

No response

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Apr 8, 2024
added
C-bugCategory: This is a bug.
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
D-confusingDiagnostics: Confusing error or lint that should be reworked.
D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
on Apr 8, 2024
compiler-errors

compiler-errors commented on Apr 8, 2024

@compiler-errors
Member

Try updating your nightly compiler and checking if it's still like that? You're using a nightly compiler from January.

estebank

estebank commented on Apr 8, 2024

@estebank
Contributor

To second compiler-errors' comment, I know that there was a change in this suggestion sometime in the past month.

Edit: nevermind

// FIXME: The same thing for closures, but this only works when the closure
// does not capture anything.

added 2 commits that reference this issue on Apr 10, 2024
77b09c2
a8b7056
self-assigned this
on Apr 10, 2024
added a commit that references this issue on Apr 10, 2024
796be88
added a commit that references this issue on Apr 10, 2024
d9bdf2a

8 remaining items

added
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
and removed
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
D-confusingDiagnostics: Confusing error or lint that should be reworked.
on Apr 13, 2024
pacak

pacak commented on Jun 30, 2024

@pacak
Contributor

Minimized reproduction in 1.77 nightly

struct Select<F, I>(F, I);

fn select<F, I>(filter: F) -> Select<F, I> {

}

fn parser1() {
    let lit = select(|x| match x {
        _ => (),
    });
}
% rustc --version
rustc 1.77.0-nightly (ca663b06c 2024-01-08)
error[E0308]: mismatched types
 --> src/lib.rs:3:31
  |
3 | fn select<F, I>(filter: F) -> Select<F, I> {
  |    ------                     ^^^^^^^^^^^^ expected `Select<F, I>`, found `()`
  |    |
  |    implicitly returns `()` as its body has no tail or `return` expression
  |
  = note: expected struct `Select<F, I>`
          found unit type `()`

error[E0282]: type annotations needed for `Select<{closure@src/lib.rs:8:22: 8:25}, I>`
 --> src/lib.rs:8:9
  |
8 |     let lit = select(|x| match x {
  |         ^^^
  |
help: consider giving `lit` an explicit type, where the type for type parameter `I` is specified
  |
8 |     let lit: Select<{closure@src/lib.rs:8:22: 8:25}, I> = select(|x| match x {
  |            ++++++++++++++++++++++++++++++++++++++++++++

Some errors have detailed explanations: E0282, E0308.
For more information about an error, try `rustc --explain E0282`.
added a commit that references this issue on Jun 30, 2024
added a commit that references this issue on Jun 30, 2024
added a commit that references this issue on Jun 30, 2024
added 2 commits that reference this issue on Jun 30, 2024
added a commit that references this issue on Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-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

    Participants

    @pacak@estebank@compiler-errors@jieyouxu@schrottkatze

    Issue actions

      Nonsensical suggested type using chumsky select! (E0284) · Issue #123630 · rust-lang/rust