chore: Fix some violations of 'needless_pass_by_ref_mut' lint (#18795)
While this lint is allow-by-default, it seems pretty useful to get rid of mutable borrows when they're not needed. Closes #ISSUE Release Notes: - N/A
This commit is contained in:
parent
59f0f4ac42
commit
03c84466c2
36 changed files with 158 additions and 204 deletions
|
@ -622,7 +622,7 @@ impl Worktree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn root_file(&self, cx: &mut ModelContext<Self>) -> Option<Arc<File>> {
|
||||
pub fn root_file(&self, cx: &ModelContext<Self>) -> Option<Arc<File>> {
|
||||
let entry = self.root_entry()?;
|
||||
Some(File::for_entry(entry.clone(), cx.handle()))
|
||||
}
|
||||
|
@ -630,7 +630,7 @@ impl Worktree {
|
|||
pub fn observe_updates<F, Fut>(
|
||||
&mut self,
|
||||
project_id: u64,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
callback: F,
|
||||
) where
|
||||
F: 'static + Send + Fn(proto::UpdateWorktree) -> Fut,
|
||||
|
@ -661,11 +661,7 @@ impl Worktree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn load_file(
|
||||
&self,
|
||||
path: &Path,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
) -> Task<Result<LoadedFile>> {
|
||||
pub fn load_file(&self, path: &Path, cx: &ModelContext<Worktree>) -> Task<Result<LoadedFile>> {
|
||||
match self {
|
||||
Worktree::Local(this) => this.load_file(path, cx),
|
||||
Worktree::Remote(_) => {
|
||||
|
@ -679,7 +675,7 @@ impl Worktree {
|
|||
path: &Path,
|
||||
text: Rope,
|
||||
line_ending: LineEnding,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<Arc<File>>> {
|
||||
match self {
|
||||
Worktree::Local(this) => this.write_file(path, text, line_ending, cx),
|
||||
|
@ -693,7 +689,7 @@ impl Worktree {
|
|||
&mut self,
|
||||
path: impl Into<Arc<Path>>,
|
||||
is_directory: bool,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<CreatedEntry>> {
|
||||
let path = path.into();
|
||||
let worktree_id = self.id();
|
||||
|
@ -773,7 +769,7 @@ impl Worktree {
|
|||
&mut self,
|
||||
entry_id: ProjectEntryId,
|
||||
new_path: impl Into<Arc<Path>>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &ModelContext<Self>,
|
||||
) -> Task<Result<CreatedEntry>> {
|
||||
let new_path = new_path.into();
|
||||
match self {
|
||||
|
@ -787,7 +783,7 @@ impl Worktree {
|
|||
entry_id: ProjectEntryId,
|
||||
relative_worktree_source_path: Option<PathBuf>,
|
||||
new_path: impl Into<Arc<Path>>,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &ModelContext<Self>,
|
||||
) -> Task<Result<Option<Entry>>> {
|
||||
let new_path = new_path.into();
|
||||
match self {
|
||||
|
@ -830,7 +826,7 @@ impl Worktree {
|
|||
target_directory: PathBuf,
|
||||
paths: Vec<Arc<Path>>,
|
||||
overwrite_existing_files: bool,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<Vec<ProjectEntryId>>> {
|
||||
match self {
|
||||
Worktree::Local(this) => {
|
||||
|
@ -845,7 +841,7 @@ impl Worktree {
|
|||
pub fn expand_entry(
|
||||
&mut self,
|
||||
entry_id: ProjectEntryId,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
match self {
|
||||
Worktree::Local(this) => this.expand_entry(entry_id, cx),
|
||||
|
@ -987,7 +983,7 @@ impl LocalWorktree {
|
|||
!self.share_private_files && self.settings.is_path_private(path)
|
||||
}
|
||||
|
||||
fn restart_background_scanners(&mut self, cx: &mut ModelContext<Worktree>) {
|
||||
fn restart_background_scanners(&mut self, cx: &ModelContext<Worktree>) {
|
||||
let (scan_requests_tx, scan_requests_rx) = channel::unbounded();
|
||||
let (path_prefixes_to_scan_tx, path_prefixes_to_scan_rx) = channel::unbounded();
|
||||
self.scan_requests_tx = scan_requests_tx;
|
||||
|
@ -999,7 +995,7 @@ impl LocalWorktree {
|
|||
&mut self,
|
||||
scan_requests_rx: channel::Receiver<ScanRequest>,
|
||||
path_prefixes_to_scan_rx: channel::Receiver<Arc<Path>>,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) {
|
||||
let snapshot = self.snapshot();
|
||||
let share_private_files = self.share_private_files;
|
||||
|
@ -1236,7 +1232,7 @@ impl LocalWorktree {
|
|||
self.git_repositories.get(&repo.work_directory.0)
|
||||
}
|
||||
|
||||
fn load_file(&self, path: &Path, cx: &mut ModelContext<Worktree>) -> Task<Result<LoadedFile>> {
|
||||
fn load_file(&self, path: &Path, cx: &ModelContext<Worktree>) -> Task<Result<LoadedFile>> {
|
||||
let path = Arc::from(path);
|
||||
let abs_path = self.absolutize(&path);
|
||||
let fs = self.fs.clone();
|
||||
|
@ -1318,7 +1314,7 @@ impl LocalWorktree {
|
|||
&self,
|
||||
path: impl Into<Arc<Path>>,
|
||||
is_dir: bool,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<CreatedEntry>> {
|
||||
let path = path.into();
|
||||
let abs_path = match self.absolutize(&path) {
|
||||
|
@ -1383,7 +1379,7 @@ impl LocalWorktree {
|
|||
path: impl Into<Arc<Path>>,
|
||||
text: Rope,
|
||||
line_ending: LineEnding,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<Arc<File>>> {
|
||||
let path = path.into();
|
||||
let fs = self.fs.clone();
|
||||
|
@ -1437,7 +1433,7 @@ impl LocalWorktree {
|
|||
&self,
|
||||
entry_id: ProjectEntryId,
|
||||
trash: bool,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
let entry = self.entry_for_id(entry_id)?.clone();
|
||||
let abs_path = self.absolutize(&entry.path);
|
||||
|
@ -1489,7 +1485,7 @@ impl LocalWorktree {
|
|||
&self,
|
||||
entry_id: ProjectEntryId,
|
||||
new_path: impl Into<Arc<Path>>,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<CreatedEntry>> {
|
||||
let old_path = match self.entry_for_id(entry_id) {
|
||||
Some(entry) => entry.path.clone(),
|
||||
|
@ -1547,7 +1543,7 @@ impl LocalWorktree {
|
|||
entry_id: ProjectEntryId,
|
||||
relative_worktree_source_path: Option<PathBuf>,
|
||||
new_path: impl Into<Arc<Path>>,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<Option<Entry>>> {
|
||||
let old_path = match self.entry_for_id(entry_id) {
|
||||
Some(entry) => entry.path.clone(),
|
||||
|
@ -1584,11 +1580,11 @@ impl LocalWorktree {
|
|||
}
|
||||
|
||||
pub fn copy_external_entries(
|
||||
&mut self,
|
||||
&self,
|
||||
target_directory: PathBuf,
|
||||
paths: Vec<Arc<Path>>,
|
||||
overwrite_existing_files: bool,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<Vec<ProjectEntryId>>> {
|
||||
let worktree_path = self.abs_path().clone();
|
||||
let fs = self.fs.clone();
|
||||
|
@ -1665,9 +1661,9 @@ impl LocalWorktree {
|
|||
}
|
||||
|
||||
fn expand_entry(
|
||||
&mut self,
|
||||
&self,
|
||||
entry_id: ProjectEntryId,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
let path = self.entry_for_id(entry_id)?.path.clone();
|
||||
let mut refresh = self.refresh_entries_for_paths(vec![path]);
|
||||
|
@ -1696,7 +1692,7 @@ impl LocalWorktree {
|
|||
&self,
|
||||
path: Arc<Path>,
|
||||
old_path: Option<Arc<Path>>,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<Option<Entry>>> {
|
||||
if self.settings.is_path_excluded(&path) {
|
||||
return Task::ready(Ok(None));
|
||||
|
@ -1720,12 +1716,8 @@ impl LocalWorktree {
|
|||
})
|
||||
}
|
||||
|
||||
fn observe_updates<F, Fut>(
|
||||
&mut self,
|
||||
project_id: u64,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
callback: F,
|
||||
) where
|
||||
fn observe_updates<F, Fut>(&mut self, project_id: u64, cx: &ModelContext<Worktree>, callback: F)
|
||||
where
|
||||
F: 'static + Send + Fn(proto::UpdateWorktree) -> Fut,
|
||||
Fut: Send + Future<Output = bool>,
|
||||
{
|
||||
|
@ -1784,7 +1776,7 @@ impl LocalWorktree {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn share_private_files(&mut self, cx: &mut ModelContext<Worktree>) {
|
||||
pub fn share_private_files(&mut self, cx: &ModelContext<Worktree>) {
|
||||
self.share_private_files = true;
|
||||
self.restart_background_scanners(cx);
|
||||
}
|
||||
|
@ -1805,7 +1797,7 @@ impl RemoteWorktree {
|
|||
self.disconnected = true;
|
||||
}
|
||||
|
||||
pub fn update_from_remote(&mut self, update: proto::UpdateWorktree) {
|
||||
pub fn update_from_remote(&self, update: proto::UpdateWorktree) {
|
||||
if let Some(updates_tx) = &self.updates_tx {
|
||||
updates_tx
|
||||
.unbounded_send(update)
|
||||
|
@ -1813,12 +1805,8 @@ impl RemoteWorktree {
|
|||
}
|
||||
}
|
||||
|
||||
fn observe_updates<F, Fut>(
|
||||
&mut self,
|
||||
project_id: u64,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
callback: F,
|
||||
) where
|
||||
fn observe_updates<F, Fut>(&mut self, project_id: u64, cx: &ModelContext<Worktree>, callback: F)
|
||||
where
|
||||
F: 'static + Send + Fn(proto::UpdateWorktree) -> Fut,
|
||||
Fut: 'static + Send + Future<Output = bool>,
|
||||
{
|
||||
|
@ -1879,7 +1867,7 @@ impl RemoteWorktree {
|
|||
&mut self,
|
||||
entry: proto::Entry,
|
||||
scan_id: usize,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<Entry>> {
|
||||
let wait_for_snapshot = self.wait_for_snapshot(scan_id);
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
|
@ -1895,10 +1883,10 @@ impl RemoteWorktree {
|
|||
}
|
||||
|
||||
fn delete_entry(
|
||||
&mut self,
|
||||
&self,
|
||||
entry_id: ProjectEntryId,
|
||||
trash: bool,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
let response = self.client.request(proto::DeleteProjectEntry {
|
||||
project_id: self.project_id,
|
||||
|
@ -1924,10 +1912,10 @@ impl RemoteWorktree {
|
|||
}
|
||||
|
||||
fn rename_entry(
|
||||
&mut self,
|
||||
&self,
|
||||
entry_id: ProjectEntryId,
|
||||
new_path: impl Into<Arc<Path>>,
|
||||
cx: &mut ModelContext<Worktree>,
|
||||
cx: &ModelContext<Worktree>,
|
||||
) -> Task<Result<CreatedEntry>> {
|
||||
let new_path = new_path.into();
|
||||
let response = self.client.request(proto::RenameProjectEntry {
|
||||
|
@ -3692,7 +3680,7 @@ impl BackgroundScanner {
|
|||
self.send_status_update(scanning, request.done)
|
||||
}
|
||||
|
||||
async fn process_events(&mut self, mut abs_paths: Vec<PathBuf>) {
|
||||
async fn process_events(&self, mut abs_paths: Vec<PathBuf>) {
|
||||
let root_path = self.state.lock().snapshot.abs_path.clone();
|
||||
let root_canonical_path = match self.fs.canonicalize(&root_path).await {
|
||||
Ok(path) => path,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue