-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gcc/rust/ChangeLog: * backend/rust-compile.cc: Modify compute_address_for_trait_item to support supertraits * typecheck/rust-tyty.cc: Remove auto gcc/testsuite/ChangeLog: * rust/compile/trait13.rs: Add test for supertraits of supertraits * rust/compile/trait14.rs: Diamond problem with supertraits test * rust/execute/torture/trait14.rs: Add test for dynamic dispatch with supertraits * rust/execute/torture/trait15.rs: Add test for dynamic dispatch with generics * rust/execute/torture/trait16.rs: Add test for dynamic dispatch with lifetime params 1 * rust/execute/torture/trait17.rs: Add test for dynamic dispatch with lifetime params 2 * rust/execute/torture/trait18.rs: Add test for default implementations with dynamic dispatch and supertraits Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
- Loading branch information
1 parent
65b00cc
commit c5f9d6d
Showing
9 changed files
with
420 additions
and
73 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,47 @@ | ||
// Testing multiple supertraits and calling supertrait methods | ||
|
||
struct Foo { | ||
my_int: u32, | ||
} | ||
|
||
trait GrandParent { | ||
fn grandparent(&self) -> u32; | ||
} | ||
|
||
trait Parent : GrandParent { | ||
fn parent(&self) -> bool; | ||
} | ||
|
||
trait Child : Parent { | ||
fn child(&self); | ||
} | ||
|
||
impl GrandParent for Foo { | ||
fn grandparent(&self) -> u32 { | ||
self.my_int | ||
} | ||
} | ||
|
||
impl Parent for Foo { | ||
fn parent(&self) -> bool { | ||
// Call supertrait method | ||
return self.grandparent() != 0; | ||
} | ||
} | ||
|
||
impl Child for Foo { | ||
fn child(&self) { | ||
let _ = self; | ||
} | ||
} | ||
|
||
pub fn main() { | ||
let a = Foo{my_int: 0xfeedf00d}; | ||
let b: &dyn Child = &a; | ||
|
||
b.parent(); | ||
b.child(); | ||
|
||
// Here to silence bogus compiler warning | ||
let _ = a.my_int; | ||
} |
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,51 @@ | ||
// Testing diamond problem with supertraits | ||
|
||
|
||
struct Foo { | ||
my_int: u32, | ||
} | ||
|
||
trait GrandParent { | ||
fn grandparent(&self); | ||
} | ||
|
||
trait Parent1 : GrandParent { | ||
fn parent1(&self); | ||
} | ||
|
||
trait Parent2 : GrandParent { | ||
fn parent2(&self); | ||
} | ||
|
||
trait Child : Parent1+Parent2 { | ||
fn child(&self); | ||
} | ||
|
||
impl GrandParent for Foo { | ||
fn grandparent(&self) { let _ = self; } | ||
} | ||
|
||
impl Parent1 for Foo { | ||
fn parent1(&self) { let _ = self; } | ||
} | ||
|
||
impl Parent2 for Foo { | ||
fn parent2(&self) { let _ = self; } | ||
} | ||
|
||
impl Child for Foo { | ||
fn child(&self) { | ||
let _ = self; | ||
} | ||
} | ||
|
||
pub fn main() { | ||
let a = Foo{my_int: 0xf00dfeed}; | ||
let b: &dyn Child = &a; | ||
|
||
b.parent1(); | ||
b.child(); | ||
|
||
// Suppress bogus compile warning | ||
let _ = a.my_int; | ||
} |
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,47 @@ | ||
/* { dg-output "parent123\r*\nchild\r*\n" } */ | ||
|
||
extern "C" { | ||
fn printf(s: *const i8, ...); | ||
} | ||
|
||
#[lang = "sized"] | ||
pub trait Sized {} | ||
|
||
struct Foo(i32); | ||
trait Parent { | ||
fn parent(&self); | ||
} | ||
|
||
trait Child : Parent { | ||
fn child(&self); | ||
} | ||
|
||
impl Parent for Foo { | ||
fn parent(&self) { | ||
unsafe { | ||
let parent = "parent%i\n\0"; | ||
let msg = parent as *const str; | ||
printf(msg as *const i8,self.0); | ||
} | ||
} | ||
} | ||
|
||
impl Child for Foo { | ||
fn child(&self) { | ||
let _ = self; | ||
unsafe { | ||
let child = "child\n\0"; | ||
let msg = child as *const str; | ||
printf(msg as *const i8); | ||
} | ||
} | ||
} | ||
|
||
pub fn main() -> i32 { | ||
let a = Foo(123); | ||
let b: &dyn Child = &a; | ||
|
||
b.parent(); | ||
b.child(); | ||
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,56 @@ | ||
/* { dg-output "parent123\r*\nchild\r*\n" } */ | ||
// Testing generics passing with supertraits | ||
|
||
extern "C" { | ||
fn printf(s: *const i8, ...); | ||
} | ||
|
||
#[lang = "sized"] | ||
pub trait Sized {} | ||
|
||
struct Foo { | ||
my_int: u32, | ||
} | ||
|
||
trait Parent<T> { | ||
fn parent(&self) -> T; | ||
} | ||
|
||
trait Child<T> : Parent<T> { | ||
fn child(&self); | ||
} | ||
|
||
impl Parent<u32> for Foo { | ||
fn parent(&self) -> u32 { | ||
unsafe { | ||
let parent = "parent%i\n\0"; | ||
let msg = parent as *const str; | ||
printf(msg as *const i8,self.my_int); | ||
return self.my_int; | ||
} | ||
} | ||
} | ||
|
||
impl Child<u32> for Foo { | ||
fn child(&self) { | ||
let _ = self; | ||
unsafe { | ||
let child = "child\n\0"; | ||
let msg = child as *const str; | ||
printf(msg as *const i8); | ||
} | ||
} | ||
} | ||
|
||
pub fn main() -> i32 { | ||
let a = Foo{my_int: 123}; | ||
let b: &dyn Child<u32> = &a; | ||
|
||
b.parent(); | ||
b.child(); | ||
|
||
//Silence bogus warning | ||
let _ = a.my_int; | ||
|
||
0 | ||
} |
Oops, something went wrong.