about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2025-02-18 01:50:10 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-02-25 16:56:04 +0000
commit7302dc660b997c882b3a250fb6a23f60259fbdf5 (patch)
tree4e67b0e4a6a0d517d94ac025eb0c340ac6ae72b2
parentae3a825faa5dbcba6a223d0d225fd5535bf5f014 (diff)
downloadrust-7302dc660b997c882b3a250fb6a23f60259fbdf5.tar.gz
rust-7302dc660b997c882b3a250fb6a23f60259fbdf5.zip
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
```
-rw-r--r--compiler/rustc_hir_typeck/messages.ftl3
-rw-r--r--compiler/rustc_hir_typeck/src/errors.rs9
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs15
-rw-r--r--tests/ui/deref-non-pointer.stderr2
-rw-r--r--tests/ui/diagnostic-width/long-E0614.rs2
-rw-r--r--tests/ui/diagnostic-width/long-E0614.stderr7
-rw-r--r--tests/ui/error-codes/E0614.stderr2
-rw-r--r--tests/ui/issues/issue-17373.stderr2
-rw-r--r--tests/ui/issues/issue-9814.stderr2
-rw-r--r--tests/ui/parser/expr-as-stmt.stderr2
-rw-r--r--tests/ui/pattern/bindings-after-at/nested-binding-modes-ref.stderr4
-rw-r--r--tests/ui/reachable/expr_unary.stderr2
-rw-r--r--tests/ui/type/type-check/missing_trait_impl.stderr2
13 files changed, 32 insertions, 22 deletions
diff --git a/compiler/rustc_hir_typeck/messages.ftl b/compiler/rustc_hir_typeck/messages.ftl
index 9c1f1bb91be..1a75a2ec315 100644
--- a/compiler/rustc_hir_typeck/messages.ftl
+++ b/compiler/rustc_hir_typeck/messages.ftl
@@ -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}`
diff --git a/compiler/rustc_hir_typeck/src/errors.rs b/compiler/rustc_hir_typeck/src/errors.rs
index 335ac1c57a7..968bcee45cf 100644
--- a/compiler/rustc_hir_typeck/src/errors.rs
+++ b/compiler/rustc_hir_typeck/src/errors.rs
@@ -455,6 +455,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> {
     #[primary_span]
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 4815627a0ce..a857a91834e 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -45,9 +45,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,
@@ -607,13 +607,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)
diff --git a/tests/ui/deref-non-pointer.stderr b/tests/ui/deref-non-pointer.stderr
index 2e5e574fb6c..3ee354819e5 100644
--- a/tests/ui/deref-non-pointer.stderr
+++ b/tests/ui/deref-non-pointer.stderr
@@ -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
 
diff --git a/tests/ui/diagnostic-width/long-E0614.rs b/tests/ui/diagnostic-width/long-E0614.rs
index 35129c909da..0b78444a00d 100644
--- a/tests/ui/diagnostic-width/long-E0614.rs
+++ b/tests/ui/diagnostic-width/long-E0614.rs
@@ -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() {}
diff --git a/tests/ui/diagnostic-width/long-E0614.stderr b/tests/ui/diagnostic-width/long-E0614.stderr
index 6bbfbad57f2..1c16ff617fa 100644
--- a/tests/ui/diagnostic-width/long-E0614.stderr
+++ b/tests/ui/diagnostic-width/long-E0614.stderr
@@ -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
 
diff --git a/tests/ui/error-codes/E0614.stderr b/tests/ui/error-codes/E0614.stderr
index ae7c2ce9a13..0bba0753980 100644
--- a/tests/ui/error-codes/E0614.stderr
+++ b/tests/ui/error-codes/E0614.stderr
@@ -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
 
diff --git a/tests/ui/issues/issue-17373.stderr b/tests/ui/issues/issue-17373.stderr
index 9438f5c6345..0e16d08c87d 100644
--- a/tests/ui/issues/issue-17373.stderr
+++ b/tests/ui/issues/issue-17373.stderr
@@ -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
 
diff --git a/tests/ui/issues/issue-9814.stderr b/tests/ui/issues/issue-9814.stderr
index d647edaf37e..fa23fb7c176 100644
--- a/tests/ui/issues/issue-9814.stderr
+++ b/tests/ui/issues/issue-9814.stderr
@@ -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
 
diff --git a/tests/ui/parser/expr-as-stmt.stderr b/tests/ui/parser/expr-as-stmt.stderr
index 76a83aa0161..577c3455a71 100644
--- a/tests/ui/parser/expr-as-stmt.stderr
+++ b/tests/ui/parser/expr-as-stmt.stderr
@@ -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
    |
diff --git a/tests/ui/pattern/bindings-after-at/nested-binding-modes-ref.stderr b/tests/ui/pattern/bindings-after-at/nested-binding-modes-ref.stderr
index b378fe356ce..46477f16090 100644
--- a/tests/ui/pattern/bindings-after-at/nested-binding-modes-ref.stderr
+++ b/tests/ui/pattern/bindings-after-at/nested-binding-modes-ref.stderr
@@ -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
 
diff --git a/tests/ui/reachable/expr_unary.stderr b/tests/ui/reachable/expr_unary.stderr
index 0a763087c6f..7deca1b8602 100644
--- a/tests/ui/reachable/expr_unary.stderr
+++ b/tests/ui/reachable/expr_unary.stderr
@@ -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
diff --git a/tests/ui/type/type-check/missing_trait_impl.stderr b/tests/ui/type/type-check/missing_trait_impl.stderr
index 033b42e6736..28ffae2d5e5 100644
--- a/tests/ui/type/type-check/missing_trait_impl.stderr
+++ b/tests/ui/type/type-check/missing_trait_impl.stderr
@@ -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