diff options
| author | Oneirical <manchot@videotron.ca> | 2025-08-20 14:02:50 -0400 |
|---|---|---|
| committer | Oneirical <manchot@videotron.ca> | 2025-09-12 14:45:12 -0400 |
| commit | 957fa10d50787a4c6c6d8a35be5af6bd43ba1770 (patch) | |
| tree | 88895b6987884c8fa52dfabfacbb6caaf0b6b325 /tests/ui/dyn-compatibility | |
| parent | e8a792daf500b5ff8097896ddb6cc037abe92487 (diff) | |
| download | rust-957fa10d50787a4c6c6d8a35be5af6bd43ba1770.tar.gz rust-957fa10d50787a4c6c6d8a35be5af6bd43ba1770.zip | |
Add test batch 3
Diffstat (limited to 'tests/ui/dyn-compatibility')
| -rw-r--r-- | tests/ui/dyn-compatibility/spurious-dyn-compat-errors-58734.rs | 25 | ||||
| -rw-r--r-- | tests/ui/dyn-compatibility/spurious-dyn-compat-errors-58734.stderr | 42 |
2 files changed, 67 insertions, 0 deletions
diff --git a/tests/ui/dyn-compatibility/spurious-dyn-compat-errors-58734.rs b/tests/ui/dyn-compatibility/spurious-dyn-compat-errors-58734.rs new file mode 100644 index 00000000000..3e9ebb497a2 --- /dev/null +++ b/tests/ui/dyn-compatibility/spurious-dyn-compat-errors-58734.rs @@ -0,0 +1,25 @@ +// https://github.com/rust-lang/rust/issues/58734 +trait Trait { + fn exists(self) -> (); + + fn dyn_incompatible() -> Self; +} + +impl Trait for () { + fn exists(self) -> () { + } + + fn dyn_incompatible() -> Self { + () + } +} + +fn main() { + // dyn-compatible or not, this call is OK + Trait::exists(()); + // no dyn-compatibility error + Trait::nonexistent(()); + //~^ WARN trait objects without an explicit `dyn` are deprecated + //~| WARN this is accepted in the current edition + //~| ERROR the trait `Trait` is not dyn compatible +} diff --git a/tests/ui/dyn-compatibility/spurious-dyn-compat-errors-58734.stderr b/tests/ui/dyn-compatibility/spurious-dyn-compat-errors-58734.stderr new file mode 100644 index 00000000000..140461283f3 --- /dev/null +++ b/tests/ui/dyn-compatibility/spurious-dyn-compat-errors-58734.stderr @@ -0,0 +1,42 @@ +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/spurious-dyn-compat-errors-58734.rs:21:5 + | +LL | Trait::nonexistent(()); + | ^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/warnings-promoted-to-error.html> + = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default +help: if this is a dyn-compatible trait, use `dyn` + | +LL | <dyn Trait>::nonexistent(()); + | ++++ + + +error[E0038]: the trait `Trait` is not dyn compatible + --> $DIR/spurious-dyn-compat-errors-58734.rs:21:5 + | +LL | Trait::nonexistent(()); + | ^^^^^ `Trait` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility> + --> $DIR/spurious-dyn-compat-errors-58734.rs:5:8 + | +LL | trait Trait { + | ----- this trait is not dyn compatible... +... +LL | fn dyn_incompatible() -> Self; + | ^^^^^^^^^^^^^^^^ ...because associated function `dyn_incompatible` has no `self` parameter + = help: only type `()` implements `Trait`; consider using it directly instead. +help: consider turning `dyn_incompatible` into a method by giving it a `&self` argument + | +LL | fn dyn_incompatible(&self) -> Self; + | +++++ +help: alternatively, consider constraining `dyn_incompatible` so it does not apply to trait objects + | +LL | fn dyn_incompatible() -> Self where Self: Sized; + | +++++++++++++++++ + +error: aborting due to 1 previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0038`. |
