Skip to content

Commit 0ad0be8

Browse files
committed
pacify the merciless clippy
1 parent 88b964d commit 0ad0be8

18 files changed

+47
-38
lines changed

components/salsa-2022-macros/src/db_lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) fn default_db_lifetime(span: Span) -> syn::Lifetime {
1616

1717
/// Require that either there are no generics or exactly one lifetime parameter.
1818
pub(crate) fn require_optional_db_lifetime(generics: &syn::Generics) -> syn::Result<()> {
19-
if generics.params.len() == 0 {
19+
if generics.params.is_empty() {
2020
return Ok(());
2121
}
2222

@@ -27,7 +27,7 @@ pub(crate) fn require_optional_db_lifetime(generics: &syn::Generics) -> syn::Res
2727

2828
/// Require that either there is exactly one lifetime parameter.
2929
pub(crate) fn require_db_lifetime(generics: &syn::Generics) -> syn::Result<()> {
30-
if generics.params.len() == 0 {
30+
if generics.params.is_empty() {
3131
return Err(syn::Error::new_spanned(
3232
generics,
3333
"this definition must have a `'db` lifetime",

components/salsa-2022-macros/src/debug.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ pub(crate) fn dump_tokens(input_name: impl ToString, tokens: TokenStream) -> Tok
3131
.unwrap()
3232
.write_all(token_string.as_bytes())?;
3333
rustfmt.wait_with_output()
34-
})
35-
.and_then(|output| Ok(eprintln!("{}", String::from_utf8_lossy(&output.stdout))))
34+
}).map(|output| eprintln!("{}", String::from_utf8_lossy(&output.stdout)))
3635
.or_else(|_| Ok(eprintln!("{token_string}")));
3736
}
3837

components/salsa-2022-macros/src/debug_with_db.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ pub(crate) fn debug_with_db(input: syn::DeriveInput) -> syn::Result<proc_macro2:
6262
|tokens, binding| {
6363
let binding_name =
6464
Literal::string(&binding.ast().ident.as_ref().unwrap().to_string());
65-
let binding_data = binding_tokens(&binding);
65+
let binding_data = binding_tokens(binding);
6666
quote!(#tokens . field(#binding_name, #binding_data))
6767
},
6868
),
6969

7070
syn::Fields::Unnamed(_) | syn::Fields::Unit => variant.fold(
7171
quote!(#fmt.debug_tuple(#variant_name)),
7272
|tokens, binding| {
73-
let binding_data = binding_tokens(&binding);
73+
let binding_data = binding_tokens(binding);
7474
quote!(#tokens . field(#binding_data))
7575
},
7676
),

components/salsa-2022-macros/src/input.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl InputStruct {
5555
let inherent_impl = self.input_inherent_impl();
5656
let ingredients_for_impl = self.input_ingredients();
5757
let as_id_impl = self.as_id_impl();
58-
let from_id_impl = self.from_id_impl();
58+
let from_id_impl = self.impl_of_from_id();
5959
let salsa_struct_in_db_impl = self.salsa_struct_in_db_impl();
6060
let as_debug_with_db_impl = self.as_debug_with_db_impl();
6161
let debug_impl = self.debug_impl();

components/salsa-2022-macros/src/interned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl InternedStruct {
6262
let configuration_impl = self.configuration_impl(&data_struct.ident, &config_struct.ident);
6363
let ingredients_for_impl = self.ingredients_for_impl(&config_struct.ident);
6464
let as_id_impl = self.as_id_impl();
65-
let from_id_impl = self.from_id_impl();
65+
let from_id_impl = self.impl_of_from_id();
6666
let lookup_id_impl = self.lookup_id_impl();
6767
let send_sync_impls = self.send_sync_impls();
6868
let named_fields_impl = self.inherent_impl_for_named_fields();

components/salsa-2022-macros/src/salsa_struct.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<A: AllowedOptions> SalsaStruct<A> {
177177
// FIXME: this should be a comma separated list but I couldn't
178178
// be bothered to remember how syn does this.
179179
let args: syn::Ident = attr.parse_args()?;
180-
if args.to_string() == "DebugWithDb" {
180+
if args == "DebugWithDb" {
181181
Ok(vec![Customization::DebugWithDb])
182182
} else {
183183
Err(syn::Error::new_spanned(args, "unrecognized customization"))
@@ -446,7 +446,7 @@ impl<A: AllowedOptions> SalsaStruct<A> {
446446
}
447447

448448
/// Generate `impl salsa::id::AsId for Foo`
449-
pub(crate) fn from_id_impl(&self) -> Option<syn::ItemImpl> {
449+
pub(crate) fn impl_of_from_id(&self) -> Option<syn::ItemImpl> {
450450
match self.the_struct_kind() {
451451
TheStructKind::Id => {
452452
let ident = self.the_ident();

components/salsa-2022-macros/src/tracked_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub(crate) fn tracked_fn(
5050
*item_fn.block = getter_fn(&args, &mut item_fn.sig, item_fn.block.span(), &config_ty)?;
5151

5252
Ok(crate::debug::dump_tokens(
53-
&fn_ident,
53+
fn_ident,
5454
quote! {
5555
#fn_struct
5656

components/salsa-2022-macros/src/tracked_struct.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) fn tracked(
1616
let tokens = SalsaStruct::with_struct(args, struct_item, "tracked_struct")
1717
.and_then(|el| TrackedStruct(el).generate_tracked())?;
1818

19-
Ok(crate::debug::dump_tokens(&struct_name, tokens))
19+
Ok(crate::debug::dump_tokens(struct_name, tokens))
2020
}
2121

2222
struct TrackedStruct(SalsaStruct<Self>);
@@ -65,7 +65,7 @@ impl TrackedStruct {
6565
let update_impl = self.update_impl();
6666
let as_id_impl = self.as_id_impl();
6767
let send_sync_impls = self.send_sync_impls();
68-
let from_id_impl = self.from_id_impl();
68+
let from_id_impl = self.impl_of_from_id();
6969
let lookup_id_impl = self.lookup_id_impl();
7070
let debug_impl = self.debug_impl();
7171
let as_debug_with_db_impl = self.as_debug_with_db_impl();
@@ -250,8 +250,6 @@ impl TrackedStruct {
250250
let field_tys = self.all_field_tys();
251251
let constructor_name = self.constructor_name();
252252

253-
let data = syn::Ident::new("__data", Span::call_site());
254-
255253
let salsa_id = self.access_salsa_id_from_self();
256254

257255
let lt_db = self.maybe_elided_db_lifetime();

components/salsa-2022/src/function/memo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<C: Configuration> MemoMap<C> {
5858

5959
/// Removes any existing memo for the given key.
6060
#[must_use]
61-
pub(super) fn remove<'db>(&'db self, key: Id) -> Option<ArcSwap<Memo<C::Value<'db>>>> {
61+
pub(super) fn remove(&self, key: Id) -> Option<ArcSwap<Memo<C::Value<'_>>>> {
6262
unsafe { self.map.remove(&key).map(|o| self.to_self(o.1)) }
6363
}
6464

components/salsa-2022/src/interned.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::durability::Durability;
99
use crate::id::{AsId, LookupId};
1010
use crate::ingredient::{fmt_index, IngredientRequiresReset};
1111
use crate::key::DependencyIndex;
12-
use crate::plumbing::transmute_lifetime;
1312
use crate::runtime::local_state::QueryOrigin;
1413
use crate::runtime::Runtime;
1514
use crate::{DatabaseKeyIndex, Id};
@@ -30,7 +29,7 @@ pub trait Configuration: Sized {
3029
/// created or, if a struct is being reused, after we have updated its
3130
/// fields (or confirmed it is green and no updates are required).
3231
///
33-
/// # Unsafety
32+
/// # Safety
3433
///
3534
/// Requires that `ptr` represents a "confirmed" value in this revision,
3635
/// which means that it will remain valid and immutable for the remainder of this
@@ -40,7 +39,7 @@ pub trait Configuration: Sized {
4039
/// Deref the struct to yield the underlying value struct.
4140
/// Since we are still part of the `'db` lifetime in which the struct was created,
4241
/// this deref is safe, and the value-struct fields are immutable and verified.
43-
fn deref_struct<'db>(s: Self::Struct<'db>) -> &'db ValueStruct<Self>;
42+
fn deref_struct(s: Self::Struct<'_>) -> &ValueStruct<Self>;
4443
}
4544

4645
pub trait InternedData: Sized + Eq + Hash + Clone {}
@@ -152,7 +151,7 @@ where
152151
}
153152
}
154153

155-
pub fn interned_value<'db>(&'db self, id: Id) -> C::Struct<'db> {
154+
pub fn interned_value(&self, id: Id) -> C::Struct<'_> {
156155
let r = self.value_map.get(&id).unwrap();
157156

158157
// SAFETY: Items are only removed from the `value_map` with an `&mut self` reference.
@@ -162,7 +161,7 @@ where
162161
/// Lookup the data for an interned value based on its id.
163162
/// Rarely used since end-users generally carry a struct with a pointer directly
164163
/// to the interned item.
165-
pub fn data<'db>(&'db self, id: Id) -> &'db C::Data<'db> {
164+
pub fn data(&self, id: Id) -> &C::Data<'_> {
166165
C::deref_struct(self.interned_value(id)).data()
167166
}
168167

@@ -284,7 +283,7 @@ impl<C> ValueStruct<C>
284283
where
285284
C: Configuration,
286285
{
287-
pub fn data<'db>(&'db self) -> &'db C::Data<'db> {
286+
pub fn data(&self) -> &C::Data<'_> {
288287
// SAFETY: The lifetime of `self` is tied to the interning ingredient;
289288
// we never remove data without an `&mut self` access to the interning ingredient.
290289
unsafe { self.to_self_ref(&self.fields) }

components/salsa-2022/src/runtime/active_query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl ActiveQuery {
172172
pub(crate) fn take_inputs_from(&mut self, cycle_query: &ActiveQuery) {
173173
self.changed_at = cycle_query.changed_at;
174174
self.durability = cycle_query.durability;
175-
self.input_outputs = cycle_query.input_outputs.clone();
175+
self.input_outputs.clone_from(&cycle_query.input_outputs);
176176
}
177177

178178
pub(super) fn disambiguate(&mut self, hash: u64) -> Disambiguator {

components/salsa-2022/src/tracked_struct.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub trait Configuration: Sized {
4444
/// created or, if a struct is being reused, after we have updated its
4545
/// fields (or confirmed it is green and no updates are required).
4646
///
47-
/// # Unsafety
47+
/// # Safety
4848
///
4949
/// Requires that `ptr` represents a "confirmed" value in this revision,
5050
/// which means that it will remain valid and immutable for the remainder of this
@@ -54,7 +54,7 @@ pub trait Configuration: Sized {
5454
/// Deref the struct to yield the underlying value struct.
5555
/// Since we are still part of the `'db` lifetime in which the struct was created,
5656
/// this deref is safe, and the value-struct fields are immutable and verified.
57-
fn deref_struct<'db>(s: Self::Struct<'db>) -> &'db ValueStruct<Self>;
57+
fn deref_struct(s: Self::Struct<'_>) -> &ValueStruct<Self>;
5858

5959
fn id_fields(fields: &Self::Fields<'_>) -> impl Hash;
6060

@@ -68,7 +68,7 @@ pub trait Configuration: Sized {
6868
/// Update the field data and, if the value has changed,
6969
/// the appropriate entry in the `revisions` array.
7070
///
71-
/// # Safety requirements and conditions
71+
/// # Safety
7272
///
7373
/// Requires the same conditions as the `maybe_update`
7474
/// method on [the `Update` trait](`crate::update::Update`).

components/salsa-2022/src/tracked_struct/struct_map.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use dashmap::mapref::one::RefMut;
99
use crate::{
1010
alloc::Alloc,
1111
hash::{FxDashMap, FxHasher},
12-
plumbing::transmute_lifetime,
1312
Id, Runtime,
1413
};
1514

components/salsa-2022/src/update.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ pub mod helper {
2323

2424
pub struct Dispatch<D>(PhantomData<D>);
2525

26+
impl<D> Default for Dispatch<D> {
27+
fn default() -> Self {
28+
Self::new()
29+
}
30+
}
31+
2632
impl<D> Dispatch<D> {
2733
pub fn new() -> Self {
2834
Dispatch(PhantomData)
@@ -33,11 +39,17 @@ pub mod helper {
3339
where
3440
D: Update,
3541
{
42+
/// # Safety
43+
///
44+
/// See the `maybe_update` method in the [`Update`][] trait.
3645
pub unsafe fn maybe_update(old_pointer: *mut D, new_value: D) -> bool {
3746
unsafe { D::maybe_update(old_pointer, new_value) }
3847
}
3948
}
4049

50+
/// # Safety
51+
///
52+
/// Impl will fulfill the postconditions of `maybe_update`
4153
pub unsafe trait Fallback<T> {
4254
/// Same safety conditions as `Update::maybe_update`
4355
unsafe fn maybe_update(old_pointer: *mut T, new_value: T) -> bool;
@@ -92,14 +104,16 @@ pub fn always_update<T>(
92104
*old_pointer = new_value;
93105
}
94106

107+
/// # Safety
108+
///
95109
/// The `unsafe` on the trait is to assert that `maybe_update` ensures
96110
/// the properties it is intended to ensure.
97111
pub unsafe trait Update {
98112
/// # Returns
99113
///
100114
/// True if the value should be considered to have changed in the new revision.
101115
///
102-
/// # Unsafe contract
116+
/// # Safety
103117
///
104118
/// ## Requires
105119
///

salsa-2022-tests/tests/interned-struct-with-lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ struct InternedPair<'db> {
2323

2424
#[salsa::tracked]
2525
fn intern_stuff(db: &dyn Db) -> String {
26-
let s1 = InternedString::new(db, format!("Hello, "));
27-
let s2 = InternedString::new(db, format!("World, "));
26+
let s1 = InternedString::new(db, "Hello, ".to_string());
27+
let s2 = InternedString::new(db, "World, ".to_string());
2828
let s3 = InternedPair::new(db, (s1, s2));
2929
format!("{:?}", s3.debug(db))
3030
}

salsa-2022-tests/tests/preverify-struct-with-leaked-data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use salsa_2022_tests::{HasLogger, Logger};
99
use test_log::test;
1010

1111
thread_local! {
12-
static COUNTER: Cell<usize> = Cell::new(0);
12+
static COUNTER: Cell<usize> = const { Cell::new(0) };
1313
}
1414

1515
#[salsa::jar(db = Db)]

src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ pub struct Event {
119119
impl Event {
120120
/// Returns a type that gives a user-readable debug output.
121121
/// Use like `println!("{:?}", index.debug(db))`.
122-
pub fn debug<'me, D: ?Sized>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
122+
pub fn debug<'me, D>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
123123
where
124-
D: plumbing::DatabaseOps,
124+
D: ?Sized + plumbing::DatabaseOps,
125125
{
126126
EventDebug { event: self, db }
127127
}
@@ -201,9 +201,9 @@ pub enum EventKind {
201201
impl EventKind {
202202
/// Returns a type that gives a user-readable debug output.
203203
/// Use like `println!("{:?}", index.debug(db))`.
204-
pub fn debug<'me, D: ?Sized>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
204+
pub fn debug<'me, D>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
205205
where
206-
D: plumbing::DatabaseOps,
206+
D: ?Sized + plumbing::DatabaseOps,
207207
{
208208
EventKindDebug { kind: self, db }
209209
}
@@ -402,9 +402,9 @@ impl DatabaseKeyIndex {
402402

403403
/// Returns a type that gives a user-readable debug output.
404404
/// Use like `println!("{:?}", index.debug(db))`.
405-
pub fn debug<D: ?Sized>(self, db: &D) -> impl std::fmt::Debug + '_
405+
pub fn debug<D>(self, db: &D) -> impl std::fmt::Debug + '_
406406
where
407-
D: plumbing::DatabaseOps,
407+
D: ?Sized + plumbing::DatabaseOps,
408408
{
409409
DatabaseKeyIndexDebug { index: self, db }
410410
}

src/runtime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ impl ActiveQuery {
628628
pub(crate) fn take_inputs_from(&mut self, cycle_query: &ActiveQuery) {
629629
self.changed_at = cycle_query.changed_at;
630630
self.durability = cycle_query.durability;
631-
self.dependencies = cycle_query.dependencies.clone();
631+
self.dependencies.clone_from(&cycle_query.dependencies);
632632
}
633633
}
634634

0 commit comments

Comments
 (0)