diff options
| author | r0cky <mu001999@outlook.com> | 2024-05-31 08:29:42 +0800 |
|---|---|---|
| committer | r0cky <mu001999@outlook.com> | 2024-05-31 08:29:42 +0800 |
| commit | ed5205fe66ccd49116e99e4244483caaa8cf933e (patch) | |
| tree | a38d2c871e2fe707cc2ec1c1c1deecf4c0894c6f /tests/ui/specialization | |
| parent | 21e6de7eb64c09102de3f100420a09edc1a2a8d7 (diff) | |
| download | rust-ed5205fe66ccd49116e99e4244483caaa8cf933e.tar.gz rust-ed5205fe66ccd49116e99e4244483caaa8cf933e.zip | |
Avoid unwrap diag.code directly
Diffstat (limited to 'tests/ui/specialization')
| -rw-r--r-- | tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.rs | 19 | ||||
| -rw-r--r-- | tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.stderr | 36 |
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.rs b/tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.rs new file mode 100644 index 00000000000..59a015da84e --- /dev/null +++ b/tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.rs @@ -0,0 +1,19 @@ +#![feature(specialization)] +#![allow(incomplete_features)] + +trait Trait { + type Type; +} + +impl Trait for i32 { + default type Type = i32; +} + +struct Wrapper<const C: <i32 as Trait>::Type> {} +//~^ ERROR `<i32 as Trait>::Type` is forbidden as the type of a const generic parameter + +impl<const C: usize> Wrapper<C> {} +//~^ ERROR the constant `C` is not of type `<i32 as Trait>::Type` +//~^^ ERROR mismatched types + +fn main() {} diff --git a/tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.stderr b/tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.stderr new file mode 100644 index 00000000000..b4c14c2294e --- /dev/null +++ b/tests/ui/specialization/default-proj-ty-as-type-of-const-issue-125757.stderr @@ -0,0 +1,36 @@ +error: `<i32 as Trait>::Type` is forbidden as the type of a const generic parameter + --> $DIR/default-proj-ty-as-type-of-const-issue-125757.rs:12:25 + | +LL | struct Wrapper<const C: <i32 as Trait>::Type> {} + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: the only supported types are integers, `bool` and `char` + +error: the constant `C` is not of type `<i32 as Trait>::Type` + --> $DIR/default-proj-ty-as-type-of-const-issue-125757.rs:15:22 + | +LL | impl<const C: usize> Wrapper<C> {} + | ^^^^^^^^^^ expected associated type, found `usize` + | + = help: consider constraining the associated type `<i32 as Trait>::Type` to `usize` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html +note: required by a bound in `Wrapper` + --> $DIR/default-proj-ty-as-type-of-const-issue-125757.rs:12:16 + | +LL | struct Wrapper<const C: <i32 as Trait>::Type> {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Wrapper` + +error[E0308]: mismatched types + --> $DIR/default-proj-ty-as-type-of-const-issue-125757.rs:15:30 + | +LL | impl<const C: usize> Wrapper<C> {} + | ^ expected associated type, found `usize` + | + = note: expected associated type `<i32 as Trait>::Type` + found type `usize` + = help: consider constraining the associated type `<i32 as Trait>::Type` to `usize` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. |
