Skip to content

Improve E0211 error diagnostic #29260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 60 additions & 4 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2348,24 +2348,80 @@ For information on the design of the orphan rules, see [RFC 1023].
"##,

E0211: r##"
You used an intrinsic function which doesn't correspond to its
definition. Erroneous code example:
You used a function or type which doesn't fit the requirements for where it was
used. Erroneous code examples:

```
#![feature(intrinsics)]

extern "rust-intrinsic" {
fn size_of<T>(); // error: intrinsic has wrong type
}

// or:

fn main() -> i32 { 0 }
// error: main function expects type: `fn() {main}`: expected (), found i32

// or:

let x = 1u8;
match x {
0u8...3i8 => (),
// error: mismatched types in range: expected u8, found i8
_ => ()
}

// or:

use std::rc::Rc;
struct Foo;

impl Foo {
fn x(self: Rc<Foo>) {}
// error: mismatched self type: expected `Foo`: expected struct
// `Foo`, found struct `alloc::rc::Rc`
}
```

Please check the function definition. Example:
For the first code example, please check the function definition. Example:

```
#![feature(intrinsics)]

extern "rust-intrinsic" {
fn size_of<T>() -> usize;
fn size_of<T>() -> usize; // ok!
}
```

The second case example is a bit particular : the main function must always
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

odd spacing here with the colon

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups, french habit...

have this definition:

```
fn main();
```

They never take parameters and never return types.

For the third example, when you match, all patterns must have the same type
as the type you're matching on. Example:

```
let x = 1u8;
match x {
0u8...3u8 => (), // ok!
_ => ()
}
```

And finally, for the last example, only `Box<Self>`, `&Self`, `Self`,
or `&mut Self` work as explicit self parameters. Example:

```
struct Foo;

impl Foo {
fn x(self: Box<Foo>) {} // ok!
}
```
"##,
Expand Down