diff options
| author | xtex <xtexchooser@duck.com> | 2025-03-30 10:00:45 +0800 |
|---|---|---|
| committer | xtex <xtexchooser@duck.com> | 2025-04-03 17:35:51 +0800 |
| commit | fdefffecb2a1c2b89dfc2c5ad041c02144adda81 (patch) | |
| tree | 0760f1131f3f0930047e6a3cc8a011a818a3cdb6 /tests/ui/dyn-compatibility | |
| parent | 365806089020f60a50391133a1430c40bc86963c (diff) | |
| download | rust-fdefffecb2a1c2b89dfc2c5ad041c02144adda81.tar.gz rust-fdefffecb2a1c2b89dfc2c5ad041c02144adda81.zip | |
compiler: report error when trait object type param reference self
Fixes #139082. Emits an error when `Self` is found in the projection bounds of a trait object. In type aliases, `Self` has no meaning, so `type A = &'static dyn B` where `trait B = Fn() -> Self` will expands to `type A = &'static Fn() -> Self` which is illegal, causing the region solver to bail out when hitting the uninferred Self. Bug: #139082 Signed-off-by: xtex <xtexchooser@duck.com>
Diffstat (limited to 'tests/ui/dyn-compatibility')
| -rw-r--r-- | tests/ui/dyn-compatibility/trait-alias-self-projection.rs | 12 | ||||
| -rw-r--r-- | tests/ui/dyn-compatibility/trait-alias-self-projection.stderr | 9 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/ui/dyn-compatibility/trait-alias-self-projection.rs b/tests/ui/dyn-compatibility/trait-alias-self-projection.rs new file mode 100644 index 00000000000..0badb738809 --- /dev/null +++ b/tests/ui/dyn-compatibility/trait-alias-self-projection.rs @@ -0,0 +1,12 @@ +#![feature(trait_alias)] +trait B = Fn() -> Self; +type D = &'static dyn B; +//~^ ERROR E0411 + +fn a() -> D { + unreachable!(); +} + +fn main() { + _ = a(); +} diff --git a/tests/ui/dyn-compatibility/trait-alias-self-projection.stderr b/tests/ui/dyn-compatibility/trait-alias-self-projection.stderr new file mode 100644 index 00000000000..dccee02e9cd --- /dev/null +++ b/tests/ui/dyn-compatibility/trait-alias-self-projection.stderr @@ -0,0 +1,9 @@ +error[E0411]: `Self` is not allowed in type aliases + --> $DIR/trait-alias-self-projection.rs:3:19 + | +LL | type D = &'static dyn B; + | ^^^^^ `Self` is only available in impls, traits, and concrete type definitions + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0411`. |
