Commit Graph

1001 Commits

Author SHA1 Message Date
bors
42b2496320 Auto merge of #126597 - estebank:unicode-output, r=fmease
Add Unicode block-drawing compiler output support

Add nightly-only theming support to rustc output using Unicode box
drawing characters instead of ASCII-art to draw the terminal UI.

In order to enable, the flags `-Zunstable-options=yes --error-format=human-unicode` must be passed in.

After:

```
error: foo
  ╭▸ test.rs:3:3
  │
3 │       X0 Y0 Z0
  │   ┌───╿──│──┘
  │  ┌│───│──┘
  │ ┏││━━━┙
  │ ┃││
4 │ ┃││   X1 Y1 Z1
5 │ ┃││   X2 Y2 Z2
  │ ┃│└────╿──│──┘ `Z` label
  │ ┃└─────│──┤
  │ ┗━━━━━━┥  `Y` is a good letter too
  │        `X` is a good letter
  ╰╴
note: bar
  ╭▸ test.rs:4:3
  │
4 │ ┏   X1 Y1 Z1
5 │ ┃   X2 Y2 Z2
6 │ ┃   X3 Y3 Z3
  │ ┗━━━━━━━━━━┛
  ├ note: bar
  ╰ note: baz
note: qux
  ╭▸ test.rs:4:3
  │
4 │   X1 Y1 Z1
  ╰╴  ━━━━━━━━
```

Before:

```
error: foo
 --> test.rs:3:3
  |
3 |       X0 Y0 Z0
  |    ___^__-__-
  |   |___|__|
  |  ||___|
  | |||
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
  |
note: bar
 --> test.rs:4:3
  |
4 | /   X1 Y1 Z1
5 | |   X2 Y2 Z2
6 | |   X3 Y3 Z3
  | |__________^
  = note: bar
  = note: baz
note: qux
 --> test.rs:4:3
  |
4 |   X1 Y1 Z1
  |   ^^^^^^^^
```

After:

![rustc output with unicode box drawing characters](https://github.com/rust-lang/rust/assets/1606434/d210b79a-6579-4407-9706-ba8edc6e9f25)

Before:
![current rustc output with ASCII art](https://github.com/rust-lang/rust/assets/1606434/5aecccf8-a6ee-4469-8b39-72fb0d979a9f)
2024-11-11 00:00:58 +00:00
León Orell Valerian Liehr
acf6344b42
Address review comments 2024-11-10 23:57:18 +01:00
Esteban Küber
1d78004575
Add Unicode block-drawing compiler output support
Add nightly-only theming support to rustc output using Unicode box
drawing characters instead of ASCII-art to draw the terminal UI:

After:

```
error: foo
  ╭▸ test.rs:3:3
  │
3 │       X0 Y0 Z0
  │   ┌───╿──│──┘
  │  ┌│───│──┘
  │ ┏││━━━┙
  │ ┃││
4 │ ┃││   X1 Y1 Z1
5 │ ┃││   X2 Y2 Z2
  │ ┃│└────╿──│──┘ `Z` label
  │ ┃└─────│──┤
  │ ┗━━━━━━┥  `Y` is a good letter too
  │        `X` is a good letter
  ╰╴
note: bar
  ╭▸ test.rs:4:3
  │
4 │ ┏   X1 Y1 Z1
5 │ ┃   X2 Y2 Z2
6 │ ┃   X3 Y3 Z3
  │ ┗━━━━━━━━━━┛
  ├ note: bar
  ╰ note: baz
note: qux
  ╭▸ test.rs:4:3
  │
4 │   X1 Y1 Z1
  ╰╴  ━━━━━━━━
```

Before:

```
error: foo
 --> test.rs:3:3
  |
3 |       X0 Y0 Z0
  |    ___^__-__-
  |   |___|__|
  |  ||___|
  | |||
4 | |||   X1 Y1 Z1
5 | |||   X2 Y2 Z2
  | |||____^__-__- `Z` label
  | ||_____|__|
  | |______|  `Y` is a good letter too
  |        `X` is a good letter
  |
note: bar
 --> test.rs:4:3
  |
4 | /   X1 Y1 Z1
5 | |   X2 Y2 Z2
6 | |   X3 Y3 Z3
  | |__________^
  = note: bar
  = note: baz
note: qux
 --> test.rs:4:3
  |
4 |   X1 Y1 Z1
  |   ^^^^^^^^
```
2024-11-10 23:57:18 +01:00
Noratrieb
a26450cf81 Rename target triple to target tuple in many places in the compiler
This changes the naming to the new naming, used by `--print
target-tuple`.
It does not change all locations, but many.
2024-11-02 21:29:59 +01:00
Jubilee
5d0f52efa4
Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillot
compiler: apply clippy::clone_on_ref_ptr for CI

Apply lint https://rust-lang.github.io/rust-clippy/master/index.html#/clone_on_ref_ptr for compiler, also see https://github.com/rust-lang/rust/pull/131225#discussion_r1790109443.

Some Arc's can be misplaced with Lrc's, sorry.

https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/enable.20more.20clippy.20lints.20for.20compiler.20.28and.5Cor.20std.29
2024-10-29 03:11:39 -07:00
klensy
746b675c5a fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
Jubilee Young
4839d6e6e5 compiler: Add rustc_abi dependence to the compiler
Depend on rustc_abi in compiler crates that use it indirectly but have
not yet taken on that dependency, and are not entangled in my other PRs.
This leaves an "excise rustc_target" step after the dust settles.
2024-10-27 21:10:58 -07:00
Josh Triplett
ecdc2441b6 "innermost", "outermost", "leftmost", and "rightmost" don't need hyphens
These are all standard dictionary words and don't require hyphenation.
2024-10-23 02:45:24 -07:00
Matthias Krüger
df61a0b1b2
Rollup merge of #131344 - nnethercote:ref-Lrc, r=compiler-errors
Avoid `&Lrc<T>` in various places

Seeing `&Lrc<T>` is a bit suspicious, and `&T` or `Lrc<T>` is often better.

r? `@oli-obk`
2024-10-07 12:23:54 +02:00
Nicholas Nethercote
731469fee5 Convert Option<&Lrc<T>> return types to Option<&T>.
It's simpler and more concise.
2024-10-07 13:56:29 +11:00
Nicholas Nethercote
25d1ef1993 Remove InferCtxt::err_count_on_creation.
It's no longer used meaningfully.

This also means `DiagCtxtHandle::err_count_excluding_lint_errs` can be
removed.
2024-10-07 09:50:50 +11:00
klensy
26c09b6553 bump few deps
cargo_metadata, thorin-dwp, windows
2024-09-27 09:23:05 +03:00
Michael Goulet
c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Lieselotte
db09345ef6
Add suggestions for expressions in patterns 2024-09-18 20:38:43 +02:00
Veera
741005792e Implement a Method to Seal DiagInner's Suggestions 2024-09-12 21:27:44 -04:00
Michael Goulet
6d064295c8 clippy::useless_conversion 2024-09-11 17:52:53 -04:00
Camille GILLOT
6dfc4033be Do not ICE on expect(warnings). 2024-09-07 01:34:59 +00:00
Camille GILLOT
94f8347bae Check AttrId for expectations. 2024-09-06 20:51:06 +00:00
Matthias Krüger
cfb12716e9
Rollup merge of #129875 - Sajjon:sajjon_fix_typos_batch_1, r=compiler-errors,jieyouxu
chore: Fix typos in 'compiler' (batch 1)

Batch 1/3: Fixes typos in `compiler`

(See [issue](https://github.com/rust-lang/rust/issues/129874) tracking all PRs with typos fixes)
2024-09-02 22:35:20 +02:00
Alexander Cyon
ac69544a17
chore: Fix typos in 'compiler' (batch 1) 2024-09-02 07:42:38 +02:00
Camille GILLOT
5f1f45b095 Remove attr_id from stable lint ids. 2024-08-31 14:01:07 +00:00
Camille GILLOT
4928b22fa8 Use AttrId key for unstable<->stable expectation map. 2024-08-31 13:58:01 +00:00
Nicholas Nethercote
5fd503ab44 Add warn(unreachable_pub) to rustc_errors. 2024-08-27 12:03:37 +10:00
Pavel Grigorenko
53ce92770d Fix elided_named_lifetimes in code 2024-08-24 19:21:32 +03:00
Xiretza
c864238baf Update annotate-snippets to 0.11 2024-08-19 20:22:07 +00:00
Jaic1
8557b56ec7 Add | to make the html doc of Level rendered correctly 2024-08-14 13:38:03 +08:00
Guillaume Gomez
7c6dca9050
Rollup merge of #128978 - compiler-errors:assert-matches, r=jieyouxu
Use `assert_matches` around the compiler more

It's a useful assertion, especially since it actually prints out the LHS.
2024-08-12 17:09:19 +02:00
Michael Goulet
c361c924a0 Use assert_matches around the compiler 2024-08-11 12:25:39 -04:00
Matthias Krüger
32e0fe129d
Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errors
Use more slice patterns inside the compiler

Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'.

r? ghost
2024-08-11 07:51:51 +02:00
Nadrieril
c256de2253 Update std and compiler 2024-08-10 12:07:17 +02:00
Matthias Krüger
2066002b86
Rollup merge of #128852 - folkertdev:multipart-suggestion-stable-sort, r=compiler-errors
use stable sort to sort multipart diagnostics

I think a stable sort should be used to sort the different parts of a multipart selection. The current unstable sort uses the text of the suggestion as a tie-breaker. That just doesn't seem right, and the order of the input is a better choice I think, because it gives the diagnostic author more control.

This came up when I was building a suggestion where

```rust
fn foo() {}
```

must be turned into an unsafe function, and an attribute must be added

```rust
#[target_feature(enable = "...")]
unsafe fn foo() {}
```

In this example, the two suggestions occur at the same position, but the order is extremely important: unsafe must come after the attribute. But the situation changes if there is a pub/pub(crate), and if the unsafe is already present. It just out that because of the suggestion text, there is no way for me to order the suggestions correctly.

This change probably should be tested, but are there tests of the diagnostics code itself in the tests?

r? ```@estebank```
2024-08-09 18:24:58 +02:00
Folkert
38874a6927
use stable sort to sort multipart diagnostics 2024-08-09 09:45:01 +02:00
Matthias Krüger
f106496b82
Rollup merge of #128806 - estebank:color-config, r=jieyouxu
Split `ColorConfig` off of `HumanReadableErrorType`

The previous setup tied two unrelated things together. Splitting these two is a better model.

Identified by https://github.com/rust-lang/rust/pull/126597/files#r1667800754
2024-08-09 00:03:36 +02:00
Esteban Küber
95c1c34fff review comments 2024-08-08 14:58:52 +00:00
Esteban Küber
ae696f847d Split ColorConfig off of HumanReadableErrorType
The previous setup tied two unrelated things together. Splitting these two is a better model.
2024-08-08 14:41:33 +00:00
bors
d3a393932e Auto merge of #128465 - GrigorenkoPV:128200, r=estebank
Some `const { }` asserts for #128200

The correctness of code in #128200 relies on an array being sorted (so that it can be used in binary search later), which is currently enforced with `// tidy-alphabetical` (and characters being written in `\u{XXXX}` form), as well as lack of duplicate entries with conflicting keys, which is not currently enforced.

This PR changes it to using a `const{ }` assertion (and also checks for duplicate entries). Sadly, we cannot use the recently-stabilized `is_sorted_by_key` here, because it is not const (but it would not allow us to check for uniqueness anyways). Instead, let's write a manual loop.

Alternative approach (perfect hash function): #128463

r? `@ghost`
2024-08-08 09:59:09 +00:00
León Orell Valerian Liehr
c4c518d2d4
Use more slice patterns inside the compiler 2024-08-07 13:37:52 +02:00
Esteban Küber
034b73ba54 fix test 2024-08-06 19:09:52 +00:00
Esteban Küber
db6c05f9b9 Maintain highlighting in note and help even when they have a span 2024-08-06 17:54:37 +00:00
bors
93ea767e29 Auto merge of #126804 - estebank:short-error-primary-label, r=davidtwco
On short error format, append primary span label to message

The `error-format=short` output only displays the path, error code and main error message all in the same line. We now add the primary span label as well after the error message, to provide more context.
2024-08-06 07:06:24 +00:00
Pavel Grigorenko
15982b2fca rustc_errors: fix inaccurate comment 2024-08-06 09:26:47 +03:00
Pavel Grigorenko
b0a8944120 rustc_errors: enforce OUTPUT_REPLACEMENTS is sorted with a compile-time assertion 2024-08-06 09:26:47 +03:00
Esteban Küber
1bbaf6eb2f On short error format, append primary span label to message
The `error-format=short` output only displays the path, error code and
main error message all in the same line. We now add the primary span label
as well after the error message, to provide more context.
2024-08-06 04:08:10 +00:00
bors
8c7e0e1608 Auto merge of #128200 - estebank:normalize-whitespace, r=pnkfelix
Change output normalization logic to be linear against size of output

Modify the rendered output normalization routine to scan each character *once* and construct a `String` to be printed out to the terminal *once*, instead of using `String::replace` in a loop multiple times. The output doesn't change, but the time spent to prepare a diagnostic is now faster (or rather, closer to what it was before #127528).
2024-08-06 03:44:38 +00:00
Esteban Küber
8ce8c42e0b Do not underline suggestions for code that is already there
When a suggestion part is for already present code, do not highlight it. If after that there are no highlights left, do not show the suggestion at all.

Fix clippy lint suggestion incorrectly treated as `span_help`.
2024-08-01 18:53:42 +00:00
Esteban Küber
51b5bb1798 Enforce sort order 2024-07-30 00:18:38 +00:00
Esteban Küber
3945480ce7 Use fold instead of flat_map 2024-07-29 19:03:25 +00:00
Esteban Küber
6d9ee6ee26 Change output normalization logic to be linear against size of output
Scan strings to be normalized for printing in a linear scan and collect
the resulting `String` only once.

Use a binary search when looking for chars to be replaced, instead of a
`HashMap::get`.
2024-07-29 18:40:58 +00:00
Nicholas Nethercote
84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Matthias Krüger
cce2db06c0
Rollup merge of #127528 - estebank:ascii-control-chars, r=oli-obk
Replace ASCII control chars with Unicode Control Pictures

Replace ASCII control chars like `CR` with Unicode Control Pictures like `␍`:

```
error: bare CR not allowed in doc-comment
  --> $DIR/lex-bare-cr-string-literal-doc-comment.rs:3:32
   |
LL | /// doc comment with bare CR: '␍'
   |                                ^
```

Centralize the checking of unicode char width for the purposes of CLI display in one place. Account for the new replacements. Remove unneeded tracking of "zero-width" unicode chars, as we calculate these in the `SourceMap` as needed now.
2024-07-25 04:43:19 +02:00