Skip to content
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

[E0053] method 'x' has an incompatible type for trait 'y' #2380

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

MahadMuhammad
Copy link
Contributor

The parameters of any trait method must match between a trait implementation and the trait definition

Code tested from E0053

#![allow(unused)]
fn main() {
trait Foo {
    fn foo(x: u16);
    fn bar(&self);
}

struct Bar;

impl Foo for Bar {
    // error, expected u16, found i16
    fn foo(x: i16) { }

    // error, types differ in mutability
    fn bar(&mut self) { }
}
}

Output:

➜  gccrs-build gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use ../mahad-testsuite/E0053.rs
../mahad-testsuite/E0053.rs:12:5: error: expected ‘fn<Bar> (x u16,) -> ()’ got ‘fn (x i16,) -> ()4 |     fn foo(x: u16);
      |     ~~
......
   12 |     fn foo(x: i16) { }
      |     ^~
../mahad-testsuite/E0053.rs:12:5: error: method ‘foo’ has an incompatible type for trait ‘Foo[E0053]
    4 |     fn foo(x: u16);
      |     ~~
......
   12 |     fn foo(x: i16) { }
      |     ^~

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 TOTAL                              :   0.00          0.00          0.00          146k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.

Running testcases:

/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/issue-2037.rs:8:5: error: expected 'fn<Baz> (ref mut self &mut Self=Baz{Baz {}},other &mut dyn [HIR Trait: Foo->[C: 0 Nid: 19 Hid: 30 Lid: 6] [(FN bar ), ]<Self>],) -> ()' got 'fn (ref mut self &mut Baz{Baz {}},other & dyn [HIR Trait: Foo->[C: 0 Nid: 19 Hid: 30 Lid: 6] [(FN bar ), ]<Self>],) -> ()'
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/issue-2037.rs:8:5: error: method 'bar' has an incompatible type for trait 'Foo' [E0053]
compiler exited with status 1

/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/traits2.rs:2:5: error: expected 'i32' got '()'
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/traits2.rs:9:5: error: expected 'fn<Baz> () -> i32' got 'fn () -> ()'
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/traits2.rs:9:5: error: method 'Bar' has an incompatible type for trait 'Foo' [E0053]
compiler exited with status 1

/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/traits3.rs:12:5: error: expected 'fn<Bar<T>> (a <placeholder:<Projection=<T>::i32>>,) -> <placeholder:<Projection=<T>::i32>>' got 'fn<T> (a f32,) -> f32'
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/traits3.rs:12:5: error: method 'baz' has an incompatible type for trait 'Foo' [E0053]
compiler exited with status 1

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItemWithTrait::visit): called error function

The parameters of any trait method must match between
a trait implementation and the trait definition

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItemWithTrait::visit):
	called error function

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
@philberty philberty added the diagnostic diagnostic static analysis label Jul 6, 2023
@philberty philberty added this to the GCC 14 Stage 3 milestone Jul 6, 2023
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@philberty philberty added this pull request to the merge queue Jul 6, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jul 6, 2023
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@philberty philberty added this pull request to the merge queue Jul 6, 2023
Merged via the queue into Rust-GCC:master with commit b9566fd Jul 6, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants