Skip to content

Missing coercion site in arguments to MethodCallExpr #755

Closed
@philberty

Description

@philberty

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions