<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/compiler/rustc_errors/src/lib.rs, branch 1.72.0</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=1.72.0</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=1.72.0'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2023-07-03T20:04:18+00:00</updated>
<entry>
<title>Add a simple markdown parser for formatting `rustc --explain`</title>
<updated>2023-07-03T20:04:18+00:00</updated>
<author>
<name>Trevor Gross</name>
<email>tmgross@umich.edu</email>
</author>
<published>2022-12-19T18:09:40+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=6a1c10bd85442f52f1d55d51005481cfa5cb40b5'/>
<id>urn:sha1:6a1c10bd85442f52f1d55d51005481cfa5cb40b5</id>
<content type='text'>
Currently, the output of `rustc --explain foo` displays the raw markdown in a
pager. This is acceptable, but using actual formatting makes it easier to
understand.

This patch consists of three major components:

1.  A markdown parser. This is an extremely simple non-backtracking recursive
    implementation that requires normalization of the final token stream
2.  A utility to write the token stream to an output buffer
3.  Configuration within rustc_driver_impl to invoke this combination for
    `--explain`. Like the current implementation, it first attempts to print to
    a pager with a fallback colorized terminal, and standard print as a last
    resort.

    If color is disabled, or if the output does not support it, or if printing
    with color fails, it will write the raw markdown (which matches current
    behavior).

    Pagers known to support color are: `less` (with `-r`), `bat` (aka `catbat`),
    and `delta`.

The markdown parser does not support the entire markdown specification, but
should support the following with reasonable accuracy:

-   Headings, including formatting
-   Comments
-   Code, inline and fenced block (no indented block)
-   Strong, emphasis, and strikethrough formatted text
-   Links, anchor, inline, and reference-style
-   Horizontal rules
-   Unordered and ordered list items, including formatting

This parser and writer should be reusable by other systems if ever needed.
</content>
</entry>
<entry>
<title>s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedList</title>
<updated>2023-06-14T07:28:54+00:00</updated>
<author>
<name>The 8472</name>
<email>git@infinite-source.de</email>
</author>
<published>2023-04-08T22:37:21+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=114d5f221c135e3267fbb966e2f0e582361cd8cb'/>
<id>urn:sha1:114d5f221c135e3267fbb966e2f0e582361cd8cb</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Respect `RUST_BACKTRACE` for delayed bugs</title>
<updated>2023-06-06T19:24:33+00:00</updated>
<author>
<name>Nilstrieb</name>
<email>48135649+Nilstrieb@users.noreply.github.com</email>
</author>
<published>2023-06-06T19:24:33+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=70980929b480d6c13e23d79ad8de2ff0afbce60c'/>
<id>urn:sha1:70980929b480d6c13e23d79ad8de2ff0afbce60c</id>
<content type='text'>
Sometimes, especially with MIR validation, the backtraces from delayed
bugs are noise and make it harder to look at them. Respect the
environment variable and don't print it when the user doesn't want it.
</content>
</entry>
<entry>
<title>Remove adt_const_params usage from compiler</title>
<updated>2023-06-01T18:21:42+00:00</updated>
<author>
<name>Michael Goulet</name>
<email>michael@errs.io</email>
</author>
<published>2023-05-19T22:04:25+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=97bacbab57128725887c3c9600bb0ad83ca42e50'/>
<id>urn:sha1:97bacbab57128725887c3c9600bb0ad83ca42e50</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Use `Cow` in `{D,Subd}iagnosticMessage`.</title>
<updated>2023-05-28T23:23:43+00:00</updated>
<author>
<name>Nicholas Nethercote</name>
<email>n.nethercote@gmail.com</email>
</author>
<published>2023-05-04T00:55:21+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=781111ef3591e4355c115593c4d75964b85555d6'/>
<id>urn:sha1:781111ef3591e4355c115593c4d75964b85555d6</id>
<content type='text'>
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow&lt;'static, str&gt;` be used here?
```
This commit answers that question in the affirmative. It's not the most
compelling change ever, but it might be worth merging.

This requires changing the `impl&lt;'a&gt; From&lt;&amp;'a str&gt;` impls to `impl
From&lt;&amp;'static str&gt;`, which involves a bunch of knock-on changes that
require/result in call sites being a little more precise about exactly
what kind of string they use to create errors, and not just `&amp;str`. This
will result in fewer unnecessary allocations, though this will not have
any notable perf effects given that these are error paths.

Note that I was lazy within Clippy, using `to_string` in a few places to
preserve the existing string imprecision. I could have used `impl
Into&lt;{D,Subd}iagnosticMessage&gt;` in various places as is done in the
compiler, but that would have required changes to *many* call sites
(mostly changing `&amp;format("...")` to `format!("...")`) which didn't seem
worthwhile.
</content>
</entry>
<entry>
<title>Use `Option::is_some_and` and `Result::is_ok_and` in the compiler</title>
<updated>2023-05-24T14:20:41+00:00</updated>
<author>
<name>Maybe Waffle</name>
<email>waffle.lapkin@gmail.com</email>
</author>
<published>2023-05-24T14:19:22+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=fb0f74a8c9e8b8f488ec5894d5d314caebf4c662'/>
<id>urn:sha1:fb0f74a8c9e8b8f488ec5894d5d314caebf4c662</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Check opaques for mismatch during writeback</title>
<updated>2023-05-22T23:33:34+00:00</updated>
<author>
<name>Michael Goulet</name>
<email>michael@errs.io</email>
</author>
<published>2023-05-22T23:33:34+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=0307db4a599ef142b7670489c674ae7abb9b5623'/>
<id>urn:sha1:0307db4a599ef142b7670489c674ae7abb9b5623</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Rollup merge of #111745 - Badel2:emitter-add-overflow, r=compiler-errors</title>
<updated>2023-05-21T14:02:59+00:00</updated>
<author>
<name>Matthias Krüger</name>
<email>matthias.krueger@famsik.de</email>
</author>
<published>2023-05-21T14:02:59+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=cb5dd1d5982909efa355f76f6524edd9616a5085'/>
<id>urn:sha1:cb5dd1d5982909efa355f76f6524edd9616a5085</id>
<content type='text'>
Fix overflow in error emitter

Fix #109854
Close #94171 (was already fixed before but missing test)

This bug happens when a multipart suggestion spans more than one line.

The fix is to update the `acc` variable, which didn't handle the case when the text to remove spans multiple lines but the text to add spans only one line.

Also, use `usize::try_from` instead of  `as usize` to detect overflows earlier in the future, and point to the source of the overflow (the original issue points to a different place where this value is used, not where the overflow had happened).

And finally add an `if start != end` check to avoid doing any extra work in case of empty ranges.

Long explanation:

Given this test case:

```rust
fn generate_setter() {
    String::with_capacity(
    //~^ ERROR this function takes 1 argument but 3 arguments were supplied
    generate_setter,
    r#"
pub(crate) struct Person&lt;T: Clone&gt; {}
"#,
     r#""#,
    );
}
```

The compiler will try to convert that code into the following:

```rust
fn generate_setter() {
    String::with_capacity(
    //~^ ERROR this function takes 1 argument but 3 arguments were supplied
    /* usize */,
    );
}
```

So it creates a suggestion with 3 separate parts:

```
// Replace "generate_setter" with "/* usize */"
SubstitutionPart { span: fuzz_input.rs:4:5: 4:20 (#0), snippet: "/* usize */" }
// Remove second arg (multiline string)
SubstitutionPart { span: fuzz_input.rs:4:20: 7:3 (#0), snippet: "" }
// Remove third arg (r#""#)
SubstitutionPart { span: fuzz_input.rs:7:3: 8:11 (#0), snippet: "" }
```

Each of this parts gets a separate `SubstitutionHighlight` (this marks the relevant text green in a terminal, the values are 0-indexed so `start: 4` means column 5):

```
SubstitutionHighlight { start: 4, end: 15 }
SubstitutionHighlight { start: 15, end: 15 }
SubstitutionHighlight { start: 18446744073709551614, end: 18446744073709551614 }
```

The 2nd and 3rd suggestion are empty (start = end) because they only remove text, so there are no additions to highlight. But the 3rd span has overflowed because the compiler assumes that the 3rd suggestion is on the same line as the first suggestion. The 2nd span starts at column 20 and the highlight starts at column 16 (15+1), so that suggestion is good. But since the 3rd span starts at column 3, the result is `3 - 4`, or column -1, which turns into -2 with 0-indexed, and that's equivalent to `18446744073709551614 as isize`.

With this fix, the resulting `SubstitutionHighlight` are:

```
SubstitutionHighlight { start: 4, end: 15 }
SubstitutionHighlight { start: 15, end: 15 }
SubstitutionHighlight { start: 15, end: 15 }
```

As expected. I guess ideally we shouldn't emit empty highlights when removing text, but I am too scared to change that.
</content>
</entry>
<entry>
<title>Fix overflow in error emitter</title>
<updated>2023-05-19T18:58:06+00:00</updated>
<author>
<name>Badel2</name>
<email>2badel2@gmail.com</email>
</author>
<published>2023-05-18T22:44:14+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=cbb41008fd43b512ffdbd35cebee2e4518b2181e'/>
<id>urn:sha1:cbb41008fd43b512ffdbd35cebee2e4518b2181e</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Give a more useful location for where a span_bug was delayed</title>
<updated>2023-05-18T04:15:22+00:00</updated>
<author>
<name>jyn</name>
<email>github@jyn.dev</email>
</author>
<published>2023-05-18T04:15:22+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e6a7fdedd720cce583f30cab41f67bf0a353a75a'/>
<id>urn:sha1:e6a7fdedd720cce583f30cab41f67bf0a353a75a</id>
<content type='text'>
Before:
```
   = note: delayed at    0: &lt;rustc_errors::HandlerInner&gt;::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1335:29
              1: &lt;rustc_errors::Handler&gt;::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1124:9
...
```

After:
```
   = note: delayed at compiler/rustc_parse/src/parser/diagnostics.rs:2158:28
              0: &lt;rustc_errors::HandlerInner&gt;::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1335:29
              1: &lt;rustc_errors::Handler&gt;::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1124:9
```

This both makes the relevant frame easier to find without having to dig
through diagnostic internals, and avoids the weird-looking formatting
for the first frame.
</content>
</entry>
</feed>
