diff options
| author | omskscream <golovkov93@gmail.com> | 2025-09-14 01:18:18 +0300 |
|---|---|---|
| committer | omskscream <golovkov93@gmail.com> | 2025-09-14 12:16:34 +0300 |
| commit | 22aecd3001038d0ac00ecd06985e2b0abc57e6dc (patch) | |
| tree | be14b34dcc2b2f6705dccb7e5b7388dffda15f2b /tests/ui/traits | |
| parent | 8ee3a08b871f8b24075f67eda06330f7005cd435 (diff) | |
| download | rust-22aecd3001038d0ac00ecd06985e2b0abc57e6dc.tar.gz rust-22aecd3001038d0ac00ecd06985e2b0abc57e6dc.zip | |
clean up issue-21950 (dyn trait cast without assoc type at the cast)
Diffstat (limited to 'tests/ui/traits')
| -rw-r--r-- | tests/ui/traits/cast-as-dyn-trait-wo-assoc-type-issue-21950.rs | 19 | ||||
| -rw-r--r-- | tests/ui/traits/cast-as-dyn-trait-wo-assoc-type-issue-21950.stderr | 12 |
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/traits/cast-as-dyn-trait-wo-assoc-type-issue-21950.rs b/tests/ui/traits/cast-as-dyn-trait-wo-assoc-type-issue-21950.rs new file mode 100644 index 00000000000..3c381505450 --- /dev/null +++ b/tests/ui/traits/cast-as-dyn-trait-wo-assoc-type-issue-21950.rs @@ -0,0 +1,19 @@ +//! Tests that compiler yields error E0191 when value with existing trait implementation +//! is cast as same `dyn` trait without specifying associated type at the cast. +//! +//! # Context +//! Original issue: https://github.com/rust-lang/rust/issues/21950 + +trait Add<Rhs=Self> { + type Output; +} + +impl Add for i32 { + type Output = i32; +} + +fn main() { + let x = &10 as &dyn Add<i32, Output = i32>; //OK + let x = &10 as &dyn Add; + //~^ ERROR E0191 +} diff --git a/tests/ui/traits/cast-as-dyn-trait-wo-assoc-type-issue-21950.stderr b/tests/ui/traits/cast-as-dyn-trait-wo-assoc-type-issue-21950.stderr new file mode 100644 index 00000000000..5f4974e6f23 --- /dev/null +++ b/tests/ui/traits/cast-as-dyn-trait-wo-assoc-type-issue-21950.stderr @@ -0,0 +1,12 @@ +error[E0191]: the value of the associated type `Output` in `Add` must be specified + --> $DIR/cast-as-dyn-trait-wo-assoc-type-issue-21950.rs:17:25 + | +LL | type Output; + | ----------- `Output` defined here +... +LL | let x = &10 as &dyn Add; + | ^^^ help: specify the associated type: `Add<Output = Type>` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0191`. |
