rust-lang / rust-lang/rust

Detect boolean literals in logical expressions

Open
#127,801 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-lints T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
fn main() {
  let _ = false || true; // expect to throw a warning that it will always return `true`.
  let _ = true || false;
  let _ = false && true; // expect to throw a warning that it will always return `false`.
  let _ = true && false;
}
Current output
compile succeeded, and no warnings were reported.
Desired output

No response

Rationale and extra context

No response

Other cases

No response

Rust Version
rustc 1.81.0-nightly (24d2ac0b5 2024-07-15)
binary: rustc
commit-hash: 24d2ac0b56fcbde13d827745f66e73efb1e17156
commit-date: 2024-07-15
host: aarch64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7
Anything else?

No response

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 by compiling the supplied Rust snippet with the referenced rustc nightly and confirm that no warnings are emitted. Trace how the compiler handles logical expressions containing boolean literals, then add coverage for the always-true and always-false cases and verify that the expected warnings are emitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.