rust-lang / rust-lang/rust-bindgen

Diagnostic implementation improvement

Open
#2,457 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

This is only a proposal and I am creating this issue for documentation.

@pvdrz has ideas and noting this down here. After the Diagnostic PR is merged, and eventually when we have time, we can improve things here.

Current implementation

First, a --emit-diagnostics flag is used to display diagnostics. You have to use --features=experimental flag with this because diagnostics are still behind experimental flag.

At this moment, the implementation is a module bindgen/diagnostics.rs which has a struct Diagnostic. This is with impl that allows us to create functions to build and display diagnostics, within other modules where we want to.

Proposal

A very early idea of the proposal is to have trait-based implementation. This would allow us to pass the bindgen context, which means it will allow us to remove code that is duplicated. Code like checking if the --emit-diagnostics flag was passed and is set.

Christian wrote, something like this -

trait Diagnostic {
    const level: DiagnosticLevel;
    fn title(&self, ctx) -> String;
    fn slices(&self, ctx) -> Vec<Slice>;
    fn footer(&self, ctx) -> Vec<IDontRemember>;
}

and we could then write a function

fn emit_diagnostic<D: Diagnostic>(diag: &D, ctx: &BindgenContext) {
      log!("{}", diag.title(ctx), D::level.into());
      if ctx.options().emit_diagnostics {
          // Build the diagnostic using the trait methods and display it
     }
}

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 with bindgen/diagnostics.rs and inspect the current Diagnostic implementation, then trace how --emit-diagnostics and --features=experimental are handled. Compare that behavior with the proposed Diagnostic trait and BindgenContext-based emitter. Done means the proposal is implemented without the duplicated flag-checking logic described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.