about summary refs log tree commit diff
path: root/src/rustllvm/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-11-02 08:30:03 +0000
committerbors <bors@rust-lang.org>2017-11-02 08:30:03 +0000
commita7d98c78377e5083d5add5d3ae8d26ffa938c005 (patch)
treeb476c024bb7cf49cf4cbd706564d58b4ddb63a1d /src/rustllvm/RustWrapper.cpp
parent2379faa933923a97158a4939b9fc82dcbd45430f (diff)
parent87c951da0f36405ee9d7226f63a7208c58a16d07 (diff)
downloadrust-a7d98c78377e5083d5add5d3ae8d26ffa938c005.tar.gz
rust-a7d98c78377e5083d5add5d3ae8d26ffa938c005.zip
Auto merge of #45630 - joshleeb:iss35241, r=estebank
Improve display of error E0308

Ref. Forgetting to call a variant constructor causes a confusing error message #35241.

This PR modifies [`note_type_err`](https://github.com/rust-lang/rust/blob/b7041bfab3a83702a8026fb7a18d8ea7d54cc648/src/librustc/infer/error_reporting/mod.rs#L669-L674) to display a `help` message when a `TyFnPtr` or `TyFnDef` are found and the return type, of the function or function pointer, is the same as the type that is expected.

The output of compiling

```rust
struct Foo(u32);

fn test() -> Foo { Foo }

fn main() {}
```

is now

```bash
$ rustc src/test/ui/issue-35241.rs
error[E0308]: mismatched types
  --> src/test/ui/issue-35241.rs:13:20
   |
13 | fn test() -> Foo { Foo }
   |              ---   ^^^ expected struct `Foo`, found fn item
   |              |
   |              expected `Foo` because of return type
   |
   = help: did you mean `Foo { /* fields */ }`?
   = note: expected type `Foo`
              found type `fn(u32) -> Foo {Foo::{{constructor}}}`

error: aborting due to previous error
```
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions