Skip to content

Commit

Permalink
*: clean up clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksa Sarai <[email protected]>
  • Loading branch information
cyphar committed Jan 1, 2020
1 parent 63382e0 commit 51d95fa
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 92 deletions.
82 changes: 82 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# libpathrs: safe path resolution on Linux
# Copyright (C) 2019, 2020 Aleksa Sarai <[email protected]>
# Copyright (C) 2019, 2020 SUSE LLC
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.

max_width = 100
hard_tabs = false
tab_spaces = 4
newline_style = "Auto"
use_small_heuristics = "Default"
indent_style = "Block"
wrap_comments = false
format_code_in_doc_comments = false
comment_width = 80
normalize_comments = false
normalize_doc_attributes = false
license_template_path = ""
format_strings = false
format_macro_matchers = false
format_macro_bodies = true
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
where_single_line = false
imports_indent = "Block"
imports_layout = "Mixed"
merge_imports = false
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
combine_control_expr = true
overflow_delimited_expr = false
struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
force_multiline_blocks = false
fn_args_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = true
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
edition = "2015"
version = "One"
inline_attribute_width = 0
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
required_version = "1.4.8"
unstable_features = false
disable_all_formatting = false
skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
report_todo = "Never"
report_fixme = "Never"
ignore = []
emit_mode = "Files"
make_backup = false
26 changes: 23 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,31 @@ rust:
- beta
- nightly

matrix:
include:
- name: "rust-fmt"
rust: 1.40.0
install:
- rustup component add rustfmt-preview
script:
- cargo fmt -- --check
- name: "rust-clippy"
rust: 1.40.0
install:
- rustup component add clippy-preview
script:
- cargo clippy --all-features -- -D clippy::all
- name: "rust-warn"
env: RUSTFLAGS="-D warnings"
rust: stable
script:
- cargo check --tests

jobs:
allow_failures:
- rust: nightly
fast_finish: true
- name: "rust-warn"

script:
- cargo build --verbose --all
- cargo test --verbose --all
- cargo build --all
- cargo test --all
4 changes: 2 additions & 2 deletions src/capi/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ fn copy_struct_in<T: CConfig>(
// SAFETY: Calculating the offset is safe because the caller has
// guaranteed us that the pointer passed is valid for ptr_size
// (>= copy) bytes.
let start_ptr = unsafe { (ptr as *const u8).offset(copy as isize) };
let start_ptr = unsafe { (ptr as *const u8).add(copy) };
for i in 0..rest {
// SAFETY: Reading this is safe because the caller has guaranteed us
// that the pointer passed is valid for ptr_size bytes.
let val = unsafe { ptr::read_unaligned(start_ptr.offset(i as isize)) };
let val = unsafe { ptr::read_unaligned(start_ptr.add(i)) };
// TODO: This should probably be a specific error type...
ensure!(val == 0, error::InvalidArgument {
name: "new_cfg_ptr",
Expand Down
4 changes: 2 additions & 2 deletions src/capi/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ impl<T> From<Vec<T>> for CVec<T> {
mem::forget(vec);

CVec {
head: head,
length: length,
head,
length,
__capacity: capacity,
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ pub static BACKTRACES_ENABLED: AtomicBool = AtomicBool::new(cfg!(debug_assertion

impl GenerateBacktrace for Backtrace {
fn generate() -> Self {
Backtrace(match BACKTRACES_ENABLED.load(Ordering::SeqCst) {
true => Some(backtrace::Backtrace::new()),
false => None,
})
if BACKTRACES_ENABLED.load(Ordering::SeqCst) {
Backtrace(Some(backtrace::Backtrace::new()))
} else {
Backtrace(None)
}
}

fn as_backtrace(&self) -> Option<&snafu::Backtrace> {
Expand Down
8 changes: 4 additions & 4 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ impl From<c_int> for OpenFlags {
impl OpenFlags {
/// Grab the access mode bits from the flags.
#[inline]
pub fn access_mode(&self) -> c_int {
pub fn access_mode(self) -> c_int {
self.0 & libc::O_ACCMODE
}

/// Does the access mode imply read access?
#[inline]
pub fn wants_read(&self) -> bool {
pub fn wants_read(self) -> bool {
let acc = self.access_mode();
acc == libc::O_RDONLY || acc == libc::O_RDWR
}
Expand All @@ -90,7 +90,7 @@ impl OpenFlags {
/// of the access mode, and thus a `false` value from `.wants_write()` does
/// not guarantee that the kernel will not do a `MAY_WRITE` check.
#[inline]
pub fn wants_write(&self) -> bool {
pub fn wants_write(self) -> bool {
let acc = self.access_mode();
acc == libc::O_WRONLY || acc == libc::O_RDWR
}
Expand Down Expand Up @@ -157,7 +157,7 @@ impl Handle {
/// [`Root::resolve`]: struct.Root.html#method.resolve
/// [`Handle::into_file`]: struct.Handle.html#method.into_file
pub fn from_file_unchecked(inner: File) -> Self {
Self { inner: inner }
Self { inner }
}

// TODO: All the different stat* interfaces?
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#![deny(warnings)]

//! libpathrs provides a series of primitives for Linux programs to safely
//! handle path operations inside an untrusted directory tree.
//!
Expand Down
9 changes: 5 additions & 4 deletions src/resolvers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ pub enum ResolverBackend {
}

lazy_static! {
static ref DEFAULT_RESOLVER_TYPE: ResolverBackend = match *kernel::IS_SUPPORTED {
true => ResolverBackend::Kernel,
false => ResolverBackend::Emulated,
static ref DEFAULT_RESOLVER_TYPE: ResolverBackend = if *kernel::IS_SUPPORTED {
ResolverBackend::Kernel
} else {
ResolverBackend::Emulated
};
}

Expand All @@ -71,7 +72,7 @@ impl Default for ResolverBackend {

impl ResolverBackend {
/// Checks if the resolver is supported on the current platform.
pub fn supported(&self) -> bool {
pub fn supported(self) -> bool {
match self {
ResolverBackend::Kernel => *kernel::IS_SUPPORTED,
ResolverBackend::Emulated => true,
Expand Down
8 changes: 4 additions & 4 deletions src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ pub enum InodeType<'a> {

/// Helper to split a Path into its parent directory and trailing path. The
/// trailing component is guaranteed to not contain a directory separator.
fn path_split<'p>(path: &'p Path) -> Result<(&'p Path, &'p Path), Error> {
fn path_split(path: &'_ Path) -> Result<(&'_ Path, &'_ Path), Error> {
// Get the parent path.
let parent = path.parent().unwrap_or("/".as_ref());
let parent = path.parent().unwrap_or_else(|| "/".as_ref());

// Now construct the trailing portion of the target.
let name = path.file_name().context(error::InvalidArgument {
Expand Down Expand Up @@ -138,7 +138,7 @@ pub struct RenameFlags(pub c_int);

impl RenameFlags {
/// Is this set of RenameFlags supported by the running kernel?
pub fn supported(&self) -> bool {
pub fn supported(self) -> bool {
self.0 == 0 || *syscalls::RENAME_FLAGS_SUPPORTED
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ impl Root {
// alternative to `Root::open`.
pub fn from_file_unchecked(inner: File) -> Self {
Self {
inner: inner,
inner,
resolver: Default::default(),
}
}
Expand Down
Loading

0 comments on commit 51d95fa

Please sign in to comment.