Skip to content

Commit

Permalink
Make E0614 a structured error
Browse files Browse the repository at this point in the history
```
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
```
  • Loading branch information
estebank committed Feb 18, 2025
1 parent 8413388 commit 2970cd3
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 22 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_hir_typeck/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ hir_typeck_cannot_cast_to_bool = cannot cast `{$expr_ty}` as `bool`
.help = compare with zero instead
.label = unsupported cast
hir_typeck_cant_dereference = type `{$ty}` cannot be dereferenced
hir_typeck_cant_dereference_label = can't be dereferenced
hir_typeck_cast_enum_drop = cannot cast enum `{$expr_ty}` into integer `{$cast_ty}` because it implements `Drop`
hir_typeck_cast_thin_pointer_to_wide_pointer = cannot cast thin pointer `{$expr_ty}` to wide pointer `{$cast_ty}`
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_hir_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ impl HelpUseLatestEdition {
}
}

#[derive(Diagnostic)]
#[diag(hir_typeck_cant_dereference, code = E0614)]
pub(crate) struct CantDereference<'tcx> {
#[primary_span]
#[label(hir_typeck_cant_dereference_label)]
pub(crate) span: Span,
pub(crate) ty: Ty<'tcx>,
}

#[derive(Diagnostic)]
#[diag(hir_typeck_expected_array_or_slice, code = E0529)]
pub(crate) struct ExpectedArrayOrSlice<'tcx> {
Expand Down
15 changes: 5 additions & 10 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ use crate::coercion::{CoerceMany, DynamicCoerceMany};
use crate::errors::{
AddressOfTemporaryTaken, BaseExpressionDoubleDot, BaseExpressionDoubleDotAddExpr,
BaseExpressionDoubleDotEnableDefaultFieldValues, BaseExpressionDoubleDotRemove,
FieldMultiplySpecifiedInInitializer, FunctionalRecordUpdateOnNonStruct, HelpUseLatestEdition,
ReturnLikeStatementKind, ReturnStmtOutsideOfFnBody, StructExprNonExhaustive,
TypeMismatchFruTypo, YieldExprOutsideOfCoroutine,
CantDereference, FieldMultiplySpecifiedInInitializer, FunctionalRecordUpdateOnNonStruct,
HelpUseLatestEdition, ReturnLikeStatementKind, ReturnStmtOutsideOfFnBody,
StructExprNonExhaustive, TypeMismatchFruTypo, YieldExprOutsideOfCoroutine,
};
use crate::{
BreakableCtxt, CoroutineTypes, Diverges, FnCtxt, Needs, cast, fatally_break_rust,
Expand Down Expand Up @@ -606,13 +606,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(ty) = self.lookup_derefing(expr, oprnd, oprnd_t) {
oprnd_t = ty;
} else {
let mut err = type_error_struct!(
self.dcx(),
expr.span,
oprnd_t,
E0614,
"type `{oprnd_t}` cannot be dereferenced",
);
let mut err =
self.dcx().create_err(CantDereference { span: expr.span, ty: oprnd_t });
let sp = tcx.sess.source_map().start_point(expr.span).with_parent(None);
if let Some(sp) =
tcx.sess.psess.ambiguous_block_expr_parse.borrow().get(&sp)
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/deref-non-pointer.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0614]: type `{integer}` cannot be dereferenced
--> $DIR/deref-non-pointer.rs:2:9
|
LL | match *1 {
| ^^
| ^^ can't be dereferenced

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/diagnostic-width/long-E0614.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type C = (B, B, B, B);
type D = (C, C, C, C);

fn foo(x: D) {
*x; //~ ERROR type `(
*x; //~ ERROR type `(...
}

fn main() {}
7 changes: 5 additions & 2 deletions tests/ui/diagnostic-width/long-E0614.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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
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

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0614.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0614]: type `u32` cannot be dereferenced
--> $DIR/E0614.rs:3:5
|
LL | *y;
| ^^
| ^^ can't be dereferenced

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-17373.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0614]: type `!` cannot be dereferenced
--> $DIR/issue-17373.rs:2:5
|
LL | *return
| ^^^^^^^
| ^^^^^^^ can't be dereferenced

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-9814.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0614]: type `Foo` cannot be dereferenced
--> $DIR/issue-9814.rs:7:13
|
LL | let _ = *Foo::Bar(2);
| ^^^^^^^^^^^^
| ^^^^^^^^^^^^ can't be dereferenced

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/parser/expr-as-stmt.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ error[E0614]: type `{integer}` cannot be dereferenced
--> $DIR/expr-as-stmt.rs:25:11
|
LL | { 3 } * 3
| ^^^
| ^^^ can't be dereferenced
|
help: parentheses are required to parse this as an expression
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ error[E0614]: type `{integer}` cannot be dereferenced
--> $DIR/nested-binding-modes-ref.rs:4:5
|
LL | *is_val;
| ^^^^^^^
| ^^^^^^^ can't be dereferenced

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

error: aborting due to 2 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/reachable/expr_unary.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0614]: type `!` cannot be dereferenced
--> $DIR/expr_unary.rs:8:16
|
LL | let x: ! = * { return; };
| ^^^^^^^^^^^^^
| ^^^^^^^^^^^^^ can't be dereferenced

error: unreachable expression
--> $DIR/expr_unary.rs:8:16
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/type/type-check/missing_trait_impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ error[E0614]: type `T` cannot be dereferenced
--> $DIR/missing_trait_impl.rs:15:13
|
LL | let y = *x;
| ^^
| ^^ can't be dereferenced

error: aborting due to 5 previous errors

Expand Down

0 comments on commit 2970cd3

Please sign in to comment.