Skip to content

Adds the result_and_inner_method lint (suspicious, warn-by-default).#16879

Open
Souradip121 wants to merge 3 commits intorust-lang:masterfrom
Souradip121:lint-result-and-inner-method
Open

Adds the result_and_inner_method lint (suspicious, warn-by-default).#16879
Souradip121 wants to merge 3 commits intorust-lang:masterfrom
Souradip121:lint-result-and-inner-method

Conversation

@Souradip121
Copy link
Copy Markdown
Contributor

@Souradip121 Souradip121 commented Apr 17, 2026

Closes #16847

What the lint catches

Calling .and() on a Result<T, E> when the inner type T has an inherent method also named and. This is a footgun: Result::and discards the first Ok value entirely, which is rarely the intent when the inner type has its own and method.

// Before
fn foot_gun() -> Result<AndType, ()> {
    foo(0b0001).and(foo(0b1111))  // calls Result::and, discards first Ok value
}

// After (suggestion)
fn foot_gun() -> Result<AndType, ()> {
    Result::and(foo(0b0001), foo(0b1111))  // explicit: clearly calling Result::and
}

Conservative conditions (no false positives)

The lint is skipped when:

  • The receiver is not Result<T, E>
  • The inner type T has no inherent method named and (e.g. Result<u8, E> does not lint)
  • The call is already in fully-qualified form (Result::and(a, b))

Only inherent methods are checked, not trait methods, which keeps the scope tight and avoids surprising users who implement custom traits with an and method on an unrelated type.

changelog: [result_and_inner_method]: new lint that warns when Result::and is called and the inner Ok type has an inherent and method, suggesting fully-qualified syntax to make the intent explicit.

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Apr 17, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 17, 2026

r? @samueltardieu

rustbot has assigned @samueltardieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@samueltardieu
Copy link
Copy Markdown
Member

r? clippy

@rustbot rustbot assigned ada4a and unassigned samueltardieu Apr 23, 2026
@ada4a
Copy link
Copy Markdown
Contributor

ada4a commented Apr 23, 2026

sorry, don't have the capacity right now

r? clippy

@rustbot rustbot assigned Jarcho and unassigned ada4a Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Result::and should check if the inner type has an and method

5 participants