Skip to content

Add new lint to detect dangling pointer return from closure #15154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PitiBouchon
Copy link

  • Finish some TODO
  • The lint name as_ptr_in_map is not good
  • Added passing UI tests (including committed .stderr file)
  • cargo test passes locally
  • Executed cargo dev update_lints
  • Added lint documentation
  • Run cargo dev fmt

The goal of this MR is to add a lint to detect dangling pointer from closure that can easily get undetected people think the closure should have took a reference instead of a value (see examples)

changelog: [as_ptr_in_map]: add a new lint to detect dangling pointer returned from closure

@rustbot
Copy link
Collaborator

rustbot commented Jun 27, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 27, 2025
@PitiBouchon PitiBouchon marked this pull request as draft June 27, 2025 00:22
@PitiBouchon
Copy link
Author

PitiBouchon commented Jun 27, 2025

The lint is working using two checks for a closure :

  • return a raw pointer
  • create a raw pointer from an owned parameter

if those two check are valid, the closure is potentially create a dangling pointer and should attract attention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants