From d5cfcc71e8a4eec626d67d3c9474349cc3de2190 Mon Sep 17 00:00:00 2001 From: Jan Cibulka Date: Mon, 21 Oct 2024 10:46:36 +0300 Subject: [PATCH] test: Add test for trait in FQS cast, issue #98565 --- tests/ui/traits/fully-qualified-syntax-cast.rs | 15 +++++++++++++++ .../ui/traits/fully-qualified-syntax-cast.stderr | 9 +++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/ui/traits/fully-qualified-syntax-cast.rs create mode 100644 tests/ui/traits/fully-qualified-syntax-cast.stderr diff --git a/tests/ui/traits/fully-qualified-syntax-cast.rs b/tests/ui/traits/fully-qualified-syntax-cast.rs new file mode 100644 index 00000000000..740220a074b --- /dev/null +++ b/tests/ui/traits/fully-qualified-syntax-cast.rs @@ -0,0 +1,15 @@ +// Regression test for #98565: Provide diagnostics when the user uses +// the built-in type `str` in a cast where a trait is expected. + +trait Foo { + fn foo(&self); +} + +impl Foo for String { + fn foo(&self) { + ::trim(self); + //~^ ERROR expected trait, found builtin type `str` + } +} + +fn main() {} diff --git a/tests/ui/traits/fully-qualified-syntax-cast.stderr b/tests/ui/traits/fully-qualified-syntax-cast.stderr new file mode 100644 index 00000000000..1848c9184c6 --- /dev/null +++ b/tests/ui/traits/fully-qualified-syntax-cast.stderr @@ -0,0 +1,9 @@ +error[E0404]: expected trait, found builtin type `str` + --> $DIR/fully-qualified-syntax-cast.rs:10:18 + | +LL | ::trim(self); + | ^^^ not a trait + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0404`.