Skip to content

Add regression test for 133065 #140574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/ui/traits/trait-impl-self-mismatch.rs
Original file line number Diff line number Diff line change
@@ -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();
}
12 changes: 12 additions & 0 deletions tests/ui/traits/trait-impl-self-mismatch.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading