Skip to content

Commit 2970cd3

Browse files
committed
Make E0614 a structured error
``` 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 ```
1 parent 8413388 commit 2970cd3

File tree

13 files changed

+32
-22
lines changed

13 files changed

+32
-22
lines changed

compiler/rustc_hir_typeck/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ hir_typeck_cannot_cast_to_bool = cannot cast `{$expr_ty}` as `bool`
2828
.help = compare with zero instead
2929
.label = unsupported cast
3030
31+
hir_typeck_cant_dereference = type `{$ty}` cannot be dereferenced
32+
hir_typeck_cant_dereference_label = can't be dereferenced
33+
3134
hir_typeck_cast_enum_drop = cannot cast enum `{$expr_ty}` into integer `{$cast_ty}` because it implements `Drop`
3235
3336
hir_typeck_cast_thin_pointer_to_wide_pointer = cannot cast thin pointer `{$expr_ty}` to wide pointer `{$cast_ty}`

compiler/rustc_hir_typeck/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,15 @@ impl HelpUseLatestEdition {
454454
}
455455
}
456456

457+
#[derive(Diagnostic)]
458+
#[diag(hir_typeck_cant_dereference, code = E0614)]
459+
pub(crate) struct CantDereference<'tcx> {
460+
#[primary_span]
461+
#[label(hir_typeck_cant_dereference_label)]
462+
pub(crate) span: Span,
463+
pub(crate) ty: Ty<'tcx>,
464+
}
465+
457466
#[derive(Diagnostic)]
458467
#[diag(hir_typeck_expected_array_or_slice, code = E0529)]
459468
pub(crate) struct ExpectedArrayOrSlice<'tcx> {

compiler/rustc_hir_typeck/src/expr.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ use crate::coercion::{CoerceMany, DynamicCoerceMany};
4444
use crate::errors::{
4545
AddressOfTemporaryTaken, BaseExpressionDoubleDot, BaseExpressionDoubleDotAddExpr,
4646
BaseExpressionDoubleDotEnableDefaultFieldValues, BaseExpressionDoubleDotRemove,
47-
FieldMultiplySpecifiedInInitializer, FunctionalRecordUpdateOnNonStruct, HelpUseLatestEdition,
48-
ReturnLikeStatementKind, ReturnStmtOutsideOfFnBody, StructExprNonExhaustive,
49-
TypeMismatchFruTypo, YieldExprOutsideOfCoroutine,
47+
CantDereference, FieldMultiplySpecifiedInInitializer, FunctionalRecordUpdateOnNonStruct,
48+
HelpUseLatestEdition, ReturnLikeStatementKind, ReturnStmtOutsideOfFnBody,
49+
StructExprNonExhaustive, TypeMismatchFruTypo, YieldExprOutsideOfCoroutine,
5050
};
5151
use crate::{
5252
BreakableCtxt, CoroutineTypes, Diverges, FnCtxt, Needs, cast, fatally_break_rust,
@@ -606,13 +606,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
606606
if let Some(ty) = self.lookup_derefing(expr, oprnd, oprnd_t) {
607607
oprnd_t = ty;
608608
} else {
609-
let mut err = type_error_struct!(
610-
self.dcx(),
611-
expr.span,
612-
oprnd_t,
613-
E0614,
614-
"type `{oprnd_t}` cannot be dereferenced",
615-
);
609+
let mut err =
610+
self.dcx().create_err(CantDereference { span: expr.span, ty: oprnd_t });
616611
let sp = tcx.sess.source_map().start_point(expr.span).with_parent(None);
617612
if let Some(sp) =
618613
tcx.sess.psess.ambiguous_block_expr_parse.borrow().get(&sp)

tests/ui/deref-non-pointer.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0614]: type `{integer}` cannot be dereferenced
22
--> $DIR/deref-non-pointer.rs:2:9
33
|
44
LL | match *1 {
5-
| ^^
5+
| ^^ can't be dereferenced
66

77
error: aborting due to 1 previous error
88

tests/ui/diagnostic-width/long-E0614.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type C = (B, B, B, B);
77
type D = (C, C, C, C);
88

99
fn foo(x: D) {
10-
*x; //~ ERROR type `(
10+
*x; //~ ERROR type `(...
1111
}
1212

1313
fn main() {}

tests/ui/diagnostic-width/long-E0614.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
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
1+
error[E0614]: type `(..., ..., ..., ...)` cannot be dereferenced
22
--> $DIR/long-E0614.rs:10:5
33
|
44
LL | *x;
5-
| ^^
5+
| ^^ can't be dereferenced
6+
|
7+
= note: the full name for the type has been written to '$TEST_BUILD_DIR/$FILE.long-type-hash.txt'
8+
= note: consider using `--verbose` to print the full type name to the console
69

710
error: aborting due to 1 previous error
811

tests/ui/error-codes/E0614.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0614]: type `u32` cannot be dereferenced
22
--> $DIR/E0614.rs:3:5
33
|
44
LL | *y;
5-
| ^^
5+
| ^^ can't be dereferenced
66

77
error: aborting due to 1 previous error
88

tests/ui/issues/issue-17373.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0614]: type `!` cannot be dereferenced
22
--> $DIR/issue-17373.rs:2:5
33
|
44
LL | *return
5-
| ^^^^^^^
5+
| ^^^^^^^ can't be dereferenced
66

77
error: aborting due to 1 previous error
88

tests/ui/issues/issue-9814.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0614]: type `Foo` cannot be dereferenced
22
--> $DIR/issue-9814.rs:7:13
33
|
44
LL | let _ = *Foo::Bar(2);
5-
| ^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^ can't be dereferenced
66

77
error: aborting due to 1 previous error
88

tests/ui/parser/expr-as-stmt.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ error[E0614]: type `{integer}` cannot be dereferenced
133133
--> $DIR/expr-as-stmt.rs:25:11
134134
|
135135
LL | { 3 } * 3
136-
| ^^^
136+
| ^^^ can't be dereferenced
137137
|
138138
help: parentheses are required to parse this as an expression
139139
|

tests/ui/pattern/bindings-after-at/nested-binding-modes-ref.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error[E0614]: type `{integer}` cannot be dereferenced
22
--> $DIR/nested-binding-modes-ref.rs:4:5
33
|
44
LL | *is_val;
5-
| ^^^^^^^
5+
| ^^^^^^^ can't be dereferenced
66

77
error[E0614]: type `{integer}` cannot be dereferenced
88
--> $DIR/nested-binding-modes-ref.rs:9:5
99
|
1010
LL | *is_val;
11-
| ^^^^^^^
11+
| ^^^^^^^ can't be dereferenced
1212

1313
error: aborting due to 2 previous errors
1414

tests/ui/reachable/expr_unary.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0614]: type `!` cannot be dereferenced
22
--> $DIR/expr_unary.rs:8:16
33
|
44
LL | let x: ! = * { return; };
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^ can't be dereferenced
66

77
error: unreachable expression
88
--> $DIR/expr_unary.rs:8:16

tests/ui/type/type-check/missing_trait_impl.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ error[E0614]: type `T` cannot be dereferenced
5050
--> $DIR/missing_trait_impl.rs:15:13
5151
|
5252
LL | let y = *x;
53-
| ^^
53+
| ^^ can't be dereferenced
5454

5555
error: aborting due to 5 previous errors
5656

0 commit comments

Comments
 (0)