Skip to content

Long type name emitted if the type name is part of a suggestion #135919

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

Open
5 of 10 tasks
weiznich opened this issue Jan 23, 2025 · 14 comments · Fixed by #135965
Open
5 of 10 tasks

Long type name emitted if the type name is part of a suggestion #135919

weiznich opened this issue Jan 23, 2025 · 14 comments · Fixed by #135965
Labels
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.

Comments

@weiznich
Copy link
Contributor

weiznich commented Jan 23, 2025

Code

use diesel::prelude::*; //diesel = { version = "2.2.6", default-features = false, features = ["postgres"] }

diesel::table! {
    foo (id) {
        id -> Int4,
        name -> Text,
    }
}

fn main() {
    diesel::debug_query(
        &foo::table
            .filter(foo::id.eq(42))
            .order(foo::name.desc())
            .limit(10)
            .offset(42),
    );
}

Current output

error[E0282]: type annotations needed
  --> src/main.rs:11:5
   |
11 |     diesel::debug_query(
   |     ^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `DB` declared on the function `debug_query`
   |
help: consider specifying the generic arguments
   |
11 |     diesel::debug_query::<DB, SelectStatement<FromClause<table>, query_builder::select_clause::DefaultSelectClause<FromClause<table>>, query_builder::distinct_clause::NoDistinctClause, query_builder::where_clause::WhereClause<diesel::expression::grouped::Grouped<diesel::expression::operators::Eq<columns::id, diesel::expression::bound::Bound<Integer, i32>>>>, query_builder::order_clause::OrderClause<diesel::expression::operators::Desc<columns::name>>, LimitOffsetClause<LimitClause<diesel::expression::bound::Bound<BigInt, i64>>, OffsetClause<diesel::expression::bound::Bound<BigInt, i64>>>>>(
   |                        ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Desired output

error[E0282]: type annotations needed
  --> src/main.rs:11:5
   |
11 |     diesel::debug_query(
   |     ^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `DB` declared on the function `debug_query`
   |
help: consider specifying the generic arguments
   |
11 |     diesel::debug_query::<DB, _>(
   |                           ++ 

Rationale and extra context

Emitting the query type there is not helpful for the users as it is long, makes the error message harder to read and ultimately is not even required to fix the code snippet. Fixing the code snippet only requires to specify the DB generic type there. Ideally rustc would be able to suggest possible types for DB there, given the existing constraint on debug_query. In the example above that's even only satisfied by one type (diesel::pg::Pg).

Other cases

If you change the exact query that you pass to debug_query the output changes. You can make the query more complex and therefore get a much more complex and longer query type in the compiler output.

Rust Version

rustc 1.86.0-nightly (649b995a9 2025-01-22)
binary: rustc
commit-hash: 649b995a9febd658b2570160703dff6fdc038ab2
commit-date: 2025-01-22
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Anything else?

cc @estebank as they expressed interested in such cases

List of cases

@weiznich weiznich 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 Jan 23, 2025
@theemathas

This comment has been minimized.

@theemathas

This comment has been minimized.

estebank added a commit to estebank/rust that referenced this issue Jan 23, 2025
We were previously printing the full type on the "this expression has type" label.

```
error[E0308]: mismatched types
  --> $DIR/secondary-label-with-long-type.rs:8:9
   |
LL |     let () = x;
   |         ^^   - this expression has type `((..., ..., ..., ...), ..., ..., ...)`
   |         |
   |         expected `((..., ..., ..., ...), ..., ..., ...)`, found `()`
   |
   = note:  expected tuple `((..., ..., ..., ...), ..., ..., ...)`
           found unit type `()`
   = note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/secondary-label-with-long-type/secondary-label-with-long-type.long-type-3987761834644699448.txt'
   = note: consider using `--verbose` to print the full type name to the console
```

Reported in a comment of rust-lang#135919.
@estebank
Copy link
Contributor

estebank commented Jan 23, 2025

The first comment is addressed in #135949. The second comment and original concern is addressed in #135965. Note that it doesn't shorten all long types, only the ones where some type parameters can be elided. It should work well enough for most cases, and pathological cases where the entire type is "important" for the suggestion... well, you kind of have no other alternative than spelling out the full type other than maybe break things up.

estebank added a commit to estebank/rust that referenced this issue Jan 24, 2025
We were previously printing the full type on the "this expression has type" label.

```
error[E0308]: mismatched types
  --> $DIR/secondary-label-with-long-type.rs:8:9
   |
LL |     let () = x;
   |         ^^   - this expression has type `((..., ..., ..., ...), ..., ..., ...)`
   |         |
   |         expected `((..., ..., ..., ...), ..., ..., ...)`, found `()`
   |
   = note:  expected tuple `((..., ..., ..., ...), ..., ..., ...)`
           found unit type `()`
   = note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/secondary-label-with-long-type/secondary-label-with-long-type.long-type-3987761834644699448.txt'
   = note: consider using `--verbose` to print the full type name to the console
```

Reported in a comment of rust-lang#135919.
@theemathas

This comment has been minimized.

@theemathas

This comment has been minimized.

@theemathas
Copy link
Contributor

Another version

type A = (i32, i32, i32, i32);
type B = (A, A, A, A);
type C = (B, B, B, B);
type D = (C, C, C, C);

const X = None::<D>;
error: missing type for `const` item
 --> src/lib.rs:6:8
  |
6 | const X = None::<D>;
  |        ^ help: provide a type for the constant: `: Option<((((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))))>`

@estebank
Copy link
Contributor

estebank commented Jan 24, 2025

For the 3rd case in the comments it's going to be hard to address because we don't have an equivalent to short_ty_string for bounds, and trying to replicate the output of bounds printing by taking the trait and the type breaks down when it comes to for lifetimes (they end up in the wrong place). The solution for that is to write a new short_bound_string method that can do that correctly, but it might take a while. For the 5th case right above, I don't think there's anything we can do to make that less ugly, beyond correctly tracking types and using them when possible. type erasure has been a long standing issue that we need to address, but given the vintage of the ticket I wouldn't hold my breath on it being done anytime soon ^_^'

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 24, 2025
Use short type string in E0308 secondary span label

We were previously printing the full type on the "this expression has type" label.

```
error[E0308]: mismatched types
  --> $DIR/secondary-label-with-long-type.rs:8:9
   |
LL |     let () = x;
   |         ^^   - this expression has type `((..., ..., ..., ...), ..., ..., ...)`
   |         |
   |         expected `((..., ..., ..., ...), ..., ..., ...)`, found `()`
   |
   = note:  expected tuple `((..., ..., ..., ...), ..., ..., ...)`
           found unit type `()`
   = note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/secondary-label-with-long-type/secondary-label-with-long-type.long-type-3987761834644699448.txt'
   = note: consider using `--verbose` to print the full type name to the console
```

Reported in a comment of rust-lang#135919.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 25, 2025
Rollup merge of rust-lang#135949 - estebank:shorten-ty, r=davidtwco

Use short type string in E0308 secondary span label

We were previously printing the full type on the "this expression has type" label.

```
error[E0308]: mismatched types
  --> $DIR/secondary-label-with-long-type.rs:8:9
   |
LL |     let () = x;
   |         ^^   - this expression has type `((..., ..., ..., ...), ..., ..., ...)`
   |         |
   |         expected `((..., ..., ..., ...), ..., ..., ...)`, found `()`
   |
   = note:  expected tuple `((..., ..., ..., ...), ..., ..., ...)`
           found unit type `()`
   = note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/secondary-label-with-long-type/secondary-label-with-long-type.long-type-3987761834644699448.txt'
   = note: consider using `--verbose` to print the full type name to the console
```

Reported in a comment of rust-lang#135919.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 25, 2025
Use short ty string for move errors

```
error[E0382]: use of moved value: `x`
  --> bay.rs:14:14
   |
12 | fn foo(x: D) {
   |        - move occurs because `x` has type `(((..., ..., ..., ...), ..., ..., ...), ..., ..., ...)`, which does not implement the `Copy` trait
13 |     let _a = x;
   |              - value moved here
14 |     let _b = x; //~ ERROR use of moved value
   |              ^ value used here after move
   |
   = note: the full type name has been written to 'bay.long-type-14349227078439097973.txt'
   = note: consider using `--verbose` to print the full type name to the console
help: consider cloning the value if the performance cost is acceptable
   |
13 |     let _a = x.clone();
   |               ++++++++
```

Address 4th case in rust-lang#135919.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 25, 2025
Rollup merge of rust-lang#136018 - estebank:long-moved-type, r=jieyouxu

Use short ty string for move errors

```
error[E0382]: use of moved value: `x`
  --> bay.rs:14:14
   |
12 | fn foo(x: D) {
   |        - move occurs because `x` has type `(((..., ..., ..., ...), ..., ..., ...), ..., ..., ...)`, which does not implement the `Copy` trait
13 |     let _a = x;
   |              - value moved here
14 |     let _b = x; //~ ERROR use of moved value
   |              ^ value used here after move
   |
   = note: the full type name has been written to 'bay.long-type-14349227078439097973.txt'
   = note: consider using `--verbose` to print the full type name to the console
help: consider cloning the value if the performance cost is acceptable
   |
13 |     let _a = x.clone();
   |               ++++++++
```

Address 4th case in rust-lang#135919.
@theemathas

This comment has been minimized.

estebank added a commit to estebank/rust that referenced this issue Jan 30, 2025
```
error[E0369]: cannot add `((..., ..., ..., ...), ..., ..., ...)` to `((..., ..., ..., ...), ..., ..., ...)`
  --> $DIR/binop.rs:9:7
   |
LL |     x + x;
   |     - ^ - ((..., ..., ..., ...), ..., ..., ...)
   |     |
   |     ((..., ..., ..., ...), ..., ..., ...)
   |
   = note: the full type name has been written to '$TEST_BUILD_DIR/diagnostic-width/binop/binop.long-type-hash.txt'
   = note: consider using `--verbose` to print the full type name to the console
```

CC rust-lang#135919.
@estebank
Copy link
Contributor

estebank commented Jan 31, 2025

With #136328 I ended up making it so that E0277 main message will also use the short type logic (actually, anything from the type system that is printable can use it now). It ended up being a bit of a refactoring, but I'm happy with it.

error[E0277]: the trait bound `(..., ..., ..., ...): Trait` is not satisfied
--> $DIR/long-e0277.rs:13:21
|
LL | require_trait::<D>();
| ^ unsatisfied trait bound
|
= help: the trait `Trait` is not implemented for `(..., ..., ..., ...)`
help: this trait has no implementations, consider adding one
--> $DIR/long-e0277.rs:8:1
|
LL | trait Trait {}
| ^^^^^^^^^^^
note: required by a bound in `require_trait`
--> $DIR/long-e0277.rs:10:21
|
LL | fn require_trait<T: Trait>() {}
| ^^^^^ required by this bound in `require_trait`
= note: the full name for the type has been written to '$TEST_BUILD_DIR/diagnostic-width/long-e0277/long-e0277.long-type-hash.txt'
= note: consider using `--verbose` to print the full type name to the console

estebank added a commit to estebank/rust that referenced this issue Jan 31, 2025
```
error[E0369]: cannot add `((..., ..., ..., ...), ..., ..., ...)` to `((..., ..., ..., ...), ..., ..., ...)`
  --> $DIR/binop.rs:9:7
   |
LL |     x + x;
   |     - ^ - ((..., ..., ..., ...), ..., ..., ...)
   |     |
   |     ((..., ..., ..., ...), ..., ..., ...)
   |
   = 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
```

```
error[E0600]: cannot apply unary operator `!` to type `(..., ..., ..., ...)`
  --> $DIR/binop.rs:14:5
   |
LL |     !x;
   |     ^^ cannot apply unary operator `!`
   |
   = 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
```

CC rust-lang#135919.
estebank added a commit to estebank/rust that referenced this issue Feb 2, 2025
```
error[E0369]: cannot add `((..., ..., ..., ...), ..., ..., ...)` to `((..., ..., ..., ...), ..., ..., ...)`
  --> $DIR/binop.rs:9:7
   |
LL |     x + x;
   |     - ^ - ((..., ..., ..., ...), ..., ..., ...)
   |     |
   |     ((..., ..., ..., ...), ..., ..., ...)
   |
   = 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
```

```
error[E0600]: cannot apply unary operator `!` to type `(..., ..., ..., ...)`
  --> $DIR/binop.rs:14:5
   |
LL |     !x;
   |     ^^ cannot apply unary operator `!`
   |
   = 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
```

CC rust-lang#135919.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Feb 6, 2025
Use short ty string for binop and unop errors

```
error[E0369]: cannot add `(..., ..., ..., ...)` to `(..., ..., ..., ...)`
  --> $DIR/binop.rs:10:7
   |
LL |     x + x;
   |     - ^ - (..., ..., ..., ...)
   |     |
   |     (..., ..., ..., ...)
   |
   = 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
```
```
error[E0600]: cannot apply unary operator `!` to type `(..., ..., ..., ...)`
  --> $DIR/binop.rs:14:5
   |
LL |     !x;
   |     ^^ cannot apply unary operator `!`
   |
   = 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
```

CC rust-lang#135919.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 6, 2025
Use short ty string for binop and unop errors

```
error[E0369]: cannot add `(..., ..., ..., ...)` to `(..., ..., ..., ...)`
  --> $DIR/binop.rs:10:7
   |
LL |     x + x;
   |     - ^ - (..., ..., ..., ...)
   |     |
   |     (..., ..., ..., ...)
   |
   = 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
```
```
error[E0600]: cannot apply unary operator `!` to type `(..., ..., ..., ...)`
  --> $DIR/binop.rs:14:5
   |
LL |     !x;
   |     ^^ cannot apply unary operator `!`
   |
   = 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
```

CC rust-lang#135919.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 6, 2025
Rollup merge of rust-lang#136315 - estebank:long-ty-binop, r=SparrowLii

Use short ty string for binop and unop errors

```
error[E0369]: cannot add `(..., ..., ..., ...)` to `(..., ..., ..., ...)`
  --> $DIR/binop.rs:10:7
   |
LL |     x + x;
   |     - ^ - (..., ..., ..., ...)
   |     |
   |     (..., ..., ..., ...)
   |
   = 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
```
```
error[E0600]: cannot apply unary operator `!` to type `(..., ..., ..., ...)`
  --> $DIR/binop.rs:14:5
   |
LL |     !x;
   |     ^^ cannot apply unary operator `!`
   |
   = 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
```

CC rust-lang#135919.
@theemathas
Copy link
Contributor

type A = (i32, i32, i32, i32);
type B = (A, A, A, A);
type C = (B, B, B, B);
type D = (C, C, C, C);

fn foo(x: D) {
    x.field;
}
error[E0609]: no field `field` on type `((((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))))`
 --> src/lib.rs:7:7
  |
7 |     x.field;
  |       ^^^^^ unknown field

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

@theemathas
Copy link
Contributor

type A = (i32, i32, i32, i32);
type B = (A, A, A, A);
type C = (B, B, B, B);
type D = (C, C, C, C);

fn foo(x: D) {
    x();
}
error[E0618]: expected function, found `((((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))))`
 --> src/lib.rs:7:5
  |
6 | fn foo(x: D) {
  |        - `x` has type `((((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))))`
7 |     x();
  |     ^--
  |     |
  |     call expression requires function

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

@theemathas
Copy link
Contributor

type A = (i32, i32, i32, i32);
type B = (A, A, A, A);
type C = (B, B, B, B);
type D = (C, C, C, C);

fn foo(x: D) {
    let [] = x;
}
error[E0529]: expected an array or slice, found `((((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))))`
 --> src/lib.rs:7:9
  |
7 |     let [] = x;
  |         ^^ pattern cannot match with input type `((((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))))`

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

@theemathas
Copy link
Contributor

type A = (i32, i32, i32, i32);
type B = (A, A, A, A);
type C = (B, B, B, B);
type D = (C, C, C, C);

fn foo(x: D) {
    *x;
}
error[E0614]: type `((((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))), (((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32)), ((i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32), (i32, i32, i32, i32))))` cannot be dereferenced
 --> src/lib.rs:7:5
  |
7 |     *x;
  |     ^^

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

Sorry if this is becoming spammy 😅

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 11, 2025
In "specify type" suggestion, skip type params that are already known

When we suggest specifying a type for an expression or pattern, like in a `let` binding, we previously would print the entire type as the type system knew it. We now look at the params that have *no* inference variables, so they are fully known to the type system which means that they don't need to be specified.

This helps in suggestions for types that are really long, because we can usually skip most of the type params and make the annotation as short as possible:

```
error[E0282]: type annotations needed for `Result<_, ((..., ..., ..., ...), ..., ..., ...)>`
  --> $DIR/really-long-type-in-let-binding-without-sufficient-type-info.rs:7:9
   |
LL |     let y = Err(x);
   |         ^   ------ type must be known at this point
   |
help: consider giving `y` an explicit type, where the type for type parameter `T` is specified
   |
LL |     let y: Result<T, _> = Err(x);
   |          ++++++++++++++
```

Fix rust-lang#135919.
@bors bors closed this as completed in 5ebacd1 Feb 12, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 12, 2025
Rollup merge of rust-lang#135965 - estebank:shorten-ty-sugg, r=lcnr

In "specify type" suggestion, skip type params that are already known

When we suggest specifying a type for an expression or pattern, like in a `let` binding, we previously would print the entire type as the type system knew it. We now look at the params that have *no* inference variables, so they are fully known to the type system which means that they don't need to be specified.

This helps in suggestions for types that are really long, because we can usually skip most of the type params and make the annotation as short as possible:

```
error[E0282]: type annotations needed for `Result<_, ((..., ..., ..., ...), ..., ..., ...)>`
  --> $DIR/really-long-type-in-let-binding-without-sufficient-type-info.rs:7:9
   |
LL |     let y = Err(x);
   |         ^   ------ type must be known at this point
   |
help: consider giving `y` an explicit type, where the type for type parameter `T` is specified
   |
LL |     let y: Result<T, _> = Err(x);
   |          ++++++++++++++
```

Fix rust-lang#135919.
@estebank
Copy link
Contributor

Keeping open as tracking issue for the other cases.

@estebank estebank reopened this Feb 12, 2025
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 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.

3 participants