Skip to content

Commit c48a9df

Browse files
committed
Improve span of maybe_update dummy implementation for better diagnostics
1 parent acbee94 commit c48a9df

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

components/salsa-macro-rules/src/setup_tracked_fn.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ macro_rules! setup_tracked_fn {
5555
// True if we `return_ref` flag was given to the function
5656
return_ref: $return_ref:tt,
5757

58+
maybe_update_fn: {$($maybe_update_fn:tt)*},
59+
5860
// Annoyingly macro-rules hygiene does not extend to items defined in the macro.
5961
// We have the procedural macro generate names for those items that are
6062
// not used elsewhere in the user's code.
@@ -150,14 +152,8 @@ macro_rules! setup_tracked_fn {
150152
///
151153
/// # Safety
152154
/// The same safety rules as for `Update` apply.
153-
unsafe fn _implements_update<'db>(old_pointer: *mut $output_ty, new_value: $output_ty) -> bool {
154-
unsafe {
155-
use $zalsa::UpdateFallback;
156-
$zalsa::UpdateDispatch::<$output_ty>::maybe_update(
157-
old_pointer, new_value
158-
)
159-
}
160-
}
155+
$($maybe_update_fn)*
156+
161157

162158
impl $zalsa::function::Configuration for $Configuration {
163159
const DEBUG_NAME: &'static str = stringify!($fn_name);

components/salsa-macros/src/tracked_fn.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ impl Macro {
117117

118118
let return_ref: bool = self.args.return_ref.is_some();
119119

120+
let maybe_update_fn = quote_spanned! {output_ty.span()=> {
121+
#[allow(clippy::all, unsafe_code)]
122+
unsafe fn _maybe_update_fn<'db>(old_pointer: *mut #output_ty, new_value: #output_ty) -> bool {
123+
unsafe {
124+
use #zalsa::UpdateFallback;
125+
#zalsa::UpdateDispatch::<#output_ty>::maybe_update(
126+
old_pointer, new_value
127+
)
128+
}
129+
}
130+
}};
131+
120132
Ok(crate::debug::dump_tokens(
121133
fn_name,
122134
quote![salsa::plumbing::setup_tracked_fn! {
@@ -137,6 +149,7 @@ impl Macro {
137149
needs_interner: #needs_interner,
138150
lru: #lru,
139151
return_ref: #return_ref,
152+
maybe_update_fn: { #maybe_update_fn },
140153
unused_names: [
141154
#zalsa,
142155
#Configuration,

tests/compile-fail/tracked_fn_return_ref.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use salsa::Database as Db;
2-
use salsa::Update;
32

43
#[salsa::input]
54
struct MyInput {
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
1-
warning: unused import: `salsa::Update`
2-
--> tests/compile-fail/tracked_fn_return_ref.rs:2:5
3-
|
4-
2 | use salsa::Update;
5-
| ^^^^^^^^^^^^^
6-
|
7-
= note: `#[warn(unused_imports)]` on by default
8-
91
error: lifetime may not live long enough
10-
--> tests/compile-fail/tracked_fn_return_ref.rs:15:1
2+
--> tests/compile-fail/tracked_fn_return_ref.rs:14:1
113
|
12-
15 | #[salsa::tracked]
13-
| ^^^^^^^^^^^^^^^^^
14-
| |
15-
| lifetime `'db` defined here
16-
| requires that `'db` must outlive `'static`
4+
14 | #[salsa::tracked]
5+
| ^^^^^^^^^^^^^^^^^ requires that `'db` must outlive `'static`
6+
15 | fn tracked_fn_return_ref<'db>(db: &'db dyn Db, input: MyInput) -> &'db str {
7+
| - lifetime `'db` defined here
178
|
18-
= note: this error originates in the macro `salsa::plumbing::setup_tracked_fn` which comes from the expansion of the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)
9+
= note: this error originates in the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)
1910

2011
error: lifetime may not live long enough
21-
--> tests/compile-fail/tracked_fn_return_ref.rs:20:1
12+
--> tests/compile-fail/tracked_fn_return_ref.rs:19:1
2213
|
23-
20 | #[salsa::tracked]
24-
| ^^^^^^^^^^^^^^^^^
25-
| |
26-
| lifetime `'db` defined here
27-
| requires that `'db` must outlive `'static`
14+
19 | #[salsa::tracked]
15+
| ^^^^^^^^^^^^^^^^^ requires that `'db` must outlive `'static`
16+
...
17+
23 | ) -> ContainsRef<'db> {
18+
| ----------- lifetime `'db` defined here
2819
|
29-
= note: this error originates in the macro `salsa::plumbing::setup_tracked_fn` which comes from the expansion of the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)
20+
= note: this error originates in the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)