diff options
| author | Laurențiu Nicola <lnicola@dend.ro> | 2024-06-20 08:03:36 +0300 |
|---|---|---|
| committer | Laurențiu Nicola <lnicola@dend.ro> | 2024-06-20 08:03:36 +0300 |
| commit | 9d2bb7f40ff91c36b590e743a6e9a92153159d1c (patch) | |
| tree | 0343d8f8c519d3e76f27f77fbae414eb88ef2738 /compiler/rustc_error_codes | |
| parent | 35d0bcd89fa7454093abcf2c7a8624782c269375 (diff) | |
| parent | 3d5d7a24f76006b391d8a53d903ae64c1b4a52d2 (diff) | |
| download | rust-9d2bb7f40ff91c36b590e743a6e9a92153159d1c.tar.gz rust-9d2bb7f40ff91c36b590e743a6e9a92153159d1c.zip | |
Merge from rust-lang/rust
Diffstat (limited to 'compiler/rustc_error_codes')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0229.md | 13 | ||||
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0582.md | 34 | ||||
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0792.md | 4 | ||||
| -rw-r--r-- | compiler/rustc_error_codes/src/lib.rs | 6 |
4 files changed, 48 insertions, 9 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0229.md b/compiler/rustc_error_codes/src/error_codes/E0229.md index a8fab057d43..f4a983cb9ef 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0229.md +++ b/compiler/rustc_error_codes/src/error_codes/E0229.md @@ -1,5 +1,4 @@ -An associated type binding was done outside of the type parameter declaration -and `where` clause. +An associated item constraint was written in an unexpected context. Erroneous code example: @@ -16,12 +15,12 @@ impl Foo for isize { fn boo(&self) -> usize { 42 } } -fn baz<I>(x: &<I as Foo<A=Bar>>::A) {} -// error: associated type bindings are not allowed here +fn baz<I>(x: &<I as Foo<A = Bar>>::A) {} +// error: associated item constraint are not allowed here ``` -To solve this error, please move the type bindings in the type parameter -declaration: +To solve this error, please move the associated item constraints to the type +parameter declaration: ``` # struct Bar; @@ -29,7 +28,7 @@ declaration: fn baz<I: Foo<A=Bar>>(x: &<I as Foo>::A) {} // ok! ``` -Or in the `where` clause: +Or into the where-clause: ``` # struct Bar; diff --git a/compiler/rustc_error_codes/src/error_codes/E0582.md b/compiler/rustc_error_codes/src/error_codes/E0582.md index e50cc60ea33..b2cdb509c95 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 +} +``` +The latter scenario encounters this error because `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. diff --git a/compiler/rustc_error_codes/src/error_codes/E0792.md b/compiler/rustc_error_codes/src/error_codes/E0792.md index bad2b5abfe4..5e3dcc4aa72 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0792.md +++ b/compiler/rustc_error_codes/src/error_codes/E0792.md @@ -39,6 +39,8 @@ type Foo<T> = impl std::fmt::Debug; fn foo<U>() -> Foo<U> { 5u32 } + +fn main() {} ``` This means that no matter the generic parameter to `foo`, @@ -57,4 +59,6 @@ type Foo<T: Debug> = impl Debug; fn foo<U: Debug>() -> Foo<U> { Vec::<U>::new() } + +fn main() {} ``` diff --git a/compiler/rustc_error_codes/src/lib.rs b/compiler/rustc_error_codes/src/lib.rs index f4a33a05c1b..d13d5e1bca2 100644 --- a/compiler/rustc_error_codes/src/lib.rs +++ b/compiler/rustc_error_codes/src/lib.rs @@ -1,10 +1,12 @@ //! This library is used to gather all error codes into one place, to make //! their maintenance easier. +// tidy-alphabetical-start #![allow(internal_features)] -#![feature(rustdoc_internals)] -#![doc(rust_logo)] #![deny(rustdoc::invalid_codeblock_attributes)] +#![doc(rust_logo)] +#![feature(rustdoc_internals)] +// tidy-alphabetical-end // This higher-order macro defines the error codes that are in use. It is used // in the `rustc_errors` crate. Removed error codes are listed in the comment |
