Skip to content

Commit

Permalink
Merge pull request #449 from DropDemBits/assert-on-tracked-struct-out…
Browse files Browse the repository at this point in the history
…side-of-tracked-fn

Improve assert message when creating a tracked struct outside of a tracked function
  • Loading branch information
nikomatsakis authored Oct 28, 2023
2 parents c6ab691 + 22646a8 commit 6ac3724
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion components/salsa-2022/src/runtime/local_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,10 @@ impl LocalState {

#[track_caller]
pub(crate) fn disambiguate(&self, data_hash: u64) -> (DatabaseKeyIndex, Disambiguator) {
assert!(self.query_in_progress());
assert!(
self.query_in_progress(),
"cannot create a tracked struct disambiguator outside of a tracked function"
);
self.with_query_stack(|stack| {
let top_query = stack.last_mut().unwrap();
let disambiguator = top_query.disambiguate(data_hash);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! Test that creating a tracked struct outside of a
//! tracked function panics with an assert message.

#[salsa::jar(db = Db)]
struct Jar(MyTracked);

trait Db: salsa::DbWithJar<Jar> {}

#[salsa::tracked(jar = Jar)]
struct MyTracked {
field: u32,
}

#[salsa::db(Jar)]
#[derive(Default)]
struct Database {
storage: salsa::Storage<Self>,
}

impl salsa::Database for Database {}

impl Db for Database {}

#[test]
#[should_panic(
expected = "cannot create a tracked struct disambiguator outside of a tracked function"
)]
fn execute() {
let db = Database::default();
MyTracked::new(&db, 0);
}

0 comments on commit 6ac3724

Please sign in to comment.