salsa/salsa-2022-tests/tests
bors[bot] 252d21e358
Merge #423
423: salsa 2022: fix input macro set_* being off by one if id field present r=XFFXFF a=jhgg

This PR fixes an issue with code generation for `#[salsa::input]` struct's `set_` methods. 

Consider the following code:

```rust
#[salsa::input(jar = Jar)]
struct BuggedInput {
    #[id]
    id: u32,
    other: String,
}
```

This will expand to:

```rust
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug)]
struct BuggedInput(salsa::Id);

impl BuggedInput {
     // snip...
    fn set_other<'db>(
        self,
        __db: &'db mut <Jar as salsa:🫙:Jar<'_>>::DynDb,
    ) -> salsa::setter::Setter<'db, BuggedInput, u32> {
        //                                       ^^^ wrong type (should be `String`)
        let (__jar, __runtime) = <_ as salsa::storage::HasJar<Jar>>::jar_mut(__db);
        let __ingredients =
            <Jar as salsa::storage::HasIngredientsFor<BuggedInput>>::ingredient_mut(__jar);
        salsa::setter::Setter::new(__runtime, self, &mut __ingredients.0)
        //                                                             ^ wrong index (should be `1`)
   }
}
```

Here we can see that the generated `set_other` impl is improperly setting the `id` field. This bug is caused because the filtering of the id fields in `InputStruct::all_set_field_names` causes a mismatch in `InputStruct::input_inherent_impl` when zipped with the field indices and types.

This PR changes `all_set_field_names` to return an `Option<&syn::Ident>` where the None is provided when a setter should not be generated, thus not causing index mismatches because no filtering occurs. Instead, we filter inside of `input_inherent_impl` after all the zips have been applied to the iterator.

After this PR, the code generated is now correct:

```rust
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug)]
struct BuggedInput(salsa::Id);

impl BuggedInput {
     // snip...
    fn set_other<'db>(
        self,
        __db: &'db mut <Jar as salsa:🫙:Jar<'_>>::DynDb,
    ) -> salsa::setter::Setter<'db, BuggedInput, String> {
        let (__jar, __runtime) = <_ as salsa::storage::HasJar<Jar>>::jar_mut(__db);
        let __ingredients =
            <Jar as salsa::storage::HasIngredientsFor<BuggedInput>>::ingredient_mut(__jar);
        salsa::setter::Setter::new(__runtime, self, &mut __ingredients.1)
    }
}
```


Co-authored-by: Jake Heinz <jh@discordapp.com>
2022-11-29 04:54:45 +00:00
..
compile-fail update compile fail tests for latest stable rustc 2022-11-29 12:36:12 +08:00
parallel Support on-demand inputs 2022-09-15 21:25:53 +01:00
warnings propagate include_all_fields option 2022-09-13 18:01:21 +02:00
accumulate-from-tracked-fn.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
accumulate-reuse-workaround.rs fix accumulator: clear the outdated accumulated values 2022-09-25 00:24:16 +00:00
accumulate-reuse.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
accumulate.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
compile_fail.rs
cycles.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
debug.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
deletion-cascade.rs update test: don't need mut reference when create inputs 2022-09-25 01:38:41 +00:00
deletion.rs update some tests and run cargo fmt 2022-09-24 23:59:25 +00:00
expect_reuse_field_x_of_a_tracked_struct_changes_but_fn_depends_on_field_y.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
expect_reuse_field_x_of_an_input_changes_but_fn_depends_on_field_y.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
hello_world.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
input_with_ids.rs salsa 2022: fix input macro set_* being off by one if id field present 2022-11-04 23:39:35 +00:00
lru.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
mutate_in_place.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
override_new_get_set.rs
panic-when-reading-fields-of-tracked-structs-from-older-revisions.rs update test: don't need mut reference when create inputs 2022-09-25 01:38:41 +00:00
singleton.rs update test: don't need mut reference when create inputs 2022-09-25 01:38:41 +00:00
specify-only-works-if-the-key-is-created-in-the-current-query.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
specify_tracked_fn_in_rev_1_but_not_2.rs update some tests and run cargo fmt 2022-09-24 23:59:25 +00:00
tracked_fn_constant.rs Replace () with Singleton Salsa struct 2022-09-06 00:34:00 +01:00
tracked_fn_on_input.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
tracked_fn_on_tracked.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
tracked_fn_on_tracked_specify.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
tracked_fn_read_own_entity.rs Support on-demand inputs 2022-09-15 21:25:53 +01:00
tracked_fn_read_own_specify.rs update a test 2022-09-24 23:59:25 +00:00
tracked_method.rs