Skip to content

Commit

Permalink
pacify the merciless clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed May 30, 2024
1 parent 88b964d commit 0ad0be8
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 38 deletions.
4 changes: 2 additions & 2 deletions components/salsa-2022-macros/src/db_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) fn default_db_lifetime(span: Span) -> syn::Lifetime {

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

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

/// Require that either there is exactly one lifetime parameter.
pub(crate) fn require_db_lifetime(generics: &syn::Generics) -> syn::Result<()> {
if generics.params.len() == 0 {
if generics.params.is_empty() {
return Err(syn::Error::new_spanned(
generics,
"this definition must have a `'db` lifetime",
Expand Down
3 changes: 1 addition & 2 deletions components/salsa-2022-macros/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ pub(crate) fn dump_tokens(input_name: impl ToString, tokens: TokenStream) -> Tok
.unwrap()
.write_all(token_string.as_bytes())?;
rustfmt.wait_with_output()
})
.and_then(|output| Ok(eprintln!("{}", String::from_utf8_lossy(&output.stdout))))
}).map(|output| eprintln!("{}", String::from_utf8_lossy(&output.stdout)))
.or_else(|_| Ok(eprintln!("{token_string}")));
}

Expand Down
4 changes: 2 additions & 2 deletions components/salsa-2022-macros/src/debug_with_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ pub(crate) fn debug_with_db(input: syn::DeriveInput) -> syn::Result<proc_macro2:
|tokens, binding| {
let binding_name =
Literal::string(&binding.ast().ident.as_ref().unwrap().to_string());
let binding_data = binding_tokens(&binding);
let binding_data = binding_tokens(binding);
quote!(#tokens . field(#binding_name, #binding_data))
},
),

syn::Fields::Unnamed(_) | syn::Fields::Unit => variant.fold(
quote!(#fmt.debug_tuple(#variant_name)),
|tokens, binding| {
let binding_data = binding_tokens(&binding);
let binding_data = binding_tokens(binding);
quote!(#tokens . field(#binding_data))
},
),
Expand Down
2 changes: 1 addition & 1 deletion components/salsa-2022-macros/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl InputStruct {
let inherent_impl = self.input_inherent_impl();
let ingredients_for_impl = self.input_ingredients();
let as_id_impl = self.as_id_impl();
let from_id_impl = self.from_id_impl();
let from_id_impl = self.impl_of_from_id();
let salsa_struct_in_db_impl = self.salsa_struct_in_db_impl();
let as_debug_with_db_impl = self.as_debug_with_db_impl();
let debug_impl = self.debug_impl();
Expand Down
2 changes: 1 addition & 1 deletion components/salsa-2022-macros/src/interned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl InternedStruct {
let configuration_impl = self.configuration_impl(&data_struct.ident, &config_struct.ident);
let ingredients_for_impl = self.ingredients_for_impl(&config_struct.ident);
let as_id_impl = self.as_id_impl();
let from_id_impl = self.from_id_impl();
let from_id_impl = self.impl_of_from_id();
let lookup_id_impl = self.lookup_id_impl();
let send_sync_impls = self.send_sync_impls();
let named_fields_impl = self.inherent_impl_for_named_fields();
Expand Down
4 changes: 2 additions & 2 deletions components/salsa-2022-macros/src/salsa_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<A: AllowedOptions> SalsaStruct<A> {
// FIXME: this should be a comma separated list but I couldn't
// be bothered to remember how syn does this.
let args: syn::Ident = attr.parse_args()?;
if args.to_string() == "DebugWithDb" {
if args == "DebugWithDb" {
Ok(vec![Customization::DebugWithDb])
} else {
Err(syn::Error::new_spanned(args, "unrecognized customization"))
Expand Down Expand Up @@ -446,7 +446,7 @@ impl<A: AllowedOptions> SalsaStruct<A> {
}

/// Generate `impl salsa::id::AsId for Foo`
pub(crate) fn from_id_impl(&self) -> Option<syn::ItemImpl> {
pub(crate) fn impl_of_from_id(&self) -> Option<syn::ItemImpl> {
match self.the_struct_kind() {
TheStructKind::Id => {
let ident = self.the_ident();
Expand Down
2 changes: 1 addition & 1 deletion components/salsa-2022-macros/src/tracked_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub(crate) fn tracked_fn(
*item_fn.block = getter_fn(&args, &mut item_fn.sig, item_fn.block.span(), &config_ty)?;

Ok(crate::debug::dump_tokens(
&fn_ident,
fn_ident,
quote! {
#fn_struct

Expand Down
6 changes: 2 additions & 4 deletions components/salsa-2022-macros/src/tracked_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) fn tracked(
let tokens = SalsaStruct::with_struct(args, struct_item, "tracked_struct")
.and_then(|el| TrackedStruct(el).generate_tracked())?;

Ok(crate::debug::dump_tokens(&struct_name, tokens))
Ok(crate::debug::dump_tokens(struct_name, tokens))
}

struct TrackedStruct(SalsaStruct<Self>);
Expand Down Expand Up @@ -65,7 +65,7 @@ impl TrackedStruct {
let update_impl = self.update_impl();
let as_id_impl = self.as_id_impl();
let send_sync_impls = self.send_sync_impls();
let from_id_impl = self.from_id_impl();
let from_id_impl = self.impl_of_from_id();
let lookup_id_impl = self.lookup_id_impl();
let debug_impl = self.debug_impl();
let as_debug_with_db_impl = self.as_debug_with_db_impl();
Expand Down Expand Up @@ -250,8 +250,6 @@ impl TrackedStruct {
let field_tys = self.all_field_tys();
let constructor_name = self.constructor_name();

let data = syn::Ident::new("__data", Span::call_site());

let salsa_id = self.access_salsa_id_from_self();

let lt_db = self.maybe_elided_db_lifetime();
Expand Down
2 changes: 1 addition & 1 deletion components/salsa-2022/src/function/memo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<C: Configuration> MemoMap<C> {

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

Expand Down
11 changes: 5 additions & 6 deletions components/salsa-2022/src/interned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::durability::Durability;
use crate::id::{AsId, LookupId};
use crate::ingredient::{fmt_index, IngredientRequiresReset};
use crate::key::DependencyIndex;
use crate::plumbing::transmute_lifetime;
use crate::runtime::local_state::QueryOrigin;
use crate::runtime::Runtime;
use crate::{DatabaseKeyIndex, Id};
Expand All @@ -30,7 +29,7 @@ pub trait Configuration: Sized {
/// created or, if a struct is being reused, after we have updated its
/// fields (or confirmed it is green and no updates are required).
///
/// # Unsafety
/// # Safety
///
/// Requires that `ptr` represents a "confirmed" value in this revision,
/// which means that it will remain valid and immutable for the remainder of this
Expand All @@ -40,7 +39,7 @@ pub trait Configuration: Sized {
/// Deref the struct to yield the underlying value struct.
/// Since we are still part of the `'db` lifetime in which the struct was created,
/// this deref is safe, and the value-struct fields are immutable and verified.
fn deref_struct<'db>(s: Self::Struct<'db>) -> &'db ValueStruct<Self>;
fn deref_struct(s: Self::Struct<'_>) -> &ValueStruct<Self>;
}

pub trait InternedData: Sized + Eq + Hash + Clone {}
Expand Down Expand Up @@ -152,7 +151,7 @@ where
}
}

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

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

Expand Down Expand Up @@ -284,7 +283,7 @@ impl<C> ValueStruct<C>
where
C: Configuration,
{
pub fn data<'db>(&'db self) -> &'db C::Data<'db> {
pub fn data(&self) -> &C::Data<'_> {
// SAFETY: The lifetime of `self` is tied to the interning ingredient;
// we never remove data without an `&mut self` access to the interning ingredient.
unsafe { self.to_self_ref(&self.fields) }
Expand Down
2 changes: 1 addition & 1 deletion components/salsa-2022/src/runtime/active_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl ActiveQuery {
pub(crate) fn take_inputs_from(&mut self, cycle_query: &ActiveQuery) {
self.changed_at = cycle_query.changed_at;
self.durability = cycle_query.durability;
self.input_outputs = cycle_query.input_outputs.clone();
self.input_outputs.clone_from(&cycle_query.input_outputs);
}

pub(super) fn disambiguate(&mut self, hash: u64) -> Disambiguator {
Expand Down
6 changes: 3 additions & 3 deletions components/salsa-2022/src/tracked_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub trait Configuration: Sized {
/// created or, if a struct is being reused, after we have updated its
/// fields (or confirmed it is green and no updates are required).
///
/// # Unsafety
/// # Safety
///
/// Requires that `ptr` represents a "confirmed" value in this revision,
/// which means that it will remain valid and immutable for the remainder of this
Expand All @@ -54,7 +54,7 @@ pub trait Configuration: Sized {
/// Deref the struct to yield the underlying value struct.
/// Since we are still part of the `'db` lifetime in which the struct was created,
/// this deref is safe, and the value-struct fields are immutable and verified.
fn deref_struct<'db>(s: Self::Struct<'db>) -> &'db ValueStruct<Self>;
fn deref_struct(s: Self::Struct<'_>) -> &ValueStruct<Self>;

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

Expand All @@ -68,7 +68,7 @@ pub trait Configuration: Sized {
/// Update the field data and, if the value has changed,
/// the appropriate entry in the `revisions` array.
///
/// # Safety requirements and conditions
/// # Safety
///
/// Requires the same conditions as the `maybe_update`
/// method on [the `Update` trait](`crate::update::Update`).
Expand Down
1 change: 0 additions & 1 deletion components/salsa-2022/src/tracked_struct/struct_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use dashmap::mapref::one::RefMut;
use crate::{
alloc::Alloc,
hash::{FxDashMap, FxHasher},
plumbing::transmute_lifetime,
Id, Runtime,
};

Expand Down
16 changes: 15 additions & 1 deletion components/salsa-2022/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub mod helper {

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

impl<D> Default for Dispatch<D> {
fn default() -> Self {
Self::new()
}
}

impl<D> Dispatch<D> {
pub fn new() -> Self {
Dispatch(PhantomData)
Expand All @@ -33,11 +39,17 @@ pub mod helper {
where
D: Update,
{
/// # Safety
///
/// See the `maybe_update` method in the [`Update`][] trait.
pub unsafe fn maybe_update(old_pointer: *mut D, new_value: D) -> bool {
unsafe { D::maybe_update(old_pointer, new_value) }
}
}

/// # Safety
///
/// Impl will fulfill the postconditions of `maybe_update`
pub unsafe trait Fallback<T> {
/// Same safety conditions as `Update::maybe_update`
unsafe fn maybe_update(old_pointer: *mut T, new_value: T) -> bool;
Expand Down Expand Up @@ -92,14 +104,16 @@ pub fn always_update<T>(
*old_pointer = new_value;
}

/// # Safety
///
/// The `unsafe` on the trait is to assert that `maybe_update` ensures
/// the properties it is intended to ensure.
pub unsafe trait Update {
/// # Returns
///
/// True if the value should be considered to have changed in the new revision.
///
/// # Unsafe contract
/// # Safety
///
/// ## Requires
///
Expand Down
4 changes: 2 additions & 2 deletions salsa-2022-tests/tests/interned-struct-with-lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct InternedPair<'db> {

#[salsa::tracked]
fn intern_stuff(db: &dyn Db) -> String {
let s1 = InternedString::new(db, format!("Hello, "));
let s2 = InternedString::new(db, format!("World, "));
let s1 = InternedString::new(db, "Hello, ".to_string());
let s2 = InternedString::new(db, "World, ".to_string());
let s3 = InternedPair::new(db, (s1, s2));
format!("{:?}", s3.debug(db))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use salsa_2022_tests::{HasLogger, Logger};
use test_log::test;

thread_local! {
static COUNTER: Cell<usize> = Cell::new(0);
static COUNTER: Cell<usize> = const { Cell::new(0) };
}

#[salsa::jar(db = Db)]
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ pub struct Event {
impl Event {
/// Returns a type that gives a user-readable debug output.
/// Use like `println!("{:?}", index.debug(db))`.
pub fn debug<'me, D: ?Sized>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
pub fn debug<'me, D>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
where
D: plumbing::DatabaseOps,
D: ?Sized + plumbing::DatabaseOps,
{
EventDebug { event: self, db }
}
Expand Down Expand Up @@ -201,9 +201,9 @@ pub enum EventKind {
impl EventKind {
/// Returns a type that gives a user-readable debug output.
/// Use like `println!("{:?}", index.debug(db))`.
pub fn debug<'me, D: ?Sized>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
pub fn debug<'me, D>(&'me self, db: &'me D) -> impl std::fmt::Debug + 'me
where
D: plumbing::DatabaseOps,
D: ?Sized + plumbing::DatabaseOps,
{
EventKindDebug { kind: self, db }
}
Expand Down Expand Up @@ -402,9 +402,9 @@ impl DatabaseKeyIndex {

/// Returns a type that gives a user-readable debug output.
/// Use like `println!("{:?}", index.debug(db))`.
pub fn debug<D: ?Sized>(self, db: &D) -> impl std::fmt::Debug + '_
pub fn debug<D>(self, db: &D) -> impl std::fmt::Debug + '_
where
D: plumbing::DatabaseOps,
D: ?Sized + plumbing::DatabaseOps,
{
DatabaseKeyIndexDebug { index: self, db }
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ impl ActiveQuery {
pub(crate) fn take_inputs_from(&mut self, cycle_query: &ActiveQuery) {
self.changed_at = cycle_query.changed_at;
self.durability = cycle_query.durability;
self.dependencies = cycle_query.dependencies.clone();
self.dependencies.clone_from(&cycle_query.dependencies);
}
}

Expand Down

0 comments on commit 0ad0be8

Please sign in to comment.