@@ -2348,24 +2348,80 @@ For information on the design of the orphan rules, see [RFC 1023].
2348
2348
"## ,
2349
2349
2350
2350
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 :
2353
2353
2354
2354
```
2355
2355
#![feature(intrinsics)]
2356
2356
2357
2357
extern "rust-intrinsic" {
2358
2358
fn size_of<T>(); // error: intrinsic has wrong type
2359
2359
}
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
+ }
2360
2385
```
2361
2386
2362
- Please check the function definition. Example:
2387
+ For the first code example, please check the function definition. Example:
2363
2388
2364
2389
```
2365
2390
#![feature(intrinsics)]
2366
2391
2367
2392
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!
2369
2425
}
2370
2426
```
2371
2427
"## ,
0 commit comments