Enable clippy::needless_lifetimes (#8777)

This PR enables the
[`clippy::needless_lifetimes`](https://rust-lang.github.io/rust-clippy/master/index.html#/needless_lifetimes)
rule and fixes the outstanding violations.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-03-03 11:52:58 -05:00 committed by GitHub
parent 1fa9496334
commit 53630dc74c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 67 additions and 78 deletions

View file

@ -97,9 +97,9 @@ impl<'a> Drop for ChannelPathsInsertGuard<'a> {
}
}
fn channel_path_sorting_key<'a>(
fn channel_path_sorting_key(
id: ChannelId,
channels_by_id: &'a BTreeMap<ChannelId, Arc<Channel>>,
channels_by_id: &BTreeMap<ChannelId, Arc<Channel>>,
) -> impl Iterator<Item = (&str, ChannelId)> {
let (parent_path, name) = channels_by_id
.get(&id)

View file

@ -138,7 +138,7 @@ impl TestServer {
(server, client_a, client_b, channel_id)
}
pub async fn start1<'a>(cx: &'a mut TestAppContext) -> TestClient {
pub async fn start1(cx: &mut TestAppContext) -> TestClient {
let mut server = Self::start(cx.executor().clone()).await;
server.create_client(cx, "user_a").await
}
@ -589,19 +589,19 @@ impl TestClient {
.await;
}
pub fn local_projects<'a>(&'a self) -> impl Deref<Target = Vec<Model<Project>>> + 'a {
pub fn local_projects(&self) -> impl Deref<Target = Vec<Model<Project>>> + '_ {
Ref::map(self.state.borrow(), |state| &state.local_projects)
}
pub fn remote_projects<'a>(&'a self) -> impl Deref<Target = Vec<Model<Project>>> + 'a {
pub fn remote_projects(&self) -> impl Deref<Target = Vec<Model<Project>>> + '_ {
Ref::map(self.state.borrow(), |state| &state.remote_projects)
}
pub fn local_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<Model<Project>>> + 'a {
pub fn local_projects_mut(&self) -> impl DerefMut<Target = Vec<Model<Project>>> + '_ {
RefMut::map(self.state.borrow_mut(), |state| &mut state.local_projects)
}
pub fn remote_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<Model<Project>>> + 'a {
pub fn remote_projects_mut(&self) -> impl DerefMut<Target = Vec<Model<Project>>> + '_ {
RefMut::map(self.state.borrow_mut(), |state| &mut state.remote_projects)
}
@ -614,16 +614,14 @@ impl TestClient {
})
}
pub fn buffers<'a>(
&'a self,
) -> impl DerefMut<Target = HashMap<Model<Project>, HashSet<Model<language::Buffer>>>> + 'a
pub fn buffers(
&self,
) -> impl DerefMut<Target = HashMap<Model<Project>, HashSet<Model<language::Buffer>>>> + '_
{
RefMut::map(self.state.borrow_mut(), |state| &mut state.buffers)
}
pub fn channel_buffers<'a>(
&'a self,
) -> impl DerefMut<Target = HashSet<Model<ChannelBuffer>>> + 'a {
pub fn channel_buffers(&self) -> impl DerefMut<Target = HashSet<Model<ChannelBuffer>>> + '_ {
RefMut::map(self.state.borrow_mut(), |state| &mut state.channel_buffers)
}

View file

@ -512,13 +512,13 @@ impl DisplaySnapshot {
})
}
pub fn chunks<'a>(
&'a self,
pub fn chunks(
&self,
display_rows: Range<u32>,
language_aware: bool,
inlay_highlight_style: Option<HighlightStyle>,
suggestion_highlight_style: Option<HighlightStyle>,
) -> DisplayChunks<'a> {
) -> DisplayChunks<'_> {
self.block_snapshot.chunks(
display_rows,
language_aware,
@ -1826,10 +1826,10 @@ pub mod tests {
)
}
fn syntax_chunks<'a>(
fn syntax_chunks(
rows: Range<u32>,
map: &Model<DisplayMap>,
theme: &'a SyntaxTheme,
theme: &SyntaxTheme,
cx: &mut AppContext,
) -> Vec<(String, Option<Hsla>)> {
chunks(rows, map, theme, cx)
@ -1838,10 +1838,10 @@ pub mod tests {
.collect()
}
fn chunks<'a>(
fn chunks(
rows: Range<u32>,
map: &Model<DisplayMap>,
theme: &'a SyntaxTheme,
theme: &SyntaxTheme,
cx: &mut AppContext,
) -> Vec<(String, Option<Hsla>, Option<Hsla>)> {
let snapshot = map.update(cx, |map, cx| map.snapshot(cx));

View file

@ -982,7 +982,7 @@ impl InlaySnapshot {
summary
}
pub fn buffer_rows<'a>(&'a self, row: u32) -> InlayBufferRows<'a> {
pub fn buffer_rows(&self, row: u32) -> InlayBufferRows<'_> {
let mut cursor = self.transforms.cursor::<(InlayPoint, Point)>();
let inlay_point = InlayPoint::new(row, 0);
cursor.seek(&inlay_point, Bias::Left, &());

View file

@ -1705,18 +1705,14 @@ impl Editor {
}
}
pub fn language_at<'a, T: ToOffset>(
&self,
point: T,
cx: &'a AppContext,
) -> Option<Arc<Language>> {
pub fn language_at<T: ToOffset>(&self, point: T, cx: &AppContext) -> Option<Arc<Language>> {
self.buffer.read(cx).language_at(point, cx)
}
pub fn file_at<'a, T: ToOffset>(
pub fn file_at<T: ToOffset>(
&self,
point: T,
cx: &'a AppContext,
cx: &AppContext,
) -> Option<Arc<dyn language::File>> {
self.buffer.read(cx).read(cx).file_at(point).cloned()
}
@ -10439,7 +10435,7 @@ pub fn styled_runs_for_code_label<'a>(
})
}
pub(crate) fn split_words<'a>(text: &'a str) -> impl std::iter::Iterator<Item = &'a str> + 'a {
pub(crate) fn split_words(text: &str) -> impl std::iter::Iterator<Item = &str> + '_ {
let mut index = 0;
let mut codepoints = text.char_indices().peekable();

View file

@ -7310,7 +7310,7 @@ async fn go_to_hunk(executor: BackgroundExecutor, cx: &mut gpui::TestAppContext)
#[test]
fn test_split_words() {
fn split<'a>(text: &'a str) -> Vec<&'a str> {
fn split(text: &str) -> Vec<&str> {
split_words(text).collect()
}

View file

@ -593,7 +593,7 @@ impl Item for Editor {
None
}
fn tab_description<'a>(&self, detail: usize, cx: &'a AppContext) -> Option<SharedString> {
fn tab_description(&self, detail: usize, cx: &AppContext) -> Option<SharedString> {
let path = path_for_buffer(&self.buffer, detail, true, cx)?;
Some(path.to_string_lossy().to_string().into())
}

View file

@ -208,8 +208,8 @@ impl BufferDiff {
}
}
fn process_patch_hunk<'a>(
patch: &GitPatch<'a>,
fn process_patch_hunk(
patch: &GitPatch<'_>,
hunk_index: usize,
buffer: &text::BufferSnapshot,
buffer_row_divergence: &mut i64,

View file

@ -2839,10 +2839,10 @@ impl BufferSnapshot {
}
/// Returns bracket range pairs overlapping or adjacent to `range`
pub fn bracket_ranges<'a, T: ToOffset>(
&'a self,
pub fn bracket_ranges<T: ToOffset>(
&self,
range: Range<T>,
) -> impl Iterator<Item = (Range<usize>, Range<usize>)> + 'a {
) -> impl Iterator<Item = (Range<usize>, Range<usize>)> + '_ {
// Find bracket pairs that *inclusively* contain the given range.
let range = range.start.to_offset(self).saturating_sub(1)
..self.len().min(range.end.to_offset(self) + 1);
@ -2935,10 +2935,10 @@ impl BufferSnapshot {
/// Returns anchor ranges for any matches of the redaction query.
/// The buffer can be associated with multiple languages, and the redaction query associated with each
/// will be run on the relevant section of the buffer.
pub fn redacted_ranges<'a, T: ToOffset>(
&'a self,
pub fn redacted_ranges<T: ToOffset>(
&self,
range: Range<T>,
) -> impl Iterator<Item = Range<usize>> + 'a {
) -> impl Iterator<Item = Range<usize>> + '_ {
let offset_range = range.start.to_offset(self)..range.end.to_offset(self);
let mut syntax_matches = self.syntax.matches(offset_range, self, |grammar| {
grammar
@ -3015,28 +3015,28 @@ impl BufferSnapshot {
/// Returns all the Git diff hunks intersecting the given
/// row range.
pub fn git_diff_hunks_in_row_range<'a>(
&'a self,
pub fn git_diff_hunks_in_row_range(
&self,
range: Range<u32>,
) -> impl 'a + Iterator<Item = git::diff::DiffHunk<u32>> {
) -> impl '_ + Iterator<Item = git::diff::DiffHunk<u32>> {
self.git_diff.hunks_in_row_range(range, self)
}
/// Returns all the Git diff hunks intersecting the given
/// range.
pub fn git_diff_hunks_intersecting_range<'a>(
&'a self,
pub fn git_diff_hunks_intersecting_range(
&self,
range: Range<Anchor>,
) -> impl 'a + Iterator<Item = git::diff::DiffHunk<u32>> {
) -> impl '_ + Iterator<Item = git::diff::DiffHunk<u32>> {
self.git_diff.hunks_intersecting_range(range, self)
}
/// Returns all the Git diff hunks intersecting the given
/// range, in reverse order.
pub fn git_diff_hunks_intersecting_range_rev<'a>(
&'a self,
pub fn git_diff_hunks_intersecting_range_rev(
&self,
range: Range<Anchor>,
) -> impl 'a + Iterator<Item = git::diff::DiffHunk<u32>> {
) -> impl '_ + Iterator<Item = git::diff::DiffHunk<u32>> {
self.git_diff.hunks_intersecting_range_rev(range, self)
}

View file

@ -1525,11 +1525,7 @@ impl MultiBuffer {
.unwrap_or(false)
}
pub fn language_at<'a, T: ToOffset>(
&self,
point: T,
cx: &'a AppContext,
) -> Option<Arc<Language>> {
pub fn language_at<T: ToOffset>(&self, point: T, cx: &AppContext) -> Option<Arc<Language>> {
self.point_to_buffer_offset(point, cx)
.and_then(|(buffer, offset, _)| buffer.read(cx).language_at(offset))
}
@ -2828,10 +2824,10 @@ impl MultiBufferSnapshot {
.map(|excerpt| (excerpt.id, &excerpt.buffer, excerpt.range.clone()))
}
fn excerpts_for_range<'a, T: ToOffset>(
&'a self,
fn excerpts_for_range<T: ToOffset>(
&self,
range: Range<T>,
) -> impl Iterator<Item = (&'a Excerpt, usize)> + 'a {
) -> impl Iterator<Item = (&Excerpt, usize)> + '_ {
let range = range.start.to_offset(self)..range.end.to_offset(self);
let mut cursor = self.excerpts.cursor::<usize>();
@ -2956,10 +2952,10 @@ impl MultiBufferSnapshot {
/// Returns enclosing bracket ranges containing the given range or returns None if the range is
/// not contained in a single excerpt
pub fn enclosing_bracket_ranges<'a, T: ToOffset>(
&'a self,
pub fn enclosing_bracket_ranges<T: ToOffset>(
&self,
range: Range<T>,
) -> Option<impl Iterator<Item = (Range<usize>, Range<usize>)> + 'a> {
) -> Option<impl Iterator<Item = (Range<usize>, Range<usize>)> + '_> {
let range = range.start.to_offset(self)..range.end.to_offset(self);
let excerpt = self.excerpt_containing(range.clone())?;
@ -2973,10 +2969,10 @@ impl MultiBufferSnapshot {
/// Returns bracket range pairs overlapping the given `range` or returns None if the `range` is
/// not contained in a single excerpt
pub fn bracket_ranges<'a, T: ToOffset>(
&'a self,
pub fn bracket_ranges<T: ToOffset>(
&self,
range: Range<T>,
) -> Option<impl Iterator<Item = (Range<usize>, Range<usize>)> + 'a> {
) -> Option<impl Iterator<Item = (Range<usize>, Range<usize>)> + '_> {
let range = range.start.to_offset(self)..range.end.to_offset(self);
let excerpt = self.excerpt_containing(range.clone())?;
@ -3041,12 +3037,12 @@ impl MultiBufferSnapshot {
self.trailing_excerpt_update_count
}
pub fn file_at<'a, T: ToOffset>(&'a self, point: T) -> Option<&'a Arc<dyn File>> {
pub fn file_at<T: ToOffset>(&self, point: T) -> Option<&Arc<dyn File>> {
self.point_to_buffer_offset(point)
.and_then(|(buffer, _)| buffer.file())
}
pub fn language_at<'a, T: ToOffset>(&'a self, point: T) -> Option<&'a Arc<Language>> {
pub fn language_at<T: ToOffset>(&self, point: T) -> Option<&Arc<Language>> {
self.point_to_buffer_offset(point)
.and_then(|(buffer, offset)| buffer.language_at(offset))
}
@ -3065,7 +3061,7 @@ impl MultiBufferSnapshot {
language_settings(language, file, cx)
}
pub fn language_scope_at<'a, T: ToOffset>(&'a self, point: T) -> Option<LanguageScope> {
pub fn language_scope_at<T: ToOffset>(&self, point: T) -> Option<LanguageScope> {
self.point_to_buffer_offset(point)
.and_then(|(buffer, offset)| buffer.language_scope_at(offset))
}
@ -3133,10 +3129,10 @@ impl MultiBufferSnapshot {
false
}
pub fn git_diff_hunks_in_range_rev<'a>(
&'a self,
pub fn git_diff_hunks_in_range_rev(
&self,
row_range: Range<u32>,
) -> impl 'a + Iterator<Item = DiffHunk<u32>> {
) -> impl Iterator<Item = DiffHunk<u32>> + '_ {
let mut cursor = self.excerpts.cursor::<Point>();
cursor.seek(&Point::new(row_range.end, 0), Bias::Left, &());
@ -3198,10 +3194,10 @@ impl MultiBufferSnapshot {
.flatten()
}
pub fn git_diff_hunks_in_range<'a>(
&'a self,
pub fn git_diff_hunks_in_range(
&self,
row_range: Range<u32>,
) -> impl 'a + Iterator<Item = DiffHunk<u32>> {
) -> impl Iterator<Item = DiffHunk<u32>> + '_ {
let mut cursor = self.excerpts.cursor::<Point>();
cursor.seek(&Point::new(row_range.start, 0), Bias::Right, &());
@ -3317,7 +3313,7 @@ impl MultiBufferSnapshot {
))
}
fn excerpt_locator_for_id<'a>(&'a self, id: ExcerptId) -> &'a Locator {
fn excerpt_locator_for_id(&self, id: ExcerptId) -> &Locator {
if id == ExcerptId::min() {
Locator::min_ref()
} else if id == ExcerptId::max() {
@ -3342,7 +3338,7 @@ impl MultiBufferSnapshot {
Some(&self.excerpt(excerpt_id)?.buffer)
}
fn excerpt<'a>(&'a self, excerpt_id: ExcerptId) -> Option<&'a Excerpt> {
fn excerpt(&self, excerpt_id: ExcerptId) -> Option<&Excerpt> {
let mut cursor = self.excerpts.cursor::<Option<&Locator>>();
let locator = self.excerpt_locator_for_id(excerpt_id);
cursor.seek(&Some(locator), Bias::Left, &());

View file

@ -1016,7 +1016,7 @@ impl Project {
}
/// Collect all worktrees, including ones that don't appear in the project panel
pub fn worktrees<'a>(&'a self) -> impl 'a + DoubleEndedIterator<Item = Model<Worktree>> {
pub fn worktrees(&self) -> impl '_ + DoubleEndedIterator<Item = Model<Worktree>> {
self.worktrees
.iter()
.filter_map(move |worktree| worktree.upgrade())
@ -9155,7 +9155,7 @@ fn subscribe_for_copilot_events(
)
}
fn glob_literal_prefix<'a>(glob: &'a str) -> &'a str {
fn glob_literal_prefix(glob: &str) -> &str {
let mut literal_end = 0;
for (i, part) in glob.split(path::MAIN_SEPARATOR).enumerate() {
if part.contains(&['*', '?', '{', '}']) {

View file

@ -2845,10 +2845,10 @@ mod tests {
))
}
#[track_caller]
fn assert_key_bindings_for<'a>(
fn assert_key_bindings_for(
window: AnyWindowHandle,
cx: &TestAppContext,
actions: Vec<(&'static str, &'a dyn Action)>,
actions: Vec<(&'static str, &dyn Action)>,
line: u32,
) {
let available_actions = cx

View file

@ -94,7 +94,6 @@ fn run_clippy(args: ClippyArgs) -> Result<()> {
"clippy::iter_overeager_cloned",
"clippy::let_underscore_future",
"clippy::map_entry",
"clippy::needless_lifetimes",
"clippy::needless_update",
"clippy::never_loop",
"clippy::non_canonical_clone_impl",