diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2025-01-16 23:53:49 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-01-16 23:53:49 +0000 |
| commit | 9bdc65866ced6531e988674324ffc72af817c880 (patch) | |
| tree | a04fafa44ace4358150941c28a71ac70424be4f6 /compiler/rustc_error_codes | |
| parent | d8a64098c9d0fb25699f657c6efff0bb418f7e18 (diff) | |
| download | rust-9bdc65866ced6531e988674324ffc72af817c880.tar.gz rust-9bdc65866ced6531e988674324ffc72af817c880.zip | |
Expand docs for `E0207` with additional example
Diffstat (limited to 'compiler/rustc_error_codes')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0207.md | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0207.md b/compiler/rustc_error_codes/src/error_codes/E0207.md index 95e7c9fc76c..5b35748f472 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0207.md +++ b/compiler/rustc_error_codes/src/error_codes/E0207.md @@ -195,6 +195,30 @@ impl<'a> Contains for Foo { Please note that unconstrained lifetime parameters are not supported if they are being used by an associated type. +In cases where the associated type's lifetime is meant to be tied to the the +self type, and none of the methods on the trait need ownership or different +mutability, then an option is to implement the trait on a borrowed type: + +```rust +struct Foo(i32); + +trait Contents { + type Item; + + fn get(&self) -> Self::Item; +} + +// Note the lifetime `'a` is used both for the self type... +impl<'a> Contents for &'a Foo { + // ...and the associated type. + type Item = &'a i32; + + fn get(&self) -> Self::Item { + &self.0 + } +} +``` + ### Additional information For more information, please see [RFC 447]. |
