diff options
| author | Jakub Beránek <berykubik@gmail.com> | 2025-01-20 14:12:41 +0100 |
|---|---|---|
| committer | Jakub Beránek <berykubik@gmail.com> | 2025-01-20 14:12:41 +0100 |
| commit | 1e0204beae7c0ebc5cddc64d1375bc7ee95f41db (patch) | |
| tree | 35fe35cfae96730b99e09b4dd97fdff8ab3e3a64 /compiler/rustc_error_codes/src | |
| parent | 808bd955862a48f604f1b227c7ca0bbb7ae2a8e8 (diff) | |
| parent | ecda83b30f0f68cf5692855dddc0bc38ee8863fc (diff) | |
| download | rust-1e0204beae7c0ebc5cddc64d1375bc7ee95f41db.tar.gz rust-1e0204beae7c0ebc5cddc64d1375bc7ee95f41db.zip | |
Merge from rustc
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0207.md | 24 | ||||
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0253.md | 12 |
2 files changed, 30 insertions, 6 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]. diff --git a/compiler/rustc_error_codes/src/error_codes/E0253.md b/compiler/rustc_error_codes/src/error_codes/E0253.md index aea51d40238..705d1bfc53e 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0253.md +++ b/compiler/rustc_error_codes/src/error_codes/E0253.md @@ -1,19 +1,19 @@ -Attempt was made to import an unimportable value. This can happen when trying -to import a method from a trait. +Attempt was made to import an unimportable type. This can happen when trying +to import a type from a trait. Erroneous code example: ```compile_fail,E0253 mod foo { pub trait MyTrait { - fn do_something(); + type SomeType; } } -use foo::MyTrait::do_something; -// error: `do_something` is not directly importable +use foo::MyTrait::SomeType; +// error: `SomeType` is not directly importable fn main() {} ``` -It's invalid to directly import methods belonging to a trait or concrete type. +It's invalid to directly import types belonging to a trait. |
