about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-01-12 10:55:13 +0100
committerGitHub <noreply@github.com>2019-01-12 10:55:13 +0100
commite0cea0db5da9d3671e9c68ebb264d90bd69b2c28 (patch)
tree2eb040cba84ca957438ae395b9df6b3cecbc64bd
parent1fff64a6947a4b78b2bf3dd48789149b2400df70 (diff)
parent29a8386bb3b7ff8434f4b1b5be0fd51a48d93bb3 (diff)
downloadrust-e0cea0db5da9d3671e9c68ebb264d90bd69b2c28.tar.gz
rust-e0cea0db5da9d3671e9c68ebb264d90bd69b2c28.zip
Rollup merge of #57493 - euclio:deref-suggest, r=oli-obk
use structured suggestion when casting a reference
-rw-r--r--src/librustc_typeck/check/cast.rs10
-rw-r--r--src/test/ui/error-codes/E0606.stderr11
-rw-r--r--src/test/ui/error-festival.stderr11
-rw-r--r--src/test/ui/mismatched_types/cast-rfc0401.stderr11
4 files changed, 20 insertions, 23 deletions
diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs
index 38f9adee0a4..fbba89164e6 100644
--- a/src/librustc_typeck/check/cast.rs
+++ b/src/librustc_typeck/check/cast.rs
@@ -213,8 +213,14 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
                                        fcx.ty_to_string(self.expr_ty),
                                        cast_ty));
                 if let Ok(snippet) = fcx.sess().source_map().span_to_snippet(self.expr.span) {
-                    err.span_help(self.expr.span,
-                        &format!("did you mean `*{}`?", snippet));
+                    err.span_suggestion_with_applicability(
+                        self.expr.span,
+                        "dereference the expression",
+                        format!("*{}", snippet),
+                        Applicability::MaybeIncorrect,
+                    );
+                } else {
+                    err.span_help(self.expr.span, "dereference the expression with `*`");
                 }
                 err.emit();
             }
diff --git a/src/test/ui/error-codes/E0606.stderr b/src/test/ui/error-codes/E0606.stderr
index bc872b3b79c..89ec4896a2b 100644
--- a/src/test/ui/error-codes/E0606.stderr
+++ b/src/test/ui/error-codes/E0606.stderr
@@ -2,13 +2,10 @@ error[E0606]: casting `&u8` as `u8` is invalid
   --> $DIR/E0606.rs:2:5
    |
 LL |     &0u8 as u8; //~ ERROR E0606
-   |     ^^^^^^^^^^ cannot cast `&u8` as `u8`
-   |
-help: did you mean `*&0u8`?
-  --> $DIR/E0606.rs:2:5
-   |
-LL |     &0u8 as u8; //~ ERROR E0606
-   |     ^^^^
+   |     ----^^^^^^
+   |     |
+   |     cannot cast `&u8` as `u8`
+   |     help: dereference the expression: `*&0u8`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/error-festival.stderr b/src/test/ui/error-festival.stderr
index 2a482722169..ef7b49399bf 100644
--- a/src/test/ui/error-festival.stderr
+++ b/src/test/ui/error-festival.stderr
@@ -60,13 +60,10 @@ error[E0606]: casting `&u8` as `u32` is invalid
   --> $DIR/error-festival.rs:37:18
    |
 LL |     let y: u32 = x as u32;
-   |                  ^^^^^^^^ cannot cast `&u8` as `u32`
-   |
-help: did you mean `*x`?
-  --> $DIR/error-festival.rs:37:18
-   |
-LL |     let y: u32 = x as u32;
-   |                  ^
+   |                  -^^^^^^^
+   |                  |
+   |                  cannot cast `&u8` as `u32`
+   |                  help: dereference the expression: `*x`
 
 error[E0607]: cannot cast thin pointer `*const u8` to fat pointer `*const [u8]`
   --> $DIR/error-festival.rs:41:5
diff --git a/src/test/ui/mismatched_types/cast-rfc0401.stderr b/src/test/ui/mismatched_types/cast-rfc0401.stderr
index 158d1146169..fbe5e6d4099 100644
--- a/src/test/ui/mismatched_types/cast-rfc0401.stderr
+++ b/src/test/ui/mismatched_types/cast-rfc0401.stderr
@@ -240,13 +240,10 @@ error[E0606]: casting `&{float}` as `f32` is invalid
   --> $DIR/cast-rfc0401.rs:71:30
    |
 LL |     vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>(); //~ ERROR is invalid
-   |                              ^^^^^^^^ cannot cast `&{float}` as `f32`
-   |
-help: did you mean `*s`?
-  --> $DIR/cast-rfc0401.rs:71:30
-   |
-LL |     vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>(); //~ ERROR is invalid
-   |                              ^
+   |                              -^^^^^^^
+   |                              |
+   |                              cannot cast `&{float}` as `f32`
+   |                              help: dereference the expression: `*s`
 
 error: aborting due to 34 previous errors