about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-11-23 12:18:09 +0100
committerGitHub <noreply@github.com>2016-11-23 12:18:09 +0100
commit464cce99f1fe09db35d56ca07ae4c05f591eb651 (patch)
treef4e030f5660d678509d4ba5c44d8824c8e1ca259 /src/test
parentccdc26fd42dfccc5832114baa275f0936738095a (diff)
parentec24442e60bce2605a64ac3aef5784510e4a5fd5 (diff)
downloadrust-464cce99f1fe09db35d56ca07ae4c05f591eb651.tar.gz
rust-464cce99f1fe09db35d56ca07ae4c05f591eb651.zip
Rollup merge of #37442 - estebank:cast-deref-hint, r=jonathandturner
Provide hint when cast needs a dereference

For a given code:

``` rust
vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>();
```

display:

``` nocode
error: casting `&f64` as `i16` is invalid
 --> file3.rs:2:35
  |
2 |     vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>();
  |                              -    ^^^
  |                              |
  |                              did you mean `*s`?
```

instead of:

``` nocode
error: casting `&f64` as `i16` is invalid
 --> <anon>:2:30
  |
2 |     vec![0.0].iter().map(|s| s as i16).collect();
  |                              ^^^^^^^^
  |
  = help: cast through a raw pointer first
```

Fixes #37338.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/cast-rfc0401.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/test/compile-fail/cast-rfc0401.rs b/src/test/compile-fail/cast-rfc0401.rs
index 1dbad9e30e3..b98f464c902 100644
--- a/src/test/compile-fail/cast-rfc0401.rs
+++ b/src/test/compile-fail/cast-rfc0401.rs
@@ -115,4 +115,9 @@ fn main()
     let _ = cf as *const Bar;
     //~^ ERROR casting
     //~^^ NOTE vtable kinds
+
+    vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>();
+    //~^ ERROR casting `&{float}` as `f32` is invalid
+    //~| NOTE cannot cast `&{float}` as `f32`
+    //~| NOTE did you mean `*s`?
 }