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

ErrorCode[E0277] Type Does Not Implement Expected Trait #2315

Merged
merged 1 commit into from
Jun 25, 2023

Conversation

MahadMuhammad
Copy link
Contributor

Type Does Not Implement Expected Trait - the type [{integer}] cannot be indexed by u32

  • Tested code from rustc E0277:
// here we declare the Foo trait with a bar method
trait Foo {
    fn bar(&self);
}

// we now declare a function which takes an object implementing the Foo trait
fn some_func<T: Foo>(foo: T) {
    foo.bar();
}

fn main() {
    // we now call the method with the i32 type, which doesn't implement
    // the Foo trait
    some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied
}

  • Output:
mahad@linux:~/Desktop/mahad/mahad-testsuite$ ../gccrs-build/gcc/crab1 E0277.rs -frust-incomplete-and-experimental-compiler-do-not-use
E0277.rs:14:15: error: bounds not satisfied for i32 ‘Foo’ is not satisfied [E0277]
    7 | fn some_func<T: Foo>(foo: T) {
      |                 ~~~
......
   14 |     some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied
      |               ^~~~

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.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): passed "E0277"
* typecheck/rust-tyty.cc (BaseType::bounds_compatible): passed "E0277"

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>

Type Does Not Implement Expected Trait - the type [{integer}] cannot be indexed by u32

gcc/rust/ChangeLog:
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): passed "E0277"
	* typecheck/rust-tyty.cc (BaseType::bounds_compatible): passed "E0277"

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

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

Looks good to me! Leaving it to @philberty to say if there are other places where that should be emitted :) Thank you @MahadMuhammad !

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 Jun 25, 2023
Merged via the queue into Rust-GCC:master with commit 04eb580 Jun 25, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants