Skip to content

manual_filter suggests replacing and_then requiring mutable access with filter #17804

Description

@programmerlexi

Summary

Clippy suggest changing an Option::and_then usage with required mutable access into a Option::filter, when the manual_filter lint is active.

Reproducer

I have the following in my code:

Uart16550Tty::new_port(0x3f8, Config::DEFAULT)
    .ok()
    .and_then(|mut uart| {
        if uart.inner_mut().check_present() && uart.inner_mut().check_connected().is_ok() {
           Some(uart)
        } else {
            None
        }
    })

clippy suggest i replace the it with

Uart16550Tty::new_port(0x3f8, Config::DEFAULT)
    .ok()
    .filter(|mut uart| uart.inner_mut().check_present() && uart.inner_mut().check_connected().is_ok())

which is quite obviously incorrect and doesn't compile.

Version

rustc 1.100.0-nightly (feaadeeac 2026-09-19)
binary: rustc
commit-hash: feaadeeaca7db0594da854e7c8c07495341c7439
commit-date: 2026-09-19
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.1

Additional Labels

@rustbot label +I-suggestion-causes-error

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions