about summary refs log tree commit diff
path: root/tests/ui/traits
diff options
context:
space:
mode:
authorJan Cibulka <jc@pntr.eu>2024-10-21 10:46:36 +0300
committerJan Cibulka <jc@pntr.eu>2024-10-21 11:45:19 +0300
commitd5cfcc71e8a4eec626d67d3c9474349cc3de2190 (patch)
tree7381a9c19c9f619fb8cad75f5cda66c778604080 /tests/ui/traits
parentde977a5acf210f7d71ff83f4b8bc42c274ce4ed9 (diff)
downloadrust-d5cfcc71e8a4eec626d67d3c9474349cc3de2190.tar.gz
rust-d5cfcc71e8a4eec626d67d3c9474349cc3de2190.zip
test: Add test for trait in FQS cast, issue #98565
Diffstat (limited to 'tests/ui/traits')
-rw-r--r--tests/ui/traits/fully-qualified-syntax-cast.rs15
-rw-r--r--tests/ui/traits/fully-qualified-syntax-cast.stderr9
2 files changed, 24 insertions, 0 deletions
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) {
+        <Self as str>::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 |         <Self as str>::trim(self);
+   |                  ^^^ not a trait
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0404`.