rust-lang / rust-lang/rustc_public

Add Stable APIs to emit diagnostic messages

Open
#59 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
125
Forks
19
PR merge metrics
No merged PRs in 30d

Description

Provide a mechanism to emit diagnostic messages using StableMIR's Span. Maybe provide methods to emit error, warning, and note.
One possibility would be to provide an API similar to what is being proposed for proc_macro diagnostics:

// crate stable_mir

pub fn span_error(span: impl Spans, message: impl Message) -> proc_macro::Diagnostic;
pub fn span_warn(span: impl Spans, message: impl Message) -> proc_macro::Diagnostic;
pub fn span_note(span: impl Spans, message: impl Message) -> proc_macro::Diagnostic;

/// This could become an alias to proc_macro::Message once it gets added.
pub trait Message;

pub trait Spans {
    /// Converts `self` into a `Vec<Span>`.
    fn into_spans(self) -> Vec<Span>;
}

impl Message for String;
impl Message for &str;
impl Spans for Span;
impl<I: IntoIterator<Item = Span>> Spans for I;
impl<T> proc_macro::MultiSpan for T where T: Spans;

We should probably also add a function abort_if_errors() to allow tool developers to end some validation stage if any error was detected.

Contributor guide

No contributing guide indexed for this repository

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 reviewing the proposed proc_macro diagnostics API and the existing StableMIR Span concept. Define the stable APIs for error, warning, and note messages, including the Message and Spans traits, and decide how abort_if_errors should behave. Done means the diagnostic mechanism and validation-stage behavior are specified and implemented; no files or tests are named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
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.