Skip to content

Commit 9106f82

Browse files
committed
EII new error code
1 parent e68cd20 commit 9106f82

File tree

5 files changed

+94
-3
lines changed

5 files changed

+94
-3
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
An externally implementable item is not compatible with its declaration.
2+
3+
Erroneous code example:
4+
5+
```rust,edition2021,compile_fail,E0806
6+
#![feature(eii)]
7+
8+
#[eii(foo)]
9+
fn x();
10+
11+
#[foo]
12+
fn y(a: u64) -> u64 {
13+
//~^ ERROR E0806
14+
a
15+
}
16+
17+
18+
fn main() {}
19+
```
20+
21+
To fix this, `y`'s signature must match that of `x`:
22+
23+
```rust,edition2021
24+
#![feature(eii)]
25+
26+
#[eii(foo)]
27+
fn x();
28+
29+
#[foo]
30+
fn y() {}
31+
32+
33+
fn main() {}
34+
```
35+
36+
One common way this can be triggered is by using the wrong
37+
signature for `#[panic_handler]`.
38+
The signature is provided by `core`.
39+
40+
```rust,edition2021,ignore
41+
#![no_std]
42+
43+
#[panic_handler]
44+
fn on_panic() -> ! {
45+
//~^ ERROR E0806
46+
47+
loop {}
48+
}
49+
50+
fn main() {}
51+
```
52+
53+
Should be:
54+
55+
```rust,edition2021,ignore
56+
#![no_std]
57+
58+
#[panic_handler]
59+
fn on_panic(info: &core::panic::PanicInfo<'_>) -> ! {
60+
loop {}
61+
}
62+
63+
fn main() {}
64+
```

compiler/rustc_error_codes/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ E0802: 0802,
548548
E0803: 0803,
549549
E0804: 0804,
550550
E0805: 0805,
551+
E0806: 0806,
551552
);
552553
)
553554
}

compiler/rustc_hir_analysis/src/check/compare_eii.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::borrow::Cow;
77
use std::iter;
88

99
use rustc_data_structures::fx::FxIndexSet;
10-
use rustc_errors::{Applicability, E0805, struct_span_code_err};
10+
use rustc_errors::{Applicability, E0806, struct_span_code_err};
1111
use rustc_hir::def_id::{DefId, LocalDefId};
1212
use rustc_hir::{self as hir, FnSig, HirId, ItemKind};
1313
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
@@ -258,7 +258,7 @@ fn compare_number_of_method_arguments<'tcx>(
258258
let mut err = struct_span_code_err!(
259259
tcx.dcx(),
260260
impl_span,
261-
E0805,
261+
E0806,
262262
"`{external_impl_name}` has {} but #[{eii_name}] requires it to have {}",
263263
potentially_plural_count(external_impl_number_args, "parameter"),
264264
declaration_number_args
@@ -300,7 +300,7 @@ fn report_eii_mismatch<'tcx>(
300300
let mut diag = struct_span_code_err!(
301301
tcx.dcx(),
302302
impl_err_span,
303-
E0805,
303+
E0806,
304304
"function `{}` has a type that is incompatible with the declaration of `#[{eii_name}]`",
305305
external_impl_name
306306
);

tests/ui/error-codes/E0806.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(eii)]
2+
3+
#[eii(foo)]
4+
fn x();
5+
6+
#[foo]
7+
fn y(a: u64) -> u64 {
8+
//~^ ERROR E0806
9+
a
10+
}
11+
12+
fn main() {}

tests/ui/error-codes/E0806.stderr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0806]: `y` has 1 parameter but #[foo] requires it to have 0
2+
--> $DIR/E0806.rs:7:9
3+
|
4+
LL | fn x();
5+
| ------- requires 0 parameters
6+
LL |
7+
LL | #[foo]
8+
| ------ required because of this attribute
9+
LL | fn y(a: u64) -> u64 {
10+
| ^^^ expected 0 parameters, found 1
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0806`.

0 commit comments

Comments
 (0)