diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-10-21 18:11:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-21 18:11:21 +0200 |
| commit | a9da2be010af81990dfcd167e5671d407c843481 (patch) | |
| tree | aabc9c49334065185d36632530350e14f73266bb | |
| parent | 1cc8c8de951887e1e70071ca0abe0249d50b7440 (diff) | |
| parent | d5cfcc71e8a4eec626d67d3c9474349cc3de2190 (diff) | |
| download | rust-a9da2be010af81990dfcd167e5671d407c843481.tar.gz rust-a9da2be010af81990dfcd167e5671d407c843481.zip | |
Rollup merge of #131991 - jannden:issue-98565-test, r=jieyouxu
test: Add test for trait in FQS cast, issue #98565 Closes #98565 by adding a test to check for diagnostics when the built-in type `str` is used in a cast where a trait is expected.
| -rw-r--r-- | tests/ui/traits/fully-qualified-syntax-cast.rs | 15 | ||||
| -rw-r--r-- | tests/ui/traits/fully-qualified-syntax-cast.stderr | 9 |
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`. |
