File tree Expand file tree Collapse file tree 5 files changed +98
-3
lines changed
rustc_hir_analysis/src/check Expand file tree Collapse file tree 5 files changed +98
-3
lines changed Original file line number Diff line number Diff line change 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+ The error here is caused by the fact that ` y ` implements the
22+ externally implementable item ` foo ` .
23+ It can only do so if the signature of the implementation ` y ` matches
24+ that of the declaration of ` foo ` .
25+ So, to fix this, ` y ` 's signature must be changed to match that of ` x ` :
26+
27+ ``` rust,edition2021
28+ #![feature(eii)]
29+
30+ #[eii(foo)]
31+ fn x();
32+
33+ #[foo]
34+ fn y() {}
35+
36+
37+ fn main() {}
38+ ```
39+
40+ One common way this can be triggered is by using the wrong
41+ signature for ` #[panic_handler] ` .
42+ The signature is provided by ` core ` .
43+
44+ ``` rust,edition2021,ignore
45+ #![no_std]
46+
47+ #[panic_handler]
48+ fn on_panic() -> ! {
49+ //~^ ERROR E0806
50+
51+ loop {}
52+ }
53+
54+ fn main() {}
55+ ```
56+
57+ Should be:
58+
59+ ``` rust,edition2021,ignore
60+ #![no_std]
61+
62+ #[panic_handler]
63+ fn on_panic(info: &core::panic::PanicInfo<'_>) -> ! {
64+ loop {}
65+ }
66+
67+ fn main() {}
68+ ```
Original file line number Diff line number Diff line change @@ -543,6 +543,7 @@ macro_rules! error_codes {
5435430803 ,
5445440804 ,
5455450805 ,
546+ 0806 ,
546547 ) ;
547548 )
548549}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ use std::borrow::Cow;
77use std:: iter;
88
99use 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} ;
1111use rustc_hir:: def_id:: { DefId , LocalDefId } ;
1212use rustc_hir:: { self as hir, FnSig , HirId , ItemKind } ;
1313use rustc_infer:: infer:: { self , InferCtxt , TyCtxtInferExt } ;
@@ -291,7 +291,7 @@ fn report_number_of_arguments_mismatch<'tcx>(
291291 let mut err = struct_span_code_err ! (
292292 tcx. dcx( ) ,
293293 impl_span,
294- E0805 ,
294+ E0806 ,
295295 "`{external_impl_name}` has {} but #[{eii_name}] requires it to have {}" ,
296296 potentially_plural_count( external_impl_number_args, "parameter" ) ,
297297 declaration_number_args
@@ -333,7 +333,7 @@ fn report_eii_mismatch<'tcx>(
333333 let mut diag = struct_span_code_err ! (
334334 tcx. dcx( ) ,
335335 impl_err_span,
336- E0805 ,
336+ E0806 ,
337337 "function `{}` has a type that is incompatible with the declaration of `#[{eii_name}]`" ,
338338 external_impl_name
339339 ) ;
Original file line number Diff line number Diff line change 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 ( ) { }
Original file line number Diff line number Diff line change 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`.
You can’t perform that action at this time.
0 commit comments