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 /tests/ui/illegal-sized-bound | |
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 'tests/ui/illegal-sized-bound')
7 files changed, 133 insertions, 0 deletions
diff --git a/tests/ui/illegal-sized-bound/mutability-mismatch-arg.fixed b/tests/ui/illegal-sized-bound/mutability-mismatch-arg.fixed new file mode 100644 index 000000000..74f3c887f --- /dev/null +++ b/tests/ui/illegal-sized-bound/mutability-mismatch-arg.fixed @@ -0,0 +1,9 @@ +// run-rustfix +fn test(t: &mut dyn Iterator<Item=&u64>) -> u64 { + *t.min().unwrap() //~ ERROR the `min` method cannot be invoked on +} + +fn main() { + let array = [0u64]; + test(&mut array.iter()); +} diff --git a/tests/ui/illegal-sized-bound/mutability-mismatch-arg.rs b/tests/ui/illegal-sized-bound/mutability-mismatch-arg.rs new file mode 100644 index 000000000..3b02c5a5a --- /dev/null +++ b/tests/ui/illegal-sized-bound/mutability-mismatch-arg.rs @@ -0,0 +1,9 @@ +// run-rustfix +fn test(t: &dyn Iterator<Item=&u64>) -> u64 { + *t.min().unwrap() //~ ERROR the `min` method cannot be invoked on +} + +fn main() { + let array = [0u64]; + test(&mut array.iter()); +} diff --git a/tests/ui/illegal-sized-bound/mutability-mismatch-arg.stderr b/tests/ui/illegal-sized-bound/mutability-mismatch-arg.stderr new file mode 100644 index 000000000..89613bd5c --- /dev/null +++ b/tests/ui/illegal-sized-bound/mutability-mismatch-arg.stderr @@ -0,0 +1,13 @@ +error: the `min` method cannot be invoked on `&dyn Iterator<Item = &u64>` + --> $DIR/mutability-mismatch-arg.rs:3:9 + | +LL | *t.min().unwrap() + | ^^^ + | +help: you need `&mut dyn Iterator<Item = &u64>` instead of `&dyn Iterator<Item = &u64>` + | +LL | fn test(t: &mut dyn Iterator<Item=&u64>) -> u64 { + | +++ + +error: aborting due to previous error + diff --git a/tests/ui/illegal-sized-bound/mutability-mismatch.rs b/tests/ui/illegal-sized-bound/mutability-mismatch.rs new file mode 100644 index 000000000..01bb3537c --- /dev/null +++ b/tests/ui/illegal-sized-bound/mutability-mismatch.rs @@ -0,0 +1,32 @@ +struct MutType; + +pub trait MutTrait { + fn function(&mut self) + where + Self: Sized; +} + +impl MutTrait for MutType { + fn function(&mut self) {} +} + +struct Type; + +pub trait Trait { + fn function(&self) + where + Self: Sized; +} + +impl Trait for Type { + fn function(&self) {} +} + +fn main() { + (&MutType as &dyn MutTrait).function(); + //~^ ERROR the `function` method cannot be invoked on `&dyn MutTrait` + //~| HELP you need `&mut dyn MutTrait` instead of `&dyn MutTrait` + (&mut Type as &mut dyn Trait).function(); + //~^ ERROR the `function` method cannot be invoked on `&mut dyn Trait` + //~| HELP you need `&dyn Trait` instead of `&mut dyn Trait` +} diff --git a/tests/ui/illegal-sized-bound/mutability-mismatch.stderr b/tests/ui/illegal-sized-bound/mutability-mismatch.stderr new file mode 100644 index 000000000..2ca571d9b --- /dev/null +++ b/tests/ui/illegal-sized-bound/mutability-mismatch.stderr @@ -0,0 +1,18 @@ +error: the `function` method cannot be invoked on `&dyn MutTrait` + --> $DIR/mutability-mismatch.rs:26:33 + | +LL | (&MutType as &dyn MutTrait).function(); + | ^^^^^^^^ + | + = help: you need `&mut dyn MutTrait` instead of `&dyn MutTrait` + +error: the `function` method cannot be invoked on `&mut dyn Trait` + --> $DIR/mutability-mismatch.rs:29:35 + | +LL | (&mut Type as &mut dyn Trait).function(); + | ^^^^^^^^ + | + = help: you need `&dyn Trait` instead of `&mut dyn Trait` + +error: aborting due to 2 previous errors + diff --git a/tests/ui/illegal-sized-bound/regular.rs b/tests/ui/illegal-sized-bound/regular.rs new file mode 100644 index 000000000..7abd27ef9 --- /dev/null +++ b/tests/ui/illegal-sized-bound/regular.rs @@ -0,0 +1,32 @@ +struct MutType; + +pub trait MutTrait { + fn function(&mut self) + where + Self: Sized; + //~^ this has a `Sized` requirement +} + +impl MutTrait for MutType { + fn function(&mut self) {} +} + +struct Type; + +pub trait Trait { + fn function(&self) + where + Self: Sized; + //~^ this has a `Sized` requirement +} + +impl Trait for Type { + fn function(&self) {} +} + +fn main() { + (&mut MutType as &mut dyn MutTrait).function(); + //~^ ERROR the `function` method cannot be invoked on a trait object + (&Type as &dyn Trait).function(); + //~^ ERROR the `function` method cannot be invoked on a trait object +} diff --git a/tests/ui/illegal-sized-bound/regular.stderr b/tests/ui/illegal-sized-bound/regular.stderr new file mode 100644 index 000000000..7f3744145 --- /dev/null +++ b/tests/ui/illegal-sized-bound/regular.stderr @@ -0,0 +1,20 @@ +error: the `function` method cannot be invoked on a trait object + --> $DIR/regular.rs:28:41 + | +LL | Self: Sized; + | ----- this has a `Sized` requirement +... +LL | (&mut MutType as &mut dyn MutTrait).function(); + | ^^^^^^^^ + +error: the `function` method cannot be invoked on a trait object + --> $DIR/regular.rs:30:27 + | +LL | Self: Sized; + | ----- this has a `Sized` requirement +... +LL | (&Type as &dyn Trait).function(); + | ^^^^^^^^ + +error: aborting due to 2 previous errors + |