Skip to content

Avoid suggesting closures when captures cross associated item boundaries - #162821

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
kulinsky:fix-153363-closure-suggestion
Sep 21, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
kulinsky:fix-153363-closure-suggestion

Conversation

@kulinsky

@kulinsky kulinsky commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #153363

We check the boundaries between a variable's declaration and its usage. If an associated item boundary is crossed, replacing a nested function with a closure does not eliminate this boundary. We retain the error but remove the ineffective suggestion.

The hint is preserved for an ordinary nested function capturing a local variable of the method.

Checks: full UI test run ./x test tests/ui --force-rerun, 21853 passed / 410 ignored, and ./x test tidy.

Used an LLM for code navigation

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 15, 2026
@rustbot

rustbot commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

r? @mejrs

rustbot has assigned @mejrs.
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: compiler
  • compiler expanded to 76 candidates
  • Random selection from 19 candidates

@mejrs mejrs left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors

rust-bors Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a757a13 has been approved by mejrs

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 21, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #163083 (Remove `G` generic param from `Diag<'_, G>`)
 - #160679 (Staticlib rename internal symbols: add COFF support)
 - #160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - #162007 (Preserve parentheses in raw borrow suggestions)
 - #162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - #163057 (Use span context for enclosing item(s) of unmet bound)
 - #163070 (label the path segment that is not an associated item of the trait)
 - #163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - #163107 (Implement Allocator for Pin unstably)
 - #163108 (remove old solver use of `SolverRelating`)
rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #163083 (Remove `G` generic param from `Diag<'_, G>`)
 - #160679 (Staticlib rename internal symbols: add COFF support)
 - #160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - #162007 (Preserve parentheses in raw borrow suggestions)
 - #162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - #163057 (Use span context for enclosing item(s) of unmet bound)
 - #163070 (label the path segment that is not an associated item of the trait)
 - #163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - #163107 (Implement Allocator for Pin unstably)
 - #163108 (remove old solver use of `SolverRelating`)
@rust-bors
rust-bors Bot merged commit 0c365b0 into rust-lang:main Sep 21, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 21, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
Rollup merge of #162821 - kulinsky:fix-153363-closure-suggestion, r=mejrs

Avoid suggesting closures when captures cross associated item boundaries

Fixes #153363

We check the boundaries between a variable's declaration and its usage. If an associated item boundary is crossed, replacing a nested function with a closure does not eliminate this boundary. We retain the error but remove the ineffective suggestion.

The hint is preserved for an ordinary nested function capturing a local variable of the method.

Checks: full UI test run `./x test tests/ui --force-rerun`, 21853 passed / 410 ignored, and `./x test tidy`.

Used an LLM for code navigation
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Sep 21, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#163083 (Remove `G` generic param from `Diag<'_, G>`)
 - rust-lang/rust#160679 (Staticlib rename internal symbols: add COFF support)
 - rust-lang/rust#160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - rust-lang/rust#162007 (Preserve parentheses in raw borrow suggestions)
 - rust-lang/rust#162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - rust-lang/rust#163057 (Use span context for enclosing item(s) of unmet bound)
 - rust-lang/rust#163070 (label the path segment that is not an associated item of the trait)
 - rust-lang/rust#163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - rust-lang/rust#163107 (Implement Allocator for Pin unstably)
 - rust-lang/rust#163108 (remove old solver use of `SolverRelating`)
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Sep 22, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#163083 (Remove `G` generic param from `Diag<'_, G>`)
 - rust-lang/rust#160679 (Staticlib rename internal symbols: add COFF support)
 - rust-lang/rust#160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - rust-lang/rust#162007 (Preserve parentheses in raw borrow suggestions)
 - rust-lang/rust#162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - rust-lang/rust#163057 (Use span context for enclosing item(s) of unmet bound)
 - rust-lang/rust#163070 (label the path segment that is not an associated item of the trait)
 - rust-lang/rust#163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - rust-lang/rust#163107 (Implement Allocator for Pin unstably)
 - rust-lang/rust#163108 (remove old solver use of `SolverRelating`)
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Sep 22, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#163083 (Remove `G` generic param from `Diag<'_, G>`)
 - rust-lang/rust#160679 (Staticlib rename internal symbols: add COFF support)
 - rust-lang/rust#160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - rust-lang/rust#162007 (Preserve parentheses in raw borrow suggestions)
 - rust-lang/rust#162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - rust-lang/rust#163057 (Use span context for enclosing item(s) of unmet bound)
 - rust-lang/rust#163070 (label the path segment that is not an associated item of the trait)
 - rust-lang/rust#163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - rust-lang/rust#163107 (Implement Allocator for Pin unstably)
 - rust-lang/rust#163108 (remove old solver use of `SolverRelating`)
makai410 pushed a commit to makai410/rust that referenced this pull request Oct 1, 2026
…nathanBrouwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang#163083 (Remove `G` generic param from `Diag<'_, G>`)
 - rust-lang#160679 (Staticlib rename internal symbols: add COFF support)
 - rust-lang#160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - rust-lang#162007 (Preserve parentheses in raw borrow suggestions)
 - rust-lang#162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - rust-lang#163057 (Use span context for enclosing item(s) of unmet bound)
 - rust-lang#163070 (label the path segment that is not an associated item of the trait)
 - rust-lang#163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - rust-lang#163107 (Implement Allocator for Pin unstably)
 - rust-lang#163108 (remove old solver use of `SolverRelating`)
makai410 pushed a commit to makai410/rustc_public that referenced this pull request Oct 1, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#163083 (Remove `G` generic param from `Diag<'_, G>`)
 - rust-lang/rust#160679 (Staticlib rename internal symbols: add COFF support)
 - rust-lang/rust#160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - rust-lang/rust#162007 (Preserve parentheses in raw borrow suggestions)
 - rust-lang/rust#162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - rust-lang/rust#163057 (Use span context for enclosing item(s) of unmet bound)
 - rust-lang/rust#163070 (label the path segment that is not an associated item of the trait)
 - rust-lang/rust#163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - rust-lang/rust#163107 (Implement Allocator for Pin unstably)
 - rust-lang/rust#163108 (remove old solver use of `SolverRelating`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E0434 suggests changing the fn item of a trait impl to a closure

3 participants