about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-05-02 19:38:01 +0200
committerGitHub <noreply@github.com>2025-05-02 19:38:01 +0200
commit6f7f3cec4fac339f1ec5cf913e6ffa2e98109467 (patch)
tree964ce99dc9b4cfc45e7ece193a565d264132d7f2
parentbcf2490c64dc62fd07f28b0b00665eb29040738f (diff)
parenta9cd0a9f03c9737274170db0a1a421183b63b66f (diff)
downloadrust-6f7f3cec4fac339f1ec5cf913e6ffa2e98109467.tar.gz
rust-6f7f3cec4fac339f1ec5cf913e6ffa2e98109467.zip
Rollup merge of #140574 - reddevilmidzy:add-test, r=compiler-errors
Add regression test for 133065

closes: #133065
-rw-r--r--tests/ui/traits/trait-impl-self-mismatch.rs19
-rw-r--r--tests/ui/traits/trait-impl-self-mismatch.stderr12
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/traits/trait-impl-self-mismatch.rs b/tests/ui/traits/trait-impl-self-mismatch.rs
new file mode 100644
index 00000000000..54226cf2c9a
--- /dev/null
+++ b/tests/ui/traits/trait-impl-self-mismatch.rs
@@ -0,0 +1,19 @@
+//@compile-flags: -Zvalidate-mir -Zinline-mir -Zinline-mir-threshold=300
+
+//! Ensure that a trait method implemented with the wrong signature
+//! correctly triggers a compile error and not an ICE.
+//! Regression test for <https://github.com/rust-lang/rust/issues/133065>.
+
+trait Bar {
+    fn bar(&self) {}
+}
+
+impl<T> Bar for T {
+    fn bar() { //~ ERROR method `bar` has a `&self` declaration in the trait, but not in the impl
+        let _ = "Hello".bytes().nth(3);
+    }
+}
+
+fn main() {
+    ().bar();
+}
diff --git a/tests/ui/traits/trait-impl-self-mismatch.stderr b/tests/ui/traits/trait-impl-self-mismatch.stderr
new file mode 100644
index 00000000000..4ee06787c7d
--- /dev/null
+++ b/tests/ui/traits/trait-impl-self-mismatch.stderr
@@ -0,0 +1,12 @@
+error[E0186]: method `bar` has a `&self` declaration in the trait, but not in the impl
+  --> $DIR/trait-impl-self-mismatch.rs:12:5
+   |
+LL |     fn bar(&self) {}
+   |     ------------- `&self` used in trait
+...
+LL |     fn bar() {
+   |     ^^^^^^^^ expected `&self` in impl
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0186`.