diff options
| author | lcnr <rust@lcnr.de> | 2022-03-29 09:47:32 +0200 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2022-03-30 11:23:58 +0200 |
| commit | 00cf7af44aaecb5b91f58ec8f1737f6623f910d3 (patch) | |
| tree | 4a39ead9b4ea6270f70c1ae4b5cb94083f7b88db /compiler/rustc_error_codes/src | |
| parent | ee62514b16b610870e001b14f15e7e71b15e54e7 (diff) | |
| download | rust-00cf7af44aaecb5b91f58ec8f1737f6623f910d3.tar.gz rust-00cf7af44aaecb5b91f58ec8f1737f6623f910d3.zip | |
rework error messages for incorrect inherent impls
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0118.md | 29 | ||||
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0390.md | 24 |
2 files changed, 26 insertions, 27 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0118.md b/compiler/rustc_error_codes/src/error_codes/E0118.md index 345ec341c3f..8033aa8384c 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0118.md +++ b/compiler/rustc_error_codes/src/error_codes/E0118.md @@ -4,7 +4,7 @@ enum, union, or trait object. Erroneous code example: ```compile_fail,E0118 -impl (u8, u8) { // error: no nominal type found for inherent implementation +impl fn(u8) { // error: no nominal type found for inherent implementation fn get_state(&self) -> String { // ... } @@ -20,8 +20,8 @@ trait LiveLongAndProsper { fn get_state(&self) -> String; } -// and now you can implement it on (u8, u8) -impl LiveLongAndProsper for (u8, u8) { +// and now you can implement it on fn(u8) +impl LiveLongAndProsper for fn(u8) { fn get_state(&self) -> String { "He's dead, Jim!".to_owned() } @@ -33,7 +33,7 @@ For example, `NewType` is a newtype over `Foo` in `struct NewType(Foo)`. Example: ``` -struct TypeWrapper((u8, u8)); +struct TypeWrapper(fn(u8)); impl TypeWrapper { fn get_state(&self) -> String { @@ -41,24 +41,3 @@ impl TypeWrapper { } } ``` - -Instead of defining an inherent implementation on a reference, you could also -move the reference inside the implementation: - -```compile_fail,E0118 -struct Foo; - -impl &Foo { // error: no nominal type found for inherent implementation - fn bar(self, other: Self) {} -} -``` - -becomes - -``` -struct Foo; - -impl Foo { - fn bar(&self, other: &Self) {} -} -``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0390.md b/compiler/rustc_error_codes/src/error_codes/E0390.md index 7a13160d098..26a9dd331ce 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0390.md +++ b/compiler/rustc_error_codes/src/error_codes/E0390.md @@ -8,8 +8,7 @@ struct Foo { } impl *mut Foo {} -// error: only a single inherent implementation marked with -// `#[lang = "mut_ptr"]` is allowed for the `*mut T` primitive +// error: cannot define inherent `impl` for primitive types ``` This isn't allowed, but using a trait to implement a method or constant @@ -29,3 +28,24 @@ impl Bar for *mut Foo { fn bar() {} // ok! } ``` + +Instead of defining an inherent implementation on a reference, you could also +move the reference inside the implementation: + +```compile_fail,E0390 +struct Foo; + +impl &Foo { // error: no nominal type found for inherent implementation + fn bar(self, other: Self) {} +} +``` + +becomes + +``` +struct Foo; + +impl Foo { + fn bar(&self, other: &Self) {} +} +``` |
