Closed
Description
The following example misses a #[salsa::db]
on the impl Db for Pimpl
but it only fails at runtime with a panic in as_view
.
Ideally, we would catch this error at compile time. If this isn't possible, improve the error message to guide users towards the proper fix.
use salsa::Accumulator;
#[salsa::db]
trait Db: salsa::Database {}
#[salsa::db]
pub(crate) struct Pimpl {
storage: salsa::Storage<Self>,
}
#[salsa::db]
impl salsa::Database for Pimpl {
fn salsa_event(&self, _event: &dyn Fn() -> salsa::Event) {}
}
// #[salsa::db] <-----MISSING
impl Db for Pimpl {
}
#[salsa::input]
struct File {
#[return_ref]
contents: String,
}
#[salsa::tracked]
struct Element<'db> {}
#[salsa::accumulator]
struct Diagnostic(&'static str);
#[salsa::tracked]
fn parse_single_file(db: &dyn Db, file: File) -> Option<Element<'_>> {
Diagnostic("argh").accumulate(db);
None
}
impl Pimpl {
pub(crate) fn new() -> Self {
Self {
storage: Default::default(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let mut pimpl = Pimpl::new();
let this = &mut pimpl;
let file = File::new(this, "Hello World!".to_string());
let node = parse_single_file(this, file);
// FIXME: This panics with 'Unwrap on None value'
parse_single_file::accumulated::<Diagnostic>(this, file);
}
}
Metadata
Metadata
Assignees
Labels
No labels