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

Missing coercion site in arguments to MethodCallExpr #755

Closed
philberty opened this issue Oct 21, 2021 · 0 comments · Fixed by #762
Closed

Missing coercion site in arguments to MethodCallExpr #755

philberty opened this issue Oct 21, 2021 · 0 comments · Fixed by #762
Assignees
Labels

Comments

@philberty
Copy link
Member

I tried this code: https://godbolt.org/z/h7zon91Kf

extern "C" {
    fn printf(s: *const i8, ...);
}

struct Foo(i32);
trait Bar {
    fn baz(&self);
    // { dg-warning "unused name" "" { target *-*-* } .-1 }
}

impl Bar for Foo {
    fn baz(&self) {
        // { dg-warning "unused name" "" { target *-*-* } .-1 }
        unsafe {
            let a = "%i\n\0";
            let b = a as *const str;
            let c = b as *const i8;

            printf(c, self.0);
        }
    }
}

struct S;
impl S {
    fn dynamic_dispatch(self, t: &dyn Bar) {
        t.baz();
    }
}

pub fn main() -> i32 {
    let a;
    a = &Foo(123);

    let b;
    b = S;

    b.dynamic_dispatch(a);

    0
}

I expected to see this happen: the argument of 'a' to the dynamic_dispatch method to be coerced into a dynamic object with a vtable

Instead, this happened: the argument of 'a' was passed without the implicit conversion required

Meta

  • What version of Rust GCC were you using, git sha if possible. 649e3e0
@philberty philberty added the bug label Oct 21, 2021
@philberty philberty self-assigned this Oct 21, 2021
@philberty philberty mentioned this issue Oct 21, 2021
51 tasks
bors bot added a commit that referenced this issue Oct 22, 2021
762: Add missing coercion site code to MethodCallExpr's r=philberty a=philberty

Arguments to methods are coercion sites and may have implicit conversions
to be performed this adds this missing code for this case.

Fixes #755


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
@bors bors bot closed this as completed in e0b43cc Oct 22, 2021
@bors bors bot closed this as completed in #762 Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant