diff options
| author | bors <bors@rust-lang.org> | 2025-01-17 09:03:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-01-17 09:03:22 +0000 |
| commit | 73c0ae6aec8f3d07467dfb9339761fa2eec92a44 (patch) | |
| tree | 63609aaa5bbc9a876366bfc42e077315183d7370 /compiler/rustc_error_codes/src | |
| parent | 0c2c096e1ac471b0c34629f9820a7cb1e6d4695d (diff) | |
| parent | 1360e76329a1e3b4590f9f1998779d663e0da003 (diff) | |
| download | rust-73c0ae6aec8f3d07467dfb9339761fa2eec92a44.tar.gz rust-73c0ae6aec8f3d07467dfb9339761fa2eec92a44.zip | |
Auto merge of #135615 - matthiaskrgr:rollup-ra7vftt, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #131806 (Treat other items as functions for the purpose of type-based search) - #134980 (Location-sensitive polonius prototype: endgame) - #135558 (Detect if-else chains with a missing final else in type errors) - #135594 (fix error for when results in a rustdoc-js test are in the wrong order) - #135601 (Fix suggestion to convert dereference of raw pointer to ref) - #135604 (Expand docs for `E0207` with additional example) r? `@ghost` `@rustbot` modify labels: rollup
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]. |
