Skip to content

Commit 0dee00f

Browse files
Rollup merge of #37244 - senior:add-error-desc-182-230-399, r=GuillaumeGomez
Add error explaination for E0182, E0230 and E0399 This PR adds some error descriptions requested in issue #32777. r? @GuillaumeGomez Specifically this adds descriptions for E0182 - unexpected binding of associated item in expression path E0230 - missing type parameter from on_unimplemented description E0399 - overriding a trait type without re-implementing default methods
2 parents 8133a55 + 9365586 commit 0dee00f

File tree

1 file changed

+101
-4
lines changed

1 file changed

+101
-4
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,45 @@ More details can be found in [RFC 438].
19151915
[RFC 438]: https://github.com/rust-lang/rfcs/pull/438
19161916
"##,
19171917

1918+
E0182: r##"
1919+
You bound an associated type in an expression path which is not
1920+
allowed.
1921+
1922+
Erroneous code example:
1923+
1924+
```compile_fail,E0182
1925+
trait Foo {
1926+
type A;
1927+
fn bar() -> isize;
1928+
}
1929+
1930+
impl Foo for isize {
1931+
type A = usize;
1932+
fn bar() -> isize { 42 }
1933+
}
1934+
1935+
// error: unexpected binding of associated item in expression path
1936+
let x: isize = Foo::<A=usize>::bar();
1937+
```
1938+
1939+
To give a concrete type when using the Universal Function Call Syntax,
1940+
use "Type as Trait". Example:
1941+
1942+
```
1943+
trait Foo {
1944+
type A;
1945+
fn bar() -> isize;
1946+
}
1947+
1948+
impl Foo for isize {
1949+
type A = usize;
1950+
fn bar() -> isize { 42 }
1951+
}
1952+
1953+
let x: isize = <isize as Foo>::bar(); // ok!
1954+
```
1955+
"##,
1956+
19181957
E0184: r##"
19191958
Explicitly implementing both Drop and Copy for a type is currently disallowed.
19201959
This feature can make some sense in theory, but the current implementation is
@@ -2752,6 +2791,30 @@ fn main() {
27522791
```
27532792
"##,
27542793

2794+
E0230: r##"
2795+
The trait has more type parameters specified than appear in its definition.
2796+
2797+
Erroneous example code:
2798+
2799+
```compile_fail,E0230
2800+
#![feature(on_unimplemented)]
2801+
#[rustc_on_unimplemented = "Trait error on `{Self}` with `<{A},{B},{C}>`"]
2802+
// error: there is no type parameter C on trait TraitWithThreeParams
2803+
trait TraitWithThreeParams<A,B>
2804+
{}
2805+
```
2806+
2807+
Include the correct number of type parameters and the compilation should
2808+
proceed:
2809+
2810+
```
2811+
#![feature(on_unimplemented)]
2812+
#[rustc_on_unimplemented = "Trait error on `{Self}` with `<{A},{B},{C}>`"]
2813+
trait TraitWithThreeParams<A,B,C> // ok!
2814+
{}
2815+
```
2816+
"##,
2817+
27552818
E0232: r##"
27562819
The attribute must have a value. Erroneous code example:
27572820
@@ -3587,6 +3650,44 @@ fn together_we_will_rule_the_galaxy(son: &A<i32>) {} // Ok!
35873650
```
35883651
"##,
35893652

3653+
E0399: r##"
3654+
You implemented a trait, overriding one or more of its associated types but did
3655+
not reimplement its default methods.
3656+
3657+
Example of erroneous code:
3658+
3659+
```compile_fail,E0399
3660+
#![feature(associated_type_defaults)]
3661+
3662+
pub trait Foo {
3663+
type Assoc = u8;
3664+
fn bar(&self) {}
3665+
}
3666+
3667+
impl Foo for i32 {
3668+
// error - the following trait items need to be reimplemented as
3669+
// `Assoc` was overridden: `bar`
3670+
type Assoc = i32;
3671+
}
3672+
```
3673+
3674+
To fix this, add an implementation for each default method from the trait:
3675+
3676+
```
3677+
#![feature(associated_type_defaults)]
3678+
3679+
pub trait Foo {
3680+
type Assoc = u8;
3681+
fn bar(&self) {}
3682+
}
3683+
3684+
impl Foo for i32 {
3685+
type Assoc = i32;
3686+
fn bar(&self) {} // ok!
3687+
}
3688+
```
3689+
"##,
3690+
35903691
E0439: r##"
35913692
The length of the platform-intrinsic function `simd_shuffle`
35923693
wasn't specified. Erroneous code example:
@@ -4074,7 +4175,6 @@ register_diagnostics! {
40744175
// E0168,
40754176
// E0173, // manual implementations of unboxed closure traits are experimental
40764177
// E0174,
4077-
E0182,
40784178
E0183,
40794179
// E0187, // can't infer the kind of the closure
40804180
// E0188, // can not cast an immutable reference to a mutable pointer
@@ -4098,7 +4198,6 @@ register_diagnostics! {
40984198
E0226, // only a single explicit lifetime bound is permitted
40994199
E0227, // ambiguous lifetime bound, explicit lifetime bound required
41004200
E0228, // explicit lifetime bound required
4101-
E0230, // there is no type parameter on trait
41024201
E0231, // only named substitution parameters are allowed
41034202
// E0233,
41044203
// E0234,
@@ -4120,8 +4219,6 @@ register_diagnostics! {
41204219
// E0372, // coherence not object safe
41214220
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
41224221
// between structures with the same definition
4123-
E0399, // trait items need to be implemented because the associated
4124-
// type `{}` was overridden
41254222
E0436, // functional record update requires a struct
41264223
E0521, // redundant default implementations of trait
41274224
E0533, // `{}` does not name a unit variant, unit struct or a constant

0 commit comments

Comments
 (0)