-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure we emit the code for coercion sites on CallExpr and MethodCall…
…Expr When we coerce the types of arguments to the parameters of functions for example we must store the actual type of the argument at that HIR ID not the coerced ones. This gives the backend a chance to then figure out when to actually implement any coercion site code. such as computing the dynamic objects. Fixes: #700
- Loading branch information
Showing
4 changed files
with
199 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* { dg-output "123\n123\n" } */ | ||
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); | ||
} | ||
} | ||
} | ||
|
||
fn static_dispatch<T: Bar>(t: &T) { | ||
t.baz(); | ||
} | ||
|
||
fn dynamic_dispatch(t: &dyn Bar) { | ||
t.baz(); | ||
} | ||
|
||
fn main() -> i32 { | ||
let a; | ||
a = Foo(123); | ||
static_dispatch(&a); | ||
|
||
let b: &dyn Bar; | ||
b = &a; | ||
dynamic_dispatch(b); | ||
|
||
0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* { dg-output "123\n123\n" } */ | ||
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); | ||
} | ||
} | ||
} | ||
|
||
fn static_dispatch<T: Bar>(t: &T) { | ||
t.baz(); | ||
} | ||
|
||
fn dynamic_dispatch(t: &dyn Bar) { | ||
t.baz(); | ||
} | ||
|
||
fn main() -> i32 { | ||
let a; | ||
a = &Foo(123); | ||
|
||
static_dispatch(a); | ||
dynamic_dispatch(a); | ||
|
||
0 | ||
} |