diff options
| author | Ralf Jung <post@ralfj.de> | 2025-01-19 17:32:20 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-19 17:32:20 +0000 |
| commit | 49375c48f7748debfdbfab9cccc450235e72bb74 (patch) | |
| tree | 9cf2eda04ec28b2451ab0770098627aa6bcc5134 /compiler/rustc_error_codes/src | |
| parent | 5460fbe610cacae6de98a3dfc3ffe9573f0c9906 (diff) | |
| parent | 544695506c1d85628d39856ae912cbfeb112021d (diff) | |
| download | rust-49375c48f7748debfdbfab9cccc450235e72bb74.tar.gz rust-49375c48f7748debfdbfab9cccc450235e72bb74.zip | |
Merge pull request #4141 from rust-lang/rustup-2025-01-19
Automatic Rustup
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -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]. |
