Skip to content

fix: ignore explicitly typed variables in misleading_variable_name - #2016

Merged
smoelius merged 1 commit into
trailofbits:masterfrom
VrtxOmega:fix/misleading-variable-explicit-type
Jul 30, 2026
Merged

fix: ignore explicitly typed variables in misleading_variable_name#2016
smoelius merged 1 commit into
trailofbits:masterfrom
VrtxOmega:fix/misleading-variable-explicit-type

Conversation

@VrtxOmega

@VrtxOmega VrtxOmega commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #1903.

Summary

  • skip misleading_variable_name for let bindings with an explicit type annotation
  • add a UI regression case proving an explicitly typed binding stays quiet
  • document the new fourth condition and regenerate the checked-in example README

Verification

I locally verified the complete amended diff:

  • Before the fix, the explicit String binding produced a seventh warning and failed the UI fixture. After the fix, the standalone UI test passes while the six existing warning expectations remain unchanged.
  • PATH="$PWD/target/debug:$PATH" CARGO_TARGET_DIR="$PWD/target" cargo +nightly-2026-05-28 test --manifest-path examples/restriction/misleading_variable_name/Cargo.toml — 1 UI test passed
  • cargo test -p cargo-dylint --test ci format_example_readmes — 1 README consistency test passed
  • cargo +nightly-2026-05-28 fmt --all --check
  • git diff --check

Assistance disclosure

OpenAI Codex helped inspect the maintainer feedback and execute the local checks. I reviewed the code change, generated README, diff, and verification output before pushing.

@VrtxOmega
VrtxOmega requested a review from smoelius as a code owner July 29, 2026 19:56
@CLAassistant

CLAassistant commented Jul 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@smoelius

Copy link
Copy Markdown
Collaborator

Thanks, @VrtxOmega. Please forgive me for pasting the below Claude review, but I think I agree with it. Could you please address it?

I think the change should be straightforward, so please fold it into the current commit.

Also, please sign the CLA.

1. The doc comment and generated README are now inaccurate

src/lib.rs:24 still reads:

Checks for variables satisfying the following three conditions:

There are now four. The new condition — the variable has no explicit type annotation — is the one users are most likely to need, since it is the documented way to silence a false positive.

cargo-dylint/tests/ci.rs:343 regenerates every example's README.md from its lint doc comment and asserts equality, so the doc comment and
examples/restriction/misleading_variable_name/README.md must be updated together (BLESS=1 cargo test). CI passes today only because neither file was touched.

Suggested wording:

/// Checks for variables satisfying the following four conditions:
///
/// - The variable is declared without an explicit type.
/// - The variable is initialized with the result of a function call.
/// - The variable's name matches the name of a type defined within the module in which the
///   function is defined.
/// - The variable's type is not the matched type.

Signed-off-by: Rage Lopez <VrtxOmega@pm.me>
@VrtxOmega
VrtxOmega force-pushed the fix/misleading-variable-explicit-type branch from f62e467 to 86eddda Compare July 30, 2026 01:17
@VrtxOmega

Copy link
Copy Markdown
Contributor Author

Thanks — addressed in 86edddabe703dc113b10f23d6f24ad5e5cf39769 and folded into the existing commit as requested.

  • Updated the rustdoc to describe all four conditions.
  • Regenerated the checked-in README through format_example_readmes.
  • Signed the Trail of Bits CLA; the CLA check is now passing.
  • Re-ran the focused UI test, README consistency test, pinned-nightly format check, and git diff --check; all pass locally.

The amended CI matrix is running now.

@smoelius

Copy link
Copy Markdown
Collaborator

Beautiful. Thank you very much, @VrtxOmega!

@smoelius
smoelius added this pull request to the merge queue Jul 30, 2026
Merged via the queue into trailofbits:master with commit 41e2a17 Jul 30, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

misleading_variable_name works weirdly

3 participants