-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #593 from ShoyuVanilla/issue-577
fix: Replace `SelfTy` with actual type in tracked methods
- Loading branch information
Showing
3 changed files
with
184 additions
and
4 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,44 @@ | ||
//! Test that a `tracked` fn with `Self` in its signature or body on a `salsa::input` | ||
//! compiles and executes successfully. | ||
#![allow(warnings)] | ||
|
||
trait TrackedTrait { | ||
type Type; | ||
|
||
fn tracked_trait_fn(self, db: &dyn salsa::Database, ty: Self::Type) -> Self::Type; | ||
|
||
fn untracked_trait_fn(); | ||
} | ||
|
||
#[salsa::input] | ||
struct MyInput { | ||
field: u32, | ||
} | ||
|
||
#[salsa::tracked] | ||
impl MyInput { | ||
#[salsa::tracked] | ||
fn tracked_fn(self, db: &dyn salsa::Database, other: Self) -> u32 { | ||
self.field(db) + other.field(db) | ||
} | ||
} | ||
|
||
#[salsa::tracked] | ||
impl TrackedTrait for MyInput { | ||
type Type = u32; | ||
|
||
#[salsa::tracked] | ||
fn tracked_trait_fn(self, db: &dyn salsa::Database, ty: Self::Type) -> Self::Type { | ||
Self::untracked_trait_fn(); | ||
Self::tracked_fn(self, db, self) + ty | ||
} | ||
|
||
fn untracked_trait_fn() {} | ||
} | ||
|
||
#[test] | ||
fn execute() { | ||
let mut db = salsa::DatabaseImpl::new(); | ||
let object = MyInput::new(&mut db, 10); | ||
assert_eq!(object.tracked_trait_fn(&db, 1), 21); | ||
} |