-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
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. |
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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>;
|
For the 3rd case in the comments it's going to be hard to address because we don't have an equivalent to |
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.
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.
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.
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.
This comment has been minimized.
This comment has been minimized.
``` 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.
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. rust/tests/ui/diagnostic-width/long-e0277.stderr Lines 1 to 19 in af50c82
|
``` 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.
``` 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.
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.
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.
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.
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;
}
|
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();
}
|
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;
}
|
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;
}
Sorry if this is becoming spammy 😅 |
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.
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.
Keeping open as tracking issue for the other cases. |
Code
Current output
Desired output
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 forDB
there, given the existing constraint ondebug_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
Anything else?
cc @estebank as they expressed interested in such cases
List of cases
const
item" (not really addressable unless we suggest incomplete code)Ty<'_>
#137201Ty<'_>
#137201Ty<'_>
#137201Ty<'_>
#137201The text was updated successfully, but these errors were encountered: