Skip to content

Commit

Permalink
Fix needless_borrow warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sgued authored and Keats committed Feb 16, 2023
1 parent 02b57b9 commit 3430d94
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions components/content/src/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl FileInfo {
let name = path.file_stem().unwrap().to_string_lossy().to_string();
let canonical = parent.join(&name);
let mut components =
find_content_components(&file_path.strip_prefix(base_path).unwrap_or(&file_path));
find_content_components(file_path.strip_prefix(base_path).unwrap_or(&file_path));
let relative = if !components.is_empty() {
format!("{}/{}.md", components.join("/"), name)
} else {
Expand Down Expand Up @@ -91,7 +91,7 @@ impl FileInfo {
let parent = path.parent().expect("Get parent of section").to_path_buf();
let name = path.file_stem().unwrap().to_string_lossy().to_string();
let components =
find_content_components(&file_path.strip_prefix(base_path).unwrap_or(&file_path));
find_content_components(file_path.strip_prefix(base_path).unwrap_or(&file_path));
let relative = if !components.is_empty() {
format!("{}/{}.md", components.join("/"), name)
} else {
Expand Down
4 changes: 2 additions & 2 deletions components/content/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl Library {
for (path, page) in self.pages.iter_mut() {
let parent_filename = &index_filename_by_lang[&page.lang];
add_translation(&page.file.canonical, path);
let mut parent_section_path = page.file.parent.join(&parent_filename);
let mut parent_section_path = page.file.parent.join(parent_filename);

while let Some(parent_section) = self.sections.get_mut(&parent_section_path) {
let is_transparent = parent_section.meta.transparent;
Expand Down Expand Up @@ -323,7 +323,7 @@ impl Library {

// We've added `_index(.{LANG})?.md` so if we are here so we need to go up twice
match parent_section_path.clone().parent().unwrap().parent() {
Some(parent) => parent_section_path = parent.join(&parent_filename),
Some(parent) => parent_section_path = parent.join(parent_filename),
None => break,
}
}
Expand Down
6 changes: 4 additions & 2 deletions components/content/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ static RFC3339_DATE: Lazy<Regex> = Lazy::new(|| {
).unwrap()
});

static FOOTNOTES_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r#"<sup class="footnote-reference"><a href=\s*.*?>\s*.*?</a></sup>"#).unwrap());
static FOOTNOTES_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r#"<sup class="footnote-reference"><a href=\s*.*?>\s*.*?</a></sup>"#).unwrap()
});

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Page {
Expand Down Expand Up @@ -260,7 +262,7 @@ impl Page {
fn serialize_assets(&self, base_path: &Path) -> Vec<String> {
self.assets
.iter()
.filter_map(|asset| asset.strip_prefix(&self.file.path.parent().unwrap()).ok())
.filter_map(|asset| asset.strip_prefix(self.file.path.parent().unwrap()).ok())
.filter_map(|filename| filename.to_str())
.map(|filename| {
let mut path = self.file.path.clone();
Expand Down
2 changes: 1 addition & 1 deletion components/content/src/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'a> Paginator<'a> {
} else {
paginator.insert("next", Value::Null);
}
paginator.insert("number_pagers", to_value(&self.pagers.len()).unwrap());
paginator.insert("number_pagers", to_value(self.pagers.len()).unwrap());
let base_url = if self.paginate_path.is_empty() {
self.permalink.to_string()
} else {
Expand Down
2 changes: 1 addition & 1 deletion components/content/src/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl Section {
fn serialize_assets(&self) -> Vec<String> {
self.assets
.iter()
.filter_map(|asset| asset.strip_prefix(&self.file.path.parent().unwrap()).ok())
.filter_map(|asset| asset.strip_prefix(self.file.path.parent().unwrap()).ok())
.filter_map(|filename| filename.to_str())
.map(|filename| format!("{}{}", self.path, filename))
.collect()
Expand Down
2 changes: 1 addition & 1 deletion components/imageproc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ pub fn read_image_metadata<P: AsRef<Path>>(path: P) -> Result<ImageMetaResponse>

match ext.as_str() {
"svg" => {
let img = SvgMetadata::parse_file(&path).with_context(err_context)?;
let img = SvgMetadata::parse_file(path).with_context(err_context)?;
match (img.height(), img.width(), img.view_box()) {
(Some(h), Some(w), _) => Ok((h, w)),
(_, _, Some(view_box)) => Ok((view_box.height, view_box.width)),
Expand Down
6 changes: 3 additions & 3 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Site {
// if we are processing a section we have to collect
// index files for all languages and process them simultaneously
// before any of the pages
let index_files = WalkDir::new(&path)
let index_files = WalkDir::new(path)
.follow_links(true)
.max_depth(1)
.into_iter()
Expand Down Expand Up @@ -664,7 +664,7 @@ impl Site {
asset_path,
&current_path.join(
asset_path
.strip_prefix(&page.file.path.parent().unwrap())
.strip_prefix(page.file.path.parent().unwrap())
.expect("Couldn't get filename from page asset"),
),
)?;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ impl Site {
asset_path,
&output_path.join(
asset_path
.strip_prefix(&section.file.path.parent().unwrap())
.strip_prefix(section.file.path.parent().unwrap())
.expect("Failed to get asset filename for section"),
),
)?;
Expand Down
4 changes: 2 additions & 2 deletions components/site/src/sass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ fn compile_sass_glob(
for file in files {
let css = compile_file(&file, options.clone()).map_err(|e| anyhow!(e))?;

let path_inside_sass = file.strip_prefix(&sass_path).unwrap();
let path_inside_sass = file.strip_prefix(sass_path).unwrap();
let parent_inside_sass = path_inside_sass.parent();
let css_output_path = output_path.join(path_inside_sass).with_extension("css");

if parent_inside_sass.is_some() {
create_dir_all(&css_output_path.parent().unwrap())?;
create_dir_all(css_output_path.parent().unwrap())?;
}

create_file(&css_output_path, &css)?;
Expand Down
2 changes: 1 addition & 1 deletion components/templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn load_tera(path: &Path, config: &Config) -> Result<Tera> {

if let Some(ref theme) = config.theme {
// Test that the templates folder exist for that theme
let theme_path = path.join("themes").join(&theme);
let theme_path = path.join("themes").join(theme);
if !theme_path.join("templates").exists() {
bail!("Theme `{}` is missing a templates folder", theme);
}
Expand Down
12 changes: 6 additions & 6 deletions components/utils/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn is_path_in_directory(parent: &Path, path: &Path) -> Result<bool> {
/// Create a file with the content given
pub fn create_file(path: &Path, content: &str) -> Result<()> {
let mut file =
File::create(&path).with_context(|| format!("Failed to create file {}", path.display()))?;
File::create(path).with_context(|| format!("Failed to create file {}", path.display()))?;
file.write_all(content.as_bytes())?;
Ok(())
}
Expand Down Expand Up @@ -92,19 +92,19 @@ pub fn copy_file_if_needed(src: &Path, dest: &Path, hard_link: bool) -> Result<(
.with_context(|| format!("Failed to get metadata of {}", src.display()))?;
let src_mtime = FileTime::from_last_modification_time(&src_metadata);
if Path::new(&dest).is_file() {
let target_metadata = metadata(&dest)?;
let target_metadata = metadata(dest)?;
let target_mtime = FileTime::from_last_modification_time(&target_metadata);
if !(src_mtime == target_mtime && src_metadata.len() == target_metadata.len()) {
copy(src, &dest).with_context(|| {
copy(src, dest).with_context(|| {
format!("Was not able to copy file {} to {}", src.display(), dest.display())
})?;
set_file_mtime(&dest, src_mtime)?;
set_file_mtime(dest, src_mtime)?;
}
} else {
copy(src, &dest).with_context(|| {
copy(src, dest).with_context(|| {
format!("Was not able to copy directory {} to {}", src.display(), dest.display())
})?;
set_file_mtime(&dest, src_mtime)?;
set_file_mtime(dest, src_mtime)?;
}
}
Ok(())
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,12 @@ pub fn serve(
Ok(a) => a,
Err(_) => return Err(anyhow!("Invalid address: {}.", address)),
};
if (TcpListener::bind(&bind_address)).is_err() {
if (TcpListener::bind(bind_address)).is_err() {
return Err(anyhow!("Cannot start server on address {}.", address));
}

let config_path = PathBuf::from(config_file);
let config_path_rel =
diff_paths(&config_path, &root_dir).unwrap_or_else(|| config_path.clone());
let config_path_rel = diff_paths(&config_path, root_dir).unwrap_or_else(|| config_path.clone());

// An array of (path, WatchMode) where the path should be watched for changes,
// and the WatchMode value indicates whether this file/folder must exist for
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ mod prompt;
fn get_config_file_path(dir: &Path, config_path: &Path) -> (PathBuf, PathBuf) {
let root_dir = dir
.ancestors()
.find(|a| a.join(&config_path).exists())
.find(|a| a.join(config_path).exists())
.unwrap_or_else(|| panic!("could not find directory containing config file"));

// if we got here we found root_dir so config file should exist so we can unwrap safely
let config_file = root_dir
.join(&config_path)
.join(config_path)
.canonicalize()
.unwrap_or_else(|_| panic!("could not find directory containing config file"));
(root_dir.to_path_buf(), config_file)
Expand Down

0 comments on commit 3430d94

Please sign in to comment.