rust-lang / rust-lang/rust-analyzer

FP `type annotations needed`, infer gives up on long iterator chains at some point

Open
#23,091 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-ty C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

maybe related to https://github.com/rust-lang/rust-analyzer/issues/11240

The following code

fn main() {
    let start: Option<u8> = None;

    let output = start
        .into_iter()
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .chain(None)
        .count();
}

comiled with rustc (cargo check):

    Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
    Checking _snippet_178 v0.1.0 (/tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178)
warning: unused variable: `output`
 --> src/main.rs:4:9
  |
4 |     let output = start
  |         ^^^^^^ help: if this is intentional, prefix it with an underscore: `_output`
  |
  = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

warning: `_snippet_178` (bin "_snippet_178") generated 1 warning (run `cargo fix --bin "_snippet_178" -p _snippet_178` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.89s

but errors were issued by rust-analyzer diagnostics

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 29, col: 15 } to LineCol { line: 29, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 30, col: 15 } to LineCol { line: 30, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 31, col: 15 } to LineCol { line: 31, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 32, col: 15 } to LineCol { line: 32, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 33, col: 15 } to LineCol { line: 33, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 34, col: 15 } to LineCol { line: 34, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 35, col: 15 } to LineCol { line: 35, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 36, col: 15 } to LineCol { line: 36, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 37, col: 15 } to LineCol { line: 37, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 38, col: 15 } to LineCol { line: 38, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 39, col: 15 } to LineCol { line: 39, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 40, col: 15 } to LineCol { line: 40, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 41, col: 15 } to LineCol { line: 41, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 42, col: 15 } to LineCol { line: 42, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 43, col: 15 } to LineCol { line: 43, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 44, col: 15 } to LineCol { line: 44, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 45, col: 15 } to LineCol { line: 45, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 46, col: 15 } to LineCol { line: 46, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 47, col: 15 } to LineCol { line: 47, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 48, col: 15 } to LineCol { line: 48, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 49, col: 15 } to LineCol { line: 49, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 50, col: 15 } to LineCol { line: 50, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 51, col: 15 } to LineCol { line: 51, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 52, col: 15 } to LineCol { line: 52, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 53, col: 15 } to LineCol { line: 53, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 54, col: 15 } to LineCol { line: 54, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 55, col: 15 } to LineCol { line: 55, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 56, col: 15 } to LineCol { line: 56, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 57, col: 15 } to LineCol { line: 57, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 58, col: 15 } to LineCol { line: 58, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 59, col: 15 } to LineCol { line: 59, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 60, col: 15 } to LineCol { line: 60, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 61, col: 15 } to LineCol { line: 61, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 62, col: 15 } to LineCol { line: 62, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 63, col: 15 } to LineCol { line: 63, col: 19 }: type annotations needed
full type: `Option<{unknown}>`

at crate _snippet_178, file /tmp/icemaker_global_tempdir.Te0xd0qSST2p/rustc_testrunner_tmpdir.FXj9h50hT9ig/_snippet_178/src/main.rs: Error RustcHardError("E0282") from LineCol { line: 64, col: 15 } to LineCol { line: 64, col: 19 }: type annotations needed
full type: `Option<{unknown}>`


diagnostic scan complete


Error: diagnostic error detected

Stack backtrace:
   0: <anyhow::Error>::msg::<&str>
             at /home/matthias/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.102/src/backtrace.rs:10:14
   1: anyhow::__private::format_err
             at /home/matthias/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.102/src/lib.rs:687:13
   2: <rust_analyzer::cli::flags::Diagnostics>::run_
             at /home/matthias/vcs/github/rust-analyzer/crates/rust-analyzer/src/cli/diagnostics.rs:123:13
   3: <rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}
             at /home/matthias/vcs/github/rust-analyzer/crates/rust-analyzer/src/cli/diagnostics.rs:20:29
   4: <stdx::thread::Builder>::spawn::<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}
             at /home/matthias/vcs/github/rust-analyzer/crates/stdx/src/thread.rs:74:13
   5: std::sys::backtrace::__rust_begin_short_backtrace::<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:166:18
   6: std::thread::lifecycle::spawn_unchecked::<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/lifecycle.rs:70:13
   7: <core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:275:9
   8: std::panicking::catch_unwind::do_call::<core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}>, core::result::Result<(), anyhow::Error>>
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:576:43
   9: std::panicking::catch_unwind::<core::result::Result<(), anyhow::Error>, core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}>>
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:544:19
  10: std::panic::catch_unwind::<core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}>, core::result::Result<(), anyhow::Error>>
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:359:14
  11: std::thread::lifecycle::spawn_unchecked::<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/lifecycle.rs:68:26
  12: <std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
             at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
  13: <alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output = ()> + core::marker::Send> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/1a98b1e135b254f209c67d447b6d8bcd56a859e0/library/alloc/src/boxed.rs:2318:9
  14: <std::sys::thread::unix::Thread>::new::thread_start
             at /rustc/1a98b1e135b254f209c67d447b6d8bcd56a859e0/library/std/src/sys/thread/unix.rs:123:17
  15: <unknown>
  16: <unknown>

version information

rust-analyzer 0.0.0 (352d11db5c 2026-08-08)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust snippet in the issue and run both cargo check and rust-analyzer diagnostics to reproduce the discrepancy. Trace how rust-analyzer handles type inference and diagnostics across the repeated chain(None) calls; done means the valid code no longer produces the reported E0282 errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.