diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /compiler/rustc_error_codes/src/error_codes/E0792.md | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_error_codes/src/error_codes/E0792.md')
-rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0792.md | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0792.md b/compiler/rustc_error_codes/src/error_codes/E0792.md new file mode 100644 index 000000000..bad2b5abf --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0792.md @@ -0,0 +1,60 @@ +A type alias impl trait can only have its hidden type assigned +when used fully generically (and within their defining scope). +This means + +```compile_fail,E0792 +#![feature(type_alias_impl_trait)] + +type Foo<T> = impl std::fmt::Debug; + +fn foo() -> Foo<u32> { + 5u32 +} +``` + +is not accepted. If it were accepted, one could create unsound situations like + +```compile_fail,E0792 +#![feature(type_alias_impl_trait)] + +type Foo<T> = impl Default; + +fn foo() -> Foo<u32> { + 5u32 +} + +fn main() { + let x = Foo::<&'static mut String>::default(); +} +``` + + +Instead you need to make the function generic: + +``` +#![feature(type_alias_impl_trait)] + +type Foo<T> = impl std::fmt::Debug; + +fn foo<U>() -> Foo<U> { + 5u32 +} +``` + +This means that no matter the generic parameter to `foo`, +the hidden type will always be `u32`. +If you want to link the generic parameter to the hidden type, +you can do that, too: + + +``` +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +type Foo<T: Debug> = impl Debug; + +fn foo<U: Debug>() -> Foo<U> { + Vec::<U>::new() +} +``` |