about summary refs log tree commit diff
path: root/compiler/rustc_error_codes/src
diff options
context:
space:
mode:
authorOliver Killane <oliverkillane@gmail.com>2024-05-05 13:54:33 +0100
committerOliver Killane <oliverkillane@gmail.com>2024-05-05 13:54:33 +0100
commitad7c2b06609c0da21ebdab6e45135cf07290f585 (patch)
tree646f489759d1eaf51a0f66bb7551cd99657444ea /compiler/rustc_error_codes/src
parent02f7806ecd641d67c8f046b073323c7e176ee6d2 (diff)
downloadrust-ad7c2b06609c0da21ebdab6e45135cf07290f585.tar.gz
rust-ad7c2b06609c0da21ebdab6e45135cf07290f585.zip
Updated error code explanation
Diffstat (limited to 'compiler/rustc_error_codes/src')
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0582.md34
1 files changed, 34 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0582.md b/compiler/rustc_error_codes/src/error_codes/E0582.md
index e50cc60ea33..ea32e4f9f33 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0582.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0582.md
@@ -27,6 +27,40 @@ fn bar<F, G>(t: F, u: G)
 fn main() { }
 ```
 
+This error also includes the use of associated types with lifetime parameters.
+```compile_fail,E0582
+trait Foo {
+    type Assoc<'a>;
+}
+
+struct Bar<X, F>
+where
+    X: Foo,
+    F: for<'a> Fn(X::Assoc<'a>) -> &'a i32
+{
+    x: X,
+    f: F
+}
+```
+This is as `Foo::Assoc<'a>` could be implemented by a type that does not use 
+the `'a` parameter, so there is no guarentee that `X::Assoc<'a>` actually uses 
+`'a`.
+
+To fix this we can pass a dummy parameter:
+```
+# trait Foo {
+#     type Assoc<'a>;
+# }
+struct Bar<X, F>
+where
+    X: Foo,
+    F: for<'a> Fn(X::Assoc<'a>, /* dummy */ &'a ()) -> &'a i32
+{
+    x: X,
+    f: F
+}
+```
+
 Note: The examples above used to be (erroneously) accepted by the
 compiler, but this was since corrected. See [issue #33685] for more
 details.