Skip to content

Commit 43869e9

Browse files
committed
Auto merge of #29260 - GuillaumeGomez:E0211_improvement, r=Manishearth
r? @Manishearth cc #29248
2 parents 8d41c6f + 77053e2 commit 43869e9

File tree

1 file changed

+60
-4
lines changed

1 file changed

+60
-4
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,24 +2348,80 @@ For information on the design of the orphan rules, see [RFC 1023].
23482348
"##,
23492349

23502350
E0211: r##"
2351-
You used an intrinsic function which doesn't correspond to its
2352-
definition. Erroneous code example:
2351+
You used a function or type which doesn't fit the requirements for where it was
2352+
used. Erroneous code examples:
23532353
23542354
```
23552355
#![feature(intrinsics)]
23562356
23572357
extern "rust-intrinsic" {
23582358
fn size_of<T>(); // error: intrinsic has wrong type
23592359
}
2360+
2361+
// or:
2362+
2363+
fn main() -> i32 { 0 }
2364+
// error: main function expects type: `fn() {main}`: expected (), found i32
2365+
2366+
// or:
2367+
2368+
let x = 1u8;
2369+
match x {
2370+
0u8...3i8 => (),
2371+
// error: mismatched types in range: expected u8, found i8
2372+
_ => ()
2373+
}
2374+
2375+
// or:
2376+
2377+
use std::rc::Rc;
2378+
struct Foo;
2379+
2380+
impl Foo {
2381+
fn x(self: Rc<Foo>) {}
2382+
// error: mismatched self type: expected `Foo`: expected struct
2383+
// `Foo`, found struct `alloc::rc::Rc`
2384+
}
23602385
```
23612386
2362-
Please check the function definition. Example:
2387+
For the first code example, please check the function definition. Example:
23632388
23642389
```
23652390
#![feature(intrinsics)]
23662391
23672392
extern "rust-intrinsic" {
2368-
fn size_of<T>() -> usize;
2393+
fn size_of<T>() -> usize; // ok!
2394+
}
2395+
```
2396+
2397+
The second case example is a bit particular : the main function must always
2398+
have this definition:
2399+
2400+
```
2401+
fn main();
2402+
```
2403+
2404+
They never take parameters and never return types.
2405+
2406+
For the third example, when you match, all patterns must have the same type
2407+
as the type you're matching on. Example:
2408+
2409+
```
2410+
let x = 1u8;
2411+
match x {
2412+
0u8...3u8 => (), // ok!
2413+
_ => ()
2414+
}
2415+
```
2416+
2417+
And finally, for the last example, only `Box<Self>`, `&Self`, `Self`,
2418+
or `&mut Self` work as explicit self parameters. Example:
2419+
2420+
```
2421+
struct Foo;
2422+
2423+
impl Foo {
2424+
fn x(self: Box<Foo>) {} // ok!
23692425
}
23702426
```
23712427
"##,

0 commit comments

Comments
 (0)