Correct the clippy::use_self lint where possible. (#114)
This commit is contained in:
committed by
Dan Gohman
parent
603f7a9f22
commit
692bb27209
@@ -1,3 +1,5 @@
|
|||||||
|
// Due to https://github.com/rust-lang/rust/issues/64247
|
||||||
|
#![allow(clippy::use_self)]
|
||||||
use crate::host;
|
use crate::host;
|
||||||
use failure::Fail;
|
use failure::Fail;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
|||||||
@@ -15,21 +15,21 @@ pub(crate) enum Descriptor {
|
|||||||
impl Descriptor {
|
impl Descriptor {
|
||||||
pub(crate) fn as_file(&self) -> Result<&OsFile> {
|
pub(crate) fn as_file(&self) -> Result<&OsFile> {
|
||||||
match self {
|
match self {
|
||||||
Descriptor::OsFile(file) => Ok(file),
|
Self::OsFile(file) => Ok(file),
|
||||||
_ => Err(Error::EBADF),
|
_ => Err(Error::EBADF),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn as_file_mut(&mut self) -> Result<&mut OsFile> {
|
pub(crate) fn as_file_mut(&mut self) -> Result<&mut OsFile> {
|
||||||
match self {
|
match self {
|
||||||
Descriptor::OsFile(file) => Ok(file),
|
Self::OsFile(file) => Ok(file),
|
||||||
_ => Err(Error::EBADF),
|
_ => Err(Error::EBADF),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_file(&self) -> bool {
|
pub(crate) fn is_file(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Descriptor::OsFile(_) => true,
|
Self::OsFile(_) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ impl Descriptor {
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub(crate) fn is_stdin(&self) -> bool {
|
pub(crate) fn is_stdin(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Descriptor::Stdin => true,
|
Self::Stdin => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ impl Descriptor {
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub(crate) fn is_stdout(&self) -> bool {
|
pub(crate) fn is_stdout(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Descriptor::Stdout => true,
|
Self::Stdout => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ impl Descriptor {
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub(crate) fn is_stderr(&self) -> bool {
|
pub(crate) fn is_stderr(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Descriptor::Stderr => true,
|
Self::Stderr => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ cfg_if::cfg_if! {
|
|||||||
impl AsRawFd for Descriptor {
|
impl AsRawFd for Descriptor {
|
||||||
fn as_raw_fd(&self) -> RawFd {
|
fn as_raw_fd(&self) -> RawFd {
|
||||||
match self {
|
match self {
|
||||||
Descriptor::OsFile(file) => file.as_raw_fd(),
|
Self::OsFile(file) => file.as_raw_fd(),
|
||||||
Descriptor::Stdin => io::stdin().as_raw_fd(),
|
Self::Stdin => io::stdin().as_raw_fd(),
|
||||||
Descriptor::Stdout => io::stdout().as_raw_fd(),
|
Self::Stdout => io::stdout().as_raw_fd(),
|
||||||
Descriptor::Stderr => io::stderr().as_raw_fd(),
|
Self::Stderr => io::stderr().as_raw_fd(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ impl DerefMut for OsFile {
|
|||||||
impl AsRawHandle for Descriptor {
|
impl AsRawHandle for Descriptor {
|
||||||
fn as_raw_handle(&self) -> RawHandle {
|
fn as_raw_handle(&self) -> RawHandle {
|
||||||
match self {
|
match self {
|
||||||
Descriptor::OsFile(file) => file.as_raw_handle(),
|
Self::OsFile(file) => file.as_raw_handle(),
|
||||||
Descriptor::Stdin => io::stdin().as_raw_handle(),
|
Self::Stdin => io::stdin().as_raw_handle(),
|
||||||
Descriptor::Stdout => io::stdout().as_raw_handle(),
|
Self::Stdout => io::stdout().as_raw_handle(),
|
||||||
Descriptor::Stderr => io::stderr().as_raw_handle(),
|
Self::Stderr => io::stderr().as_raw_handle(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,9 +96,7 @@ pub(crate) unsafe fn determine_type_rights<Handle: AsRawHandle>(
|
|||||||
)
|
)
|
||||||
} else if file_type.is_disk() {
|
} else if file_type.is_disk() {
|
||||||
// disk file: file, dir or disk device
|
// disk file: file, dir or disk device
|
||||||
let file = std::mem::ManuallyDrop::new(unsafe {
|
let file = std::mem::ManuallyDrop::new(File::from_raw_handle(handle.as_raw_handle()));
|
||||||
File::from_raw_handle(handle.as_raw_handle())
|
|
||||||
});
|
|
||||||
let meta = file.metadata().map_err(|_| Error::EINVAL)?;
|
let meta = file.metadata().map_err(|_| Error::EINVAL)?;
|
||||||
if meta.is_dir() {
|
if meta.is_dir() {
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use crate::{host, Error, Result};
|
|||||||
use std::ffi::{OsStr, OsString};
|
use std::ffi::{OsStr, OsString};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::os::windows::ffi::{OsStrExt, OsStringExt};
|
use std::os::windows::ffi::{OsStrExt, OsStringExt};
|
||||||
use std::os::windows::prelude::AsRawHandle;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
pub(crate) trait PathGetExt {
|
pub(crate) trait PathGetExt {
|
||||||
|
|||||||
Reference in New Issue
Block a user