Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/bevy_animation/src/animation_curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub trait AnimatableProperty: Send + Sync + 'static {

/// The [`EvaluatorId`] used to look up the [`AnimationCurveEvaluator`] for this [`AnimatableProperty`].
/// For a given animated property, this ID should always be the same to allow things like animation blending to occur.
fn evaluator_id(&self) -> EvaluatorId;
fn evaluator_id(&self) -> EvaluatorId<'_>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very standard case: we're secretly returning an object with a lifetime bound to self.

Good lint!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice. It always bugged me that you couldn't tell the difference between a thing with a lifetime tied to self and something that was static.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. Pretty much sells me on this lint.

}

/// A [`Component`] field that can be animated, defined by a function that reads the component and returns
Expand Down Expand Up @@ -236,7 +236,7 @@ where
Ok((self.func)(c.into_inner()))
}

fn evaluator_id(&self) -> EvaluatorId {
fn evaluator_id(&self) -> EvaluatorId<'_> {
EvaluatorId::ComponentField(&self.evaluator_id)
}
}
Expand Down Expand Up @@ -357,7 +357,7 @@ where
self.curve.domain()
}

fn evaluator_id(&self) -> EvaluatorId {
fn evaluator_id(&self) -> EvaluatorId<'_> {
self.property.evaluator_id()
}

Expand Down Expand Up @@ -476,7 +476,7 @@ where
self.0.domain()
}

fn evaluator_id(&self) -> EvaluatorId {
fn evaluator_id(&self) -> EvaluatorId<'_> {
EvaluatorId::Type(TypeId::of::<WeightsCurveEvaluator>())
}

Expand Down Expand Up @@ -768,7 +768,7 @@ pub trait AnimationCurve: Debug + Send + Sync + 'static {
///
/// This must match the type returned by [`Self::create_evaluator`]. It must
/// be a single type that doesn't depend on the type of the curve.
fn evaluator_id(&self) -> EvaluatorId;
fn evaluator_id(&self) -> EvaluatorId<'_>;

/// Returns a newly-instantiated [`AnimationCurveEvaluator`] for use with
/// this curve.
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ struct CurrentEvaluators {
}

impl CurrentEvaluators {
pub(crate) fn keys(&self) -> impl Iterator<Item = EvaluatorId> {
pub(crate) fn keys(&self) -> impl Iterator<Item = EvaluatorId<'_>> {
self.component_properties
.keys()
.map(EvaluatorId::ComponentField)
Expand Down Expand Up @@ -1462,7 +1462,7 @@ impl<'a> TriggeredEvents<'a> {
self.lower.is_empty() && self.upper.is_empty()
}

fn iter(&self) -> TriggeredEventsIter {
fn iter(&self) -> TriggeredEventsIter<'_> {
match self.direction {
TriggeredEventsDir::Forward => TriggeredEventsIter::Forward(self.lower.iter()),
TriggeredEventsDir::Reverse => TriggeredEventsIter::Reverse(self.lower.iter().rev()),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl<'a> LoadContext<'a> {
/// load_context.add_loaded_labeled_asset(label, loaded_asset);
/// }
/// ```
pub fn begin_labeled_asset(&self) -> LoadContext {
pub fn begin_labeled_asset(&self) -> LoadContext<'_> {
LoadContext::new(
self.asset_server,
self.asset_path.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl<'a> AssetPath<'a> {
/// Gets the "asset source", if one was defined. If none was defined, the default source
/// will be used.
#[inline]
pub fn source(&self) -> &AssetSourceId {
pub fn source(&self) -> &AssetSourceId<'_> {
&self.source
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/saver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'a, A: Asset> SavedAsset<'a, A> {
}

/// Returns the labeled asset, if it exists and matches this type.
pub fn get_labeled<B: Asset, Q>(&self, label: &Q) -> Option<SavedAsset<B>>
pub fn get_labeled<B: Asset, Q>(&self, label: &Q) -> Option<SavedAsset<'_, B>>
where
CowArc<'static, str>: Borrow<Q>,
Q: ?Sized + Hash + Eq,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ impl AssetServer {
}

/// Returns the path for the given `id`, if it has one.
pub fn get_path(&self, id: impl Into<UntypedAssetId>) -> Option<AssetPath> {
pub fn get_path(&self, id: impl Into<UntypedAssetId>) -> Option<AssetPath<'_>> {
let infos = self.data.infos.read();
let info = infos.get(id.into())?;
Some(info.path.as_ref()?.clone())
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_asset/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<A: Asset> TransformedAsset<A> {
&mut self.value
}
/// Returns the labeled asset, if it exists and matches this type.
pub fn get_labeled<B: Asset, Q>(&mut self, label: &Q) -> Option<TransformedSubAsset<B>>
pub fn get_labeled<B: Asset, Q>(&mut self, label: &Q) -> Option<TransformedSubAsset<'_, B>>
where
CowArc<'static, str>: Borrow<Q>,
Q: ?Sized + Hash + Eq,
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<'a, A: Asset> TransformedSubAsset<'a, A> {
self.value
}
/// Returns the labeled asset, if it exists and matches this type.
pub fn get_labeled<B: Asset, Q>(&mut self, label: &Q) -> Option<TransformedSubAsset<B>>
pub fn get_labeled<B: Asset, Q>(&mut self, label: &Q) -> Option<TransformedSubAsset<'_, B>>
where
CowArc<'static, str>: Borrow<Q>,
Q: ?Sized + Hash + Eq,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ impl<'w> MutUntyped<'w> {
/// Returns a [`MutUntyped`] with a smaller lifetime.
/// This is useful if you have `&mut MutUntyped`, but you need a `MutUntyped`.
#[inline]
pub fn reborrow(&mut self) -> MutUntyped {
pub fn reborrow(&mut self) -> MutUntyped<'_> {
MutUntyped {
value: self.value.reborrow(),
ticks: TicksMut {
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/entity/clone_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ impl EntityCloner {
/// explicitly denied, for example by using the [`deny`](EntityClonerBuilder<OptOut>::deny) method.
///
/// Required components are not considered by denied components and must be explicitly denied as well if desired.
pub fn build_opt_out(world: &mut World) -> EntityClonerBuilder<OptOut> {
pub fn build_opt_out(world: &mut World) -> EntityClonerBuilder<'_, OptOut> {
EntityClonerBuilder {
world,
filter: Default::default(),
Expand All @@ -461,7 +461,7 @@ impl EntityCloner {
/// Components allowed to be cloned through this builder would also allow their required components,
/// which will be cloned from the source entity only if the target entity does not contain them already.
/// To skip adding required components see [`without_required_components`](EntityClonerBuilder<OptIn>::without_required_components).
pub fn build_opt_in(world: &mut World) -> EntityClonerBuilder<OptIn> {
pub fn build_opt_in(world: &mut World) -> EntityClonerBuilder<'_, OptIn> {
EntityClonerBuilder {
world,
filter: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ impl Entities {
clippy::unnecessary_fallible_conversions,
reason = "`IdCursor::try_from` may fail on 32-bit platforms."
)]
pub fn reserve_entities(&self, count: u32) -> ReserveEntitiesIterator {
pub fn reserve_entities(&self, count: u32) -> ReserveEntitiesIterator<'_> {
// Use one atomic subtract to grab a range of new IDs. The range might be
// entirely nonnegative, meaning all IDs come from the freelist, or entirely
// negative, meaning they are all new IDs to allocate, or a mix of both.
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl World {
pub fn add_observer<E: Event, B: Bundle, M>(
&mut self,
system: impl IntoObserverSystem<E, B, M>,
) -> EntityWorldMut {
) -> EntityWorldMut<'_> {
self.spawn(Observer::new(system))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/observer/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'w, E, B: Bundle> On<'w, E, B> {
}

/// Returns a pointer to the triggered event.
pub fn event_ptr(&self) -> Ptr {
pub fn event_ptr(&self) -> Ptr<'_> {
Ptr::from(&self.event)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/relationship/related_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ impl<'w, R: Relationship> RelatedSpawnerCommands<'w, R> {
}

/// Returns the underlying [`Commands`].
pub fn commands(&mut self) -> Commands {
pub fn commands(&mut self) -> Commands<'_, '_> {
self.commands.reborrow()
}

Expand Down
18 changes: 9 additions & 9 deletions crates/bevy_ecs/src/system/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl<'w, 's> Commands<'w, 's> {
/// - [`spawn_batch`](Self::spawn_batch) to spawn many entities
/// with the same combination of components.
#[track_caller]
pub fn spawn_empty(&mut self) -> EntityCommands {
pub fn spawn_empty(&mut self) -> EntityCommands<'_> {
let entity = self.entities.reserve_entity();
let mut entity_commands = EntityCommands {
entity,
Expand Down Expand Up @@ -375,7 +375,7 @@ impl<'w, 's> Commands<'w, 's> {
/// - [`spawn_batch`](Self::spawn_batch) to spawn many entities
/// with the same combination of components.
#[track_caller]
pub fn spawn<T: Bundle>(&mut self, bundle: T) -> EntityCommands {
pub fn spawn<T: Bundle>(&mut self, bundle: T) -> EntityCommands<'_> {
let entity = self.entities.reserve_entity();
let mut entity_commands = EntityCommands {
entity,
Expand Down Expand Up @@ -436,7 +436,7 @@ impl<'w, 's> Commands<'w, 's> {
/// - [`get_entity`](Self::get_entity) for the fallible version.
#[inline]
#[track_caller]
pub fn entity(&mut self, entity: Entity) -> EntityCommands {
pub fn entity(&mut self, entity: Entity) -> EntityCommands<'_> {
EntityCommands {
entity,
commands: self.reborrow(),
Expand Down Expand Up @@ -487,7 +487,7 @@ impl<'w, 's> Commands<'w, 's> {
pub fn get_entity(
&mut self,
entity: Entity,
) -> Result<EntityCommands, EntityDoesNotExistError> {
) -> Result<EntityCommands<'_>, EntityDoesNotExistError> {
if self.entities.contains(entity) {
Ok(EntityCommands {
entity,
Expand Down Expand Up @@ -1120,7 +1120,7 @@ impl<'w, 's> Commands<'w, 's> {
pub fn add_observer<E: Event, B: Bundle, M>(
&mut self,
observer: impl IntoObserverSystem<E, B, M>,
) -> EntityCommands {
) -> EntityCommands<'_> {
self.spawn(Observer::new(observer))
}

Expand Down Expand Up @@ -1269,7 +1269,7 @@ impl<'a> EntityCommands<'a> {
/// Returns an [`EntityCommands`] with a smaller lifetime.
///
/// This is useful if you have `&mut EntityCommands` but you need `EntityCommands`.
pub fn reborrow(&mut self) -> EntityCommands {
pub fn reborrow(&mut self) -> EntityCommands<'_> {
EntityCommands {
entity: self.entity,
commands: self.commands.reborrow(),
Expand Down Expand Up @@ -1319,7 +1319,7 @@ impl<'a> EntityCommands<'a> {
///
/// # bevy_ecs::system::assert_is_system(level_up_system);
/// ```
pub fn entry<T: Component>(&mut self) -> EntityEntryCommands<T> {
pub fn entry<T: Component>(&mut self) -> EntityEntryCommands<'_, T> {
EntityEntryCommands {
entity_commands: self.reborrow(),
marker: PhantomData,
Expand Down Expand Up @@ -1982,7 +1982,7 @@ impl<'a> EntityCommands<'a> {
}

/// Returns the underlying [`Commands`].
pub fn commands(&mut self) -> Commands {
pub fn commands(&mut self) -> Commands<'_, '_> {
self.commands.reborrow()
}

Expand Down Expand Up @@ -2381,7 +2381,7 @@ impl<'a, T: Component> EntityEntryCommands<'a, T> {
/// }
/// # bevy_ecs::system::assert_is_system(level_up_system);
/// ```
pub fn entity(&mut self) -> EntityCommands {
pub fn entity(&mut self) -> EntityCommands<'_> {
self.entity_commands.reborrow()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ impl<'a, T: SystemBuffer> DerefMut for Deferred<'a, T> {
impl<T: SystemBuffer> Deferred<'_, T> {
/// Returns a [`Deferred<T>`] with a smaller lifetime.
/// This is useful if you have `&mut Deferred<T>` but need `Deferred<T>`.
pub fn reborrow(&mut self) -> Deferred<T> {
pub fn reborrow(&mut self) -> Deferred<'_, T> {
Deferred(self.0)
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/world/deferred_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ impl<'w> From<&'w mut World> for DeferredWorld<'w> {
impl<'w> DeferredWorld<'w> {
/// Reborrow self as a new instance of [`DeferredWorld`]
#[inline]
pub fn reborrow(&mut self) -> DeferredWorld {
pub fn reborrow(&mut self) -> DeferredWorld<'_> {
DeferredWorld { world: self.world }
}

/// Creates a [`Commands`] instance that pushes to the world's command queue
#[inline]
pub fn commands(&mut self) -> Commands {
pub fn commands(&mut self) -> Commands<'_, '_> {
// SAFETY: &mut self ensure that there are no outstanding accesses to the queue
let command_queue = unsafe { self.world.get_raw_command_queue() };
// SAFETY: command_queue is stored on world and always valid while the world exists
Expand All @@ -81,7 +81,7 @@ impl<'w> DeferredWorld<'w> {
pub fn get_mut<T: Component<Mutability = Mutable>>(
&mut self,
entity: Entity,
) -> Option<Mut<T>> {
) -> Option<Mut<'_, T>> {
self.get_entity_mut(entity).ok()?.into_mut()
}

Expand Down Expand Up @@ -418,7 +418,7 @@ impl<'w> DeferredWorld<'w> {
/// # assert_eq!(_world.get::<TargetedBy>(e1).unwrap().0, eid);
/// # assert_eq!(_world.get::<TargetedBy>(e2).unwrap().0, eid);
/// ```
pub fn entities_and_commands(&mut self) -> (EntityFetcher, Commands) {
pub fn entities_and_commands(&mut self) -> (EntityFetcher<'_>, Commands<'_, '_>) {
let cell = self.as_unsafe_world_cell();
// SAFETY: `&mut self` gives mutable access to the entire world, and prevents simultaneous access.
let fetcher = unsafe { EntityFetcher::new(cell) };
Expand Down Expand Up @@ -887,7 +887,7 @@ impl<'w> DeferredWorld<'w> {
/// # Safety
/// - must only be used to make non-structural ECS changes
#[inline]
pub(crate) fn as_unsafe_world_cell(&mut self) -> UnsafeWorldCell {
pub(crate) fn as_unsafe_world_cell(&mut self) -> UnsafeWorldCell<'_> {
self.world
}
}
Loading
Loading