Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very wide type shows up in error output #121687

Closed
pacak opened this issue Feb 27, 2024 · 1 comment · Fixed by #121739
Closed

Very wide type shows up in error output #121687

pacak opened this issue Feb 27, 2024 · 1 comment · Fixed by #121739
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pacak
Copy link
Contributor

pacak commented Feb 27, 2024

Code

pub fn foo() -> impl std::fmt::Display {
    Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
        Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
            Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
                Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
                    Some(Some(Some(Some(Some(Some(Some(Some(())))))))),
                ))))))))))),
            ))))))))))),
        ))))))))))),
    )))))))))))
}

Current output

Compiling repr v0.1.0 (/home/pacak/tmp/repr)
error[E0277]: `Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<()>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` doesn't implement `std::fmt::Display`
  --> src/lib.rs:1:17
   |
1  |   pub fn foo() -> impl std::fmt::Display {
   |                   ^^^^^^^^^^^^^^^^^^^^^^ `Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<()>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` cannot be formatted with the default formatter
2  | /     Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
3  | |         Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
4  | |             Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
5  | |                 Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
...  |
9  | |         ))))))))))),
10 | |     )))))))))))
   | |_______________- return type was inferred to be `Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<()>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` here
   |
   = help: the trait `std::fmt::Display` is not implemented for `Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<Option<...>>>>>>>>>>>>>>>>>>>>>>>>>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

For more information about this error, try `rustc --explain E0277`.
error: could not compile `repr` (lib test) due to 1 previous error

Desired output

Anything that fits on a single line

Rationale and extra context

https://hachyderm.io/@ekuber/112004179050519020

Other cases

No response

Rust Version

rustc 1.78.0-nightly (1a648b397 2024-02-11)
binary: rustc
commit-hash: 1a648b397dedc98ada3dd3360f6d661ec2436c56
commit-date: 2024-02-11
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6


rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

Anything else?

No response

@pacak pacak added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 27, 2024
@pacak
Copy link
Contributor Author

pacak commented Feb 27, 2024

This example is very artificial, but this kind of type can be achieved easily with idiomatic code with chomsky, bpaf or any other library that uses combinators and tries to avoid allocations.

@jieyouxu jieyouxu added the D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. label Feb 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 2, 2024
Display short types for unimplemented trait

Shortens unimplemented trait diagnostics. Now shows:

```
error[E0277]: `Option<Option<Option<...>>>` doesn't implement `std::fmt::Display`
  --> $DIR/on_unimplemented_long_types.rs:4:17
   |
LL |   pub fn foo() -> impl std::fmt::Display {
   |                   ^^^^^^^^^^^^^^^^^^^^^^ `Option<Option<Option<...>>>` cannot be formatted with the default formatter
LL |
LL | /     Some(Some(Some(Some(Some(Some(Some(Some(Some(S...
LL | |         Some(Some(Some(Some(Some(Some(Some(Some(So...
LL | |             Some(Some(Some(Some(Some(Some(Some(Som...
LL | |                 Some(Some(Some(Some(Some(Some(Some...
...  |
LL | |         ))))))))))),
LL | |     )))))))))))
   | |_______________- return type was inferred to be `Option<Option<Option<...>>>` here
   |
   = help: the trait `std::fmt::Display` is not implemented for `Option<Option<Option<...>>>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
```

I'm not 100% sure if this is desirable, or if we should just let the long types remain long. This is also kinda a short-term bandaid solution. The real long term solution is to properly migrate `rustc_trait_selection`'s error reporting to use translatable diagnostics and then properly handle type name printing.

Fixes rust-lang#121687.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Mar 2, 2024
Display short types for unimplemented trait

Shortens unimplemented trait diagnostics. Now shows:

```
error[E0277]: `Option<Option<Option<...>>>` doesn't implement `std::fmt::Display`
  --> $DIR/on_unimplemented_long_types.rs:4:17
   |
LL |   pub fn foo() -> impl std::fmt::Display {
   |                   ^^^^^^^^^^^^^^^^^^^^^^ `Option<Option<Option<...>>>` cannot be formatted with the default formatter
LL |
LL | /     Some(Some(Some(Some(Some(Some(Some(Some(Some(S...
LL | |         Some(Some(Some(Some(Some(Some(Some(Some(So...
LL | |             Some(Some(Some(Some(Some(Some(Some(Som...
LL | |                 Some(Some(Some(Some(Some(Some(Some...
...  |
LL | |         ))))))))))),
LL | |     )))))))))))
   | |_______________- return type was inferred to be `Option<Option<Option<...>>>` here
   |
   = help: the trait `std::fmt::Display` is not implemented for `Option<Option<Option<...>>>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
```

I'm not 100% sure if this is desirable, or if we should just let the long types remain long. This is also kinda a short-term bandaid solution. The real long term solution is to properly migrate `rustc_trait_selection`'s error reporting to use translatable diagnostics and then properly handle type name printing.

Fixes rust-lang#121687.
@bors bors closed this as completed in 3432d1b Mar 2, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 2, 2024
Rollup merge of rust-lang#121739 - jieyouxu:loooong-typename, r=estebank

Display short types for unimplemented trait

Shortens unimplemented trait diagnostics. Now shows:

```
error[E0277]: `Option<Option<Option<...>>>` doesn't implement `std::fmt::Display`
  --> $DIR/on_unimplemented_long_types.rs:4:17
   |
LL |   pub fn foo() -> impl std::fmt::Display {
   |                   ^^^^^^^^^^^^^^^^^^^^^^ `Option<Option<Option<...>>>` cannot be formatted with the default formatter
LL |
LL | /     Some(Some(Some(Some(Some(Some(Some(Some(Some(S...
LL | |         Some(Some(Some(Some(Some(Some(Some(Some(So...
LL | |             Some(Some(Some(Some(Some(Some(Some(Som...
LL | |                 Some(Some(Some(Some(Some(Some(Some...
...  |
LL | |         ))))))))))),
LL | |     )))))))))))
   | |_______________- return type was inferred to be `Option<Option<Option<...>>>` here
   |
   = help: the trait `std::fmt::Display` is not implemented for `Option<Option<Option<...>>>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
```

I'm not 100% sure if this is desirable, or if we should just let the long types remain long. This is also kinda a short-term bandaid solution. The real long term solution is to properly migrate `rustc_trait_selection`'s error reporting to use translatable diagnostics and then properly handle type name printing.

Fixes rust-lang#121687.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants