Skip to content

Suppress warnings caused by todo!() #75277

@SOF3

Description

@SOF3

todo!() is often used to quickly fill expressions that the developer currently does not have time/want to finish. However, use of todo!() often leads to the unreachable_code warning since it panics and the subsequent is not executable.

It is currently possible to suppress this warning at the crate level, #![allow(unreachable_code)], but this would result in suppressing legitimate unreachable code bugs as well. On the other hand, it is also possible to suppress this warning for each function that uses todo!(), but this introduces significantly more boilerplate (compare #[allow(unreachable_code)] 26 chars, need to move cursor to declaring block, vs todo!(), 7 chars in place).

According to the docs for todo!(), "todo! conveys an intent of implementing the functionality later". This implies that the TODO itself is already implies the current code is meant to be somewhat incorrect, and it is unlikely that a developer writing code after todo!() does not know it is unreachable.

Hence, subsequent code after todo!() shall not be considered unreachable, and the compiler shall suppress such warnings that would not have happened without todo!().

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.L-unreachable_codeLint: unreachable_codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions