about summary refs log tree commit diff
path: root/compiler/rustc_error_codes/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-20 10:20:27 +0000
committerbors <bors@rust-lang.org>2022-12-20 10:20:27 +0000
commit8a746f4ac3a489efb724cde813607f3b96c2df7b (patch)
treec1a88a68650bff13ac0b61a0195f89c58e1a850a /compiler/rustc_error_codes/src
parenteb9e5e711d3eef1998ff24ac2bc57386662652e9 (diff)
parent051c52a72705035e1d18b4204de6ae4c8248aca0 (diff)
downloadrust-8a746f4ac3a489efb724cde813607f3b96c2df7b.tar.gz
rust-8a746f4ac3a489efb724cde813607f3b96c2df7b.zip
Auto merge of #105940 - matthiaskrgr:rollup-ho4po1t, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #105901 (Don't panic on stable since miri is not available there)
 - #105912 (rustdoc: force pre tags to have the default line height)
 - #105914 (rustdoc: Simplify CSS for scraped code examples code blocks)
 - #105933 (Add readable rustdoc display for tvOS and watchOS)
 - #105935 (docs/test: add UI test and long-form error docs for `E0377`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_error_codes/src')
-rw-r--r--compiler/rustc_error_codes/src/error_codes.rs3
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0377.md29
2 files changed, 30 insertions, 2 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs
index 883a4bbe8e8..4e149fc2b99 100644
--- a/compiler/rustc_error_codes/src/error_codes.rs
+++ b/compiler/rustc_error_codes/src/error_codes.rs
@@ -184,6 +184,7 @@ E0373: include_str!("./error_codes/E0373.md"),
 E0374: include_str!("./error_codes/E0374.md"),
 E0375: include_str!("./error_codes/E0375.md"),
 E0376: include_str!("./error_codes/E0376.md"),
+E0377: include_str!("./error_codes/E0377.md"),
 E0378: include_str!("./error_codes/E0378.md"),
 E0379: include_str!("./error_codes/E0379.md"),
 E0380: include_str!("./error_codes/E0380.md"),
@@ -579,8 +580,6 @@ E0791: include_str!("./error_codes/E0791.md"),
 //  E0315, // cannot invoke closure outside of its lifetime
 //  E0319, // trait impls for defaulted traits allowed just for structs/enums
 //  E0372, // coherence not object safe
-    E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
-           // between structures with the same definition
 //  E0385, // {} in an aliasable location
 //  E0402, // cannot use an outer type parameter in this context
 //  E0406, // merged into 420
diff --git a/compiler/rustc_error_codes/src/error_codes/E0377.md b/compiler/rustc_error_codes/src/error_codes/E0377.md
new file mode 100644
index 00000000000..b1d36406332
--- /dev/null
+++ b/compiler/rustc_error_codes/src/error_codes/E0377.md
@@ -0,0 +1,29 @@
+The trait `CoerceUnsized` may only be implemented for a coercion between
+structures with the same definition.
+
+Example of erroneous code:
+
+```compile_fail,E0377
+#![feature(coerce_unsized)]
+use std::ops::CoerceUnsized;
+
+pub struct Foo<T: ?Sized> {
+    field_with_unsized_type: T,
+}
+
+pub struct Bar<T: ?Sized> {
+    field_with_unsized_type: T,
+}
+
+// error: the trait `CoerceUnsized` may only be implemented for a coercion
+//        between structures with the same definition
+impl<T, U> CoerceUnsized<Bar<U>> for Foo<T> where T: CoerceUnsized<U> {}
+```
+
+When attempting to implement `CoerceUnsized`, the `impl` signature must look
+like: `impl CoerceUnsized<Type<U>> for Type<T> where T: CoerceUnsized<U>`;
+the *implementer* and *`CoerceUnsized` type parameter* must be the same
+type. In this example, `Bar` and `Foo` (even though structurally identical)
+are *not* the same type and are rejected. Learn more about the `CoerceUnsized`
+trait and DST coercion in
+[the `CoerceUnsized` docs](../std/ops/trait.CoerceUnsized.html).