Skip to content

Commit 7db4f70

Browse files
committed
error codes
1 parent 1c7af70 commit 7db4f70

File tree

6 files changed

+111
-7
lines changed

6 files changed

+111
-7
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,E0805
6+
#![feature(eii)]
7+
8+
#[eii(foo)]
9+
fn x();
10+
11+
#[foo]
12+
fn y(a: u64) -> u64 {
13+
//~^ ERROR E0805
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 E0805
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
@@ -547,6 +547,7 @@ E0801: 0801,
547547
E0802: 0802,
548548
E0803: 0803,
549549
E0804: 0804,
550+
E0805: 0805,
550551
);
551552
)
552553
}

compiler/rustc_hir_analysis/src/check/compare_eii.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::borrow::Cow;
22
use std::iter;
33

44
use rustc_data_structures::fx::FxIndexSet;
5-
use rustc_errors::{Applicability, E0050, E0053, struct_span_code_err};
5+
use rustc_errors::{Applicability, E0805, struct_span_code_err};
66
use rustc_hir::def_id::{DefId, LocalDefId};
77
use rustc_hir::{self as hir, FnSig, HirId, ItemKind};
88
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
@@ -182,7 +182,7 @@ fn compare_number_of_method_arguments<'tcx>(
182182
let mut err = struct_span_code_err!(
183183
tcx.dcx(),
184184
impl_span,
185-
E0050, // FIXME(jdonszelmann): new error code
185+
E0805,
186186
"`{external_impl_name}` has {} but #[{eii_name}] requires it to have {}",
187187
potentially_plural_count(external_impl_number_args, "parameter"),
188188
declaration_number_args
@@ -279,7 +279,6 @@ pub(crate) fn compare_eii_function_types<'tcx>(
279279
if let Err(terr) = result {
280280
debug!(?external_impl_sig, ?declaration_sig, ?terr, "sub_types failed");
281281

282-
// TODO: nice error
283282
let emitted = report_eii_mismatch(
284283
infcx,
285284
cause,
@@ -330,7 +329,7 @@ fn report_eii_mismatch<'tcx>(
330329
let mut diag = struct_span_code_err!(
331330
tcx.dcx(),
332331
impl_err_span,
333-
E0053, // TODO: new error code
332+
E0805,
334333
"function `{}` has a type that is incompatible with the declaration of `#[{eii_name}]`",
335334
external_impl_name
336335
);

compiler/rustc_passes/src/check_attr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
131131
// no checks needed
132132
}
133133
Attribute::Parsed(AttributeKind::EiiMangleExtern { .. }) => {
134-
// TODO: checks?
134+
// FIXME: mangle extern should be removed
135135
}
136136
Attribute::Parsed(AttributeKind::AllowInternalUnstable(syms)) => self
137137
.check_allow_internal_unstable(
@@ -304,8 +304,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
304304
| sym::lang
305305
| sym::needs_allocator
306306
| sym::default_lib_allocator
307-
| sym::custom_mir
308-
| sym::eii_macro_for, // TODO: remove
307+
| sym::custom_mir,
309308
..
310309
] => {}
311310
[name, ..] => {

tests/ui/error-codes/E0805.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 E0805
9+
a
10+
}
11+
12+
fn main() {}

tests/ui/error-codes/E0805.stderr

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: free function without a body
2+
--> $DIR/E0805.rs:4:1
3+
|
4+
LL | fn x();
5+
| ^^^^^^-
6+
| |
7+
| help: provide a definition for the function: `{ <body> }`
8+
9+
error: cannot find attribute `foo` in this scope
10+
--> $DIR/E0805.rs:6:3
11+
|
12+
LL | #[foo]
13+
| ^^^
14+
15+
error: cannot find attribute `eii` in this scope
16+
--> $DIR/E0805.rs:3:3
17+
|
18+
LL | #[eii(foo)]
19+
| ^^^
20+
21+
error[E0635]: unknown feature `eii`
22+
--> $DIR/E0805.rs:1:12
23+
|
24+
LL | #![feature(eii)]
25+
| ^^^
26+
27+
error: aborting due to 4 previous errors
28+
29+
For more information about this error, try `rustc --explain E0635`.

0 commit comments

Comments
 (0)