This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better way to replace self in traits (#141)
* Make it taking * Make type drivable * Add test for references in traits * Add test for reference to none * Add test for reference to literal * Better way to replace self
- Loading branch information
1 parent
498bb01
commit 7309048
Showing
9 changed files
with
74 additions
and
13 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
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 |
---|---|---|
|
@@ -37,3 +37,6 @@ pub use tmp::*; | |
|
||
mod unnamed; | ||
pub use unnamed::*; | ||
|
||
mod replace_self; | ||
pub use replace_self::*; |
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,21 @@ | ||
use derive_visitor::VisitorMut; | ||
|
||
use crate::hir::Type; | ||
|
||
#[derive(VisitorMut)] | ||
#[visitor(Type(enter))] | ||
pub struct ReplaceSelf { | ||
ty: Type, | ||
} | ||
|
||
impl ReplaceSelf { | ||
pub fn with(ty: Type) -> Self { | ||
Self { ty } | ||
} | ||
|
||
fn enter_type(&mut self, ty: &mut Type) { | ||
if let Type::SelfType(_) = ty { | ||
*ty = self.ty.clone(); | ||
} | ||
} | ||
} |
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,3 @@ | ||
fn foo <x: &Integer> => println x | ||
|
||
foo 42 |
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,4 @@ | ||
fn foo <:&None> => println "foo" | ||
|
||
let x = none | ||
foo x |
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,9 @@ | ||
trait Foo: | ||
fn foo <:&Self> | ||
|
||
fn foo <:&Integer> => println "foo integer" | ||
|
||
fn bar <x: &Foo> => foo x | ||
|
||
let x = 0 | ||
bar x |