Skip to content

Teach structured errors to display short Ty<'_> - #137201

Merged
bors merged 7 commits into
rust-lang:masterfrom
estebank:structured-errors-long-ty
Feb 26, 2025
Merged

Teach structured errors to display short Ty<'_>#137201
bors merged 7 commits into
rust-lang:masterfrom
estebank:structured-errors-long-ty

Conversation

@estebank

Copy link
Copy Markdown
Contributor

Make it so that in every structured error annotated with #[derive(Diagnostic)] that has a field of type Ty<'_>, the printing of that value into a String will look at the thread-local storage TyCtxt in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to.

error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)``
--> long.rs:7:5
|
6 | fn foo(x: D) { //~ `x` has type `(...
| - `x` has type `((..., ..., ..., ...), ..., ..., ...)`
7 | x(); //~ ERROR expected function, found `(...
| ^--
| |
| call expression requires function
|
= note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt'
= note: consider using `--verbose` to print the full type name to the console

Follow up to and response to the comments on #136898.

r? @oli-obk

@rustbotrustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Feb 18, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @rust-lang/wg-const-eval

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred in match checking

cc @Nadrieril

Some changes occurred to the CTFE machinery

cc @rust-lang/wg-const-eval

Some changes occurred in need_type_info.rs

cc @lcnr

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 18, 2025
Comment threadcompiler/rustc_errors/src/diagnostic.rs
@estebank
estebankforce-pushed the structured-errors-long-ty branch from d8758cd to 56a942bCompareFebruary 19, 2025 01:27
Comment threadcompiler/rustc_errors/src/diagnostic.rs Outdated
@estebank
estebankforce-pushed the structured-errors-long-ty branch from 56a942b to a33d786CompareFebruary 19, 2025 16:49
@rust-log-analyzer

This comment has been minimized.

Comment threadcompiler/rustc_errors/src/diagnostic.rs Outdated
Comment threadcompiler/rustc_middle/src/ty/predicate.rs
Comment threadcompiler/rustc_errors/src/diagnostic.rs
@oli-obk

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Feb 25, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 2dcd85f has been approved by oli-obk

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 25, 2025
fmease added a commit to fmease/rust that referenced this pull request Feb 25, 2025
…, r=oli-obk
Teach structured errors to display short `Ty<'_>`
Make it so that in every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to.
```
error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)``
--> long.rs:7:5
|
6 | fn foo(x: D) { //~ `x` has type `(...
| - `x` has type `((..., ..., ..., ...), ..., ..., ...)`
7 | x(); //~ ERROR expected function, found `(...
| ^--
| |
| call expression requires function
|
= note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt'
= note: consider using `--verbose` to print the full type name to the console
```
Follow up to and response to the comments on rust-lang#136898.
r? `@oli-obk`
@fmeasefmease mentioned this pull request Feb 25, 2025
@fmeasefmease closed this Feb 25, 2025
@fmeasefmease reopened this Feb 25, 2025
@fmease

fmease commented Feb 25, 2025

Copy link
Copy Markdown
Member

Needs rebase due to #135726 which added

implIntoDiagArgforRustcVersion{fninto_diag_arg(self) -> DiagArgValue{DiagArgValue::Str(Cow::Owned(self.to_string()))}}

to https://github.com/rust-lang/blobrust/blob/compiler/rustc_errors/src/diagnostic_impls.rs.

(CI failed in rollup #137607: #137607 (comment))

@bors r-

@borsbors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 25, 2025
@rust-log-analyzer

This comment has been minimized.

Make it so that every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to.
```
error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)``
--> long.rs:7:5
|
6 | fn foo(x: D) { //~ `x` has type `(...
| - `x` has type `((..., ..., ..., ...), ..., ..., ...)`
7 | x(); //~ ERROR expected function, found `(...
| ^--
| |
| call expression requires function
|
= note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt'
= note: consider using `--verbose` to print the full type name to the console
```
```
error[E0614]: type `(..., ..., ..., ...)` cannot be dereferenced
--> $DIR/long-E0614.rs:10:5
|
LL | *x;
| ^^ can't be dereferenced
|
= note: the full name for the type has been written to '$TEST_BUILD_DIR/$FILE.long-type-hash.txt'
= note: consider using `--verbose` to print the full type name to the console
```
@estebank
estebankforce-pushed the structured-errors-long-ty branch from 2dcd85f to c550beeCompareFebruary 25, 2025 17:27
@estebank

Copy link
Copy Markdown
ContributorAuthor

@bors r=oli-obk

@bors

bors commented Feb 26, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit c550bee has been approved by oli-obk

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 26, 2025
fmease added a commit to fmease/rust that referenced this pull request Feb 26, 2025
…, r=oli-obk
Teach structured errors to display short `Ty<'_>`
Make it so that in every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to.
```
error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)``
--> long.rs:7:5
|
6 | fn foo(x: D) { //~ `x` has type `(...
| - `x` has type `((..., ..., ..., ...), ..., ..., ...)`
7 | x(); //~ ERROR expected function, found `(...
| ^--
| |
| call expression requires function
|
= note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt'
= note: consider using `--verbose` to print the full type name to the console
```
Follow up to and response to the comments on rust-lang#136898.
r? `@oli-obk`
@fmeasefmease mentioned this pull request Feb 26, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2025
Rollup of 10 pull requests
Successful merges:
- rust-lang#134585 (remove `MaybeUninit::uninit_array`)
- rust-lang#136187 (Use less CString in the examples of CStr.)
- rust-lang#136457 (Expose algebraic floating point intrinsics)
- rust-lang#137201 (Teach structured errors to display short `Ty<'_>`)
- rust-lang#137620 (Fix `attr` cast for espidf)
- rust-lang#137631 (Avoid collecting associated types for undefined trait)
- rust-lang#137635 (Don't suggest constraining unstable associated types)
- rust-lang#137642 (Rustc dev guide subtree update)
- rust-lang#137660 (Update gcc submodule)
- rust-lang#137670 (revert accidental change in get_closest_merge_commit)
r? `@ghost`
`@rustbot` modify labels: rollup
@fmeasefmease mentioned this pull request Feb 26, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2025
Rollup of 10 pull requests
Successful merges:
- rust-lang#134585 (remove `MaybeUninit::uninit_array`)
- rust-lang#136187 (Use less CString in the examples of CStr.)
- rust-lang#137201 (Teach structured errors to display short `Ty<'_>`)
- rust-lang#137620 (Fix `attr` cast for espidf)
- rust-lang#137631 (Avoid collecting associated types for undefined trait)
- rust-lang#137635 (Don't suggest constraining unstable associated types)
- rust-lang#137642 (Rustc dev guide subtree update)
- rust-lang#137660 (Update gcc submodule)
- rust-lang#137670 (revert accidental change in get_closest_merge_commit)
- rust-lang#137671 (Make -Z unpretty=mir suggest -Z dump-mir as well for discoverability)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 5da5c37 into rust-lang:masterFeb 26, 2025
@rustbotrustbot added this to the 1.87.0 milestone Feb 26, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2025
Rollup merge of rust-lang#137201 - estebank:structured-errors-long-ty, r=oli-obk
Teach structured errors to display short `Ty<'_>`
Make it so that in every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to.
```
error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)``
--> long.rs:7:5
|
6 | fn foo(x: D) { //~ `x` has type `(...
| - `x` has type `((..., ..., ..., ...), ..., ..., ...)`
7 | x(); //~ ERROR expected function, found `(...
| ^--
| |
| call expression requires function
|
= note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt'
= note: consider using `--verbose` to print the full type name to the console
```
Follow up to and response to the comments on rust-lang#136898.
r? ``@oli-obk``
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@estebank@rustbot@rust-log-analyzer@oli-obk@bors@fmease@RalfJung