rust-lang / rust-lang/rust-analyzer

Soundness of `proc-macro-srv` crate

Open
#19,342 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

When using rust-analyzer as a library[1], we've found it helpful to use the proc-macro-srv crate directly (rather than via the server binary).
Its API is not marked unsafe, but doesn't seem to be sound in the usual sense:

  • at a high level, dlopen() a caller-provided filename can obviously be UB without extra-lingual guarantees, this can't be avoided
  • there are some techniques (use of mmap) that are similar, but could be avoided by doing IO a different way

There are multiple reasonable approaches to safety here, e.g.:

  • mark most of the crate crate "unsafe" (but this probably bubbles all the way up to main())
  • keep the safe APIs, based on crate-level assumptions about the environment
  • say "this is an internal detail, we're not interested in safety contracts"

If there's some consensus on what the maintainers want here, I'd like to document/implement that.

[1] https://rust-lang.zulipchat.com/#narrow/channel/185405-t-compiler.2Frust-analyzer/topic/Bundling.20proc.20macros.20with.20rust-analyzer/with/504826746

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 reading the proc-macro-srv crate's public API and the dlopen and mmap paths described in the issue. Review the linked Zulip discussion and existing comments to determine whether maintainers want unsafe APIs, documented environmental assumptions, or an internal-detail designation. Done means the chosen safety contract is clearly documented or implemented consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
security, tooling
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.