Skip to content

ran cargo clippy --fix -- -Wclippy::use_self #1046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data-url/src/forgiving_base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<E: std::error::Error> std::error::Error for DecodeError<E> {}

impl<E> From<InvalidBase64Details> for DecodeError<E> {
fn from(e: InvalidBase64Details) -> Self {
DecodeError::InvalidBase64(InvalidBase64(e))
Self::InvalidBase64(InvalidBase64(e))
}
}

Expand Down
2 changes: 1 addition & 1 deletion form_urlencoded/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ pub(crate) fn decode_utf8_lossy(input: Cow<'_, [u8]>) -> Cow<'_, str> {

// First we do a debug_assert to confirm our description above.
let raw_utf8: *const [u8] = utf8.as_bytes();
debug_assert!(raw_utf8 == &*bytes as *const [u8]);
debug_assert!(core::ptr::eq(raw_utf8, &*bytes));

// Given we know the original input bytes are valid UTF-8,
// and we have ownership of those bytes, we re-use them and
Expand Down
2 changes: 1 addition & 1 deletion idna/src/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub struct Config {
/// The defaults are that of _beStrict=false_ in the [WHATWG URL Standard](https://url.spec.whatwg.org/#idna)
impl Default for Config {
fn default() -> Self {
Config {
Self {
use_std3_ascii_rules: false,
transitional_processing: false,
check_hyphens: false,
Expand Down
2 changes: 1 addition & 1 deletion idna/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub use crate::deprecated::{Config, Idna};
pub struct Errors {}

impl From<Errors> for Result<(), Errors> {
fn from(e: Errors) -> Result<(), Errors> {
fn from(e: Errors) -> Self {
Err(e)
}
}
Expand Down
2 changes: 1 addition & 1 deletion idna/src/punycode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@

impl From<core::fmt::Error> for PunycodeEncodeError {
fn from(_: core::fmt::Error) -> Self {
PunycodeEncodeError::Sink
Self::Sink

Check warning on line 353 in idna/src/punycode.rs

View check run for this annotation

Codecov / codecov/patch

idna/src/punycode.rs#L353

Added line #L353 was not covered by tests
}
}

Expand Down
10 changes: 5 additions & 5 deletions idna/src/uts46.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
bits |= 1u128 << b;
i += 1;
}
AsciiDenyList { bits }
Self { bits }
}

/// No ASCII deny list. This corresponds to _UseSTD3ASCIIRules=false_.
Expand All @@ -332,14 +332,14 @@
/// but it's more efficient to use `AsciiDenyList` than post-processing,
/// because the internals of this crate can optimize away checks in
/// certain cases.
pub const EMPTY: AsciiDenyList = AsciiDenyList::new(false, "");
pub const EMPTY: Self = Self::new(false, "");

/// The STD3 deny list. This corresponds to _UseSTD3ASCIIRules=true_.
///
/// Note that this deny list rejects the underscore, which occurs in
/// pseudo-hosts used by various TXT record-based protocols, and also
/// characters that may occurs in non-DNS naming, such as NetBIOS.
pub const STD3: AsciiDenyList = AsciiDenyList { bits: ldh_mask() };
pub const STD3: Self = Self { bits: ldh_mask() };

/// [Forbidden domain code point](https://url.spec.whatwg.org/#forbidden-domain-code-point) from the WHATWG URL Standard.
///
Expand All @@ -348,7 +348,7 @@
/// Note that this deny list rejects IPv6 addresses, so (as in URL
/// parsing) you need to check for IPv6 addresses first and not
/// put them through UTS 46 processing.
pub const URL: AsciiDenyList = AsciiDenyList::new(true, "%#/:<>?@[\\]^|");
pub const URL: Self = Self::new(true, "%#/:<>?@[\\]^|");
}

/// The _CheckHyphens_ mode.
Expand Down Expand Up @@ -434,7 +434,7 @@

impl From<core::fmt::Error> for ProcessingError {
fn from(_: core::fmt::Error) -> Self {
ProcessingError::SinkError
Self::SinkError

Check warning on line 437 in idna/src/uts46.rs

View check run for this annotation

Codecov / codecov/patch

idna/src/uts46.rs#L437

Added line #L437 was not covered by tests
}
}

Expand Down
10 changes: 5 additions & 5 deletions percent_encoding/src/ascii_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const BITS_PER_CHUNK: usize = 8 * mem::size_of::<Chunk>();

impl AsciiSet {
/// An empty set.
pub const EMPTY: AsciiSet = AsciiSet {
pub const EMPTY: Self = Self {
mask: [0; ASCII_RANGE_LEN / BITS_PER_CHUNK],
};

Expand All @@ -56,13 +56,13 @@ impl AsciiSet {
pub const fn add(&self, byte: u8) -> Self {
let mut mask = self.mask;
mask[byte as usize / BITS_PER_CHUNK] |= 1 << (byte as usize % BITS_PER_CHUNK);
AsciiSet { mask }
Self { mask }
}

pub const fn remove(&self, byte: u8) -> Self {
let mut mask = self.mask;
mask[byte as usize / BITS_PER_CHUNK] &= !(1 << (byte as usize % BITS_PER_CHUNK));
AsciiSet { mask }
Self { mask }
}

/// Return the union of two sets.
Expand All @@ -73,13 +73,13 @@ impl AsciiSet {
self.mask[2] | other.mask[2],
self.mask[3] | other.mask[3],
];
AsciiSet { mask }
Self { mask }
}

/// Return the negation of the set.
pub const fn complement(&self) -> Self {
let mask = [!self.mask[0], !self.mask[1], !self.mask[2], !self.mask[3]];
AsciiSet { mask }
Self { mask }
}
}

Expand Down
2 changes: 1 addition & 1 deletion percent_encoding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ fn decode_utf8_lossy(input: Cow<'_, [u8]>) -> Cow<'_, str> {

// First we do a debug_assert to confirm our description above.
let raw_utf8: *const [u8] = utf8.as_bytes();
debug_assert!(raw_utf8 == &*bytes as *const [u8]);
debug_assert!(core::ptr::eq(raw_utf8, &*bytes));

// Given we know the original input bytes are valid UTF-8,
// and we have ownership of those bytes, we re-use them and
Expand Down
22 changes: 11 additions & 11 deletions url/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ pub(crate) enum HostInternal {
}

impl From<Host<Cow<'_, str>>> for HostInternal {
fn from(host: Host<Cow<'_, str>>) -> HostInternal {
fn from(host: Host<Cow<'_, str>>) -> Self {
match host {
Host::Domain(ref s) if s.is_empty() => HostInternal::None,
Host::Domain(_) => HostInternal::Domain,
Host::Ipv4(address) => HostInternal::Ipv4(address),
Host::Ipv6(address) => HostInternal::Ipv6(address),
Host::Domain(ref s) if s.is_empty() => Self::None,
Host::Domain(_) => Self::Domain,
Host::Ipv4(address) => Self::Ipv4(address),
Host::Ipv6(address) => Self::Ipv6(address),
}
}
}
Expand Down Expand Up @@ -175,9 +175,9 @@ impl<'a> Host<Cow<'a, str>> {
impl<S: AsRef<str>> fmt::Display for Host<S> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match *self {
Host::Domain(ref domain) => domain.as_ref().fmt(f),
Host::Ipv4(ref addr) => addr.fmt(f),
Host::Ipv6(ref addr) => {
Self::Domain(ref domain) => domain.as_ref().fmt(f),
Self::Ipv4(ref addr) => addr.fmt(f),
Self::Ipv6(ref addr) => {
f.write_str("[")?;
write_ipv6(addr, f)?;
f.write_str("]")
Expand All @@ -192,9 +192,9 @@ where
{
fn eq(&self, other: &Host<T>) -> bool {
match (self, other) {
(Host::Domain(a), Host::Domain(b)) => a == b,
(Host::Ipv4(a), Host::Ipv4(b)) => a == b,
(Host::Ipv6(a), Host::Ipv6(b)) => a == b,
(Self::Domain(a), Host::Domain(b)) => a == b,
(Self::Ipv4(a), Host::Ipv4(b)) => a == b,
(Self::Ipv6(a), Host::Ipv6(b)) => a == b,
(_, _) => false,
}
}
Expand Down
32 changes: 16 additions & 16 deletions url/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@
///
/// [`ParseError`]: enum.ParseError.html
#[inline]
pub fn parse(input: &str) -> Result<Url, crate::ParseError> {
Url::options().parse(input)
pub fn parse(input: &str) -> Result<Self, crate::ParseError> {
Self::options().parse(input)
}

/// Parse an absolute URL from a string and add params to its query string.
Expand Down Expand Up @@ -368,14 +368,14 @@
///
/// [`ParseError`]: enum.ParseError.html
#[inline]
pub fn parse_with_params<I, K, V>(input: &str, iter: I) -> Result<Url, crate::ParseError>
pub fn parse_with_params<I, K, V>(input: &str, iter: I) -> Result<Self, crate::ParseError>
where
I: IntoIterator,
I::Item: Borrow<(K, V)>,
K: AsRef<str>,
V: AsRef<str>,
{
let mut url = Url::options().parse(input);
let mut url = Self::options().parse(input);

if let Ok(ref mut url) = url {
url.query_pairs_mut().extend_pairs(iter);
Expand Down Expand Up @@ -468,8 +468,8 @@
/// [`ParseError`]: enum.ParseError.html
/// [`make_relative`]: #method.make_relative
#[inline]
pub fn join(&self, input: &str) -> Result<Url, crate::ParseError> {
Url::options().base_url(Some(self)).parse(input)
pub fn join(&self, input: &str) -> Result<Self, crate::ParseError> {
Self::options().base_url(Some(self)).parse(input)
}

/// Creates a relative URL if possible, with this URL as the base URL.
Expand Down Expand Up @@ -513,7 +513,7 @@
/// This is for example the case if the scheme, host or port are not the same.
///
/// [`join`]: #method.join
pub fn make_relative(&self, url: &Url) -> Option<String> {
pub fn make_relative(&self, url: &Self) -> Option<String> {
if self.cannot_be_a_base() {
return None;
}
Expand Down Expand Up @@ -789,7 +789,7 @@
assert!(fragment_start > query_start);
}

let other = Url::parse(self.as_str()).expect("Failed to parse myself?");
let other = Self::parse(self.as_str()).expect("Failed to parse myself?");
assert_eq!(&self.serialization, &other.serialization);
assert_eq!(self.scheme_end, other.scheme_end);
assert_eq!(self.username_end, other.username_end);
Expand Down Expand Up @@ -2543,11 +2543,11 @@
)
))]
#[allow(clippy::result_unit_err)]
pub fn from_file_path<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
pub fn from_file_path<P: AsRef<std::path::Path>>(path: P) -> Result<Self, ()> {
let mut serialization = "file://".to_owned();
let host_start = serialization.len() as u32;
let (host_end, host) = path_to_file_url_segments(path.as_ref(), &mut serialization)?;
Ok(Url {
Ok(Self {
serialization,
scheme_end: "file".len() as u32,
username_end: host_start,
Expand Down Expand Up @@ -2591,8 +2591,8 @@
)
))]
#[allow(clippy::result_unit_err)]
pub fn from_directory_path<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
let mut url = Url::from_file_path(path)?;
pub fn from_directory_path<P: AsRef<std::path::Path>>(path: P) -> Result<Self, ()> {
let mut url = Self::from_file_path(path)?;
if !url.serialization.ends_with('/') {
url.serialization.push('/')
}
Expand Down Expand Up @@ -2771,16 +2771,16 @@
type Err = ParseError;

#[inline]
fn from_str(input: &str) -> Result<Url, crate::ParseError> {
Url::parse(input)
fn from_str(input: &str) -> Result<Self, crate::ParseError> {
Self::parse(input)
}
}

impl<'a> TryFrom<&'a str> for Url {
type Error = ParseError;

fn try_from(s: &'a str) -> Result<Self, Self::Error> {
Url::parse(s)
Self::parse(s)

Check warning on line 2783 in url/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

url/src/lib.rs#L2783

Added line #L2783 was not covered by tests
}
}

Expand All @@ -2794,7 +2794,7 @@

/// String conversion.
impl From<Url> for String {
fn from(value: Url) -> String {
fn from(value: Url) -> Self {

Check warning on line 2797 in url/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

url/src/lib.rs#L2797

Added line #L2797 was not covered by tests
value.serialization
}
}
Expand Down
14 changes: 7 additions & 7 deletions url/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ pub enum Origin {

impl Origin {
/// Creates a new opaque origin that is only equal to itself.
pub fn new_opaque() -> Origin {
pub fn new_opaque() -> Self {
static COUNTER: AtomicUsize = AtomicUsize::new(0);
Origin::Opaque(OpaqueOrigin(COUNTER.fetch_add(1, Ordering::SeqCst)))
Self::Opaque(OpaqueOrigin(COUNTER.fetch_add(1, Ordering::SeqCst)))
}

/// Return whether this origin is a (scheme, host, port) tuple
/// (as opposed to an opaque origin).
pub fn is_tuple(&self) -> bool {
matches!(*self, Origin::Tuple(..))
matches!(*self, Self::Tuple(..))
}

/// <https://html.spec.whatwg.org/multipage/#ascii-serialisation-of-an-origin>
pub fn ascii_serialization(&self) -> String {
match *self {
Origin::Opaque(_) => "null".to_owned(),
Origin::Tuple(ref scheme, ref host, port) => {
Self::Opaque(_) => "null".to_owned(),
Self::Tuple(ref scheme, ref host, port) => {
if default_port(scheme) == Some(port) {
format!("{}://{}", scheme, host)
} else {
Expand All @@ -91,8 +91,8 @@ impl Origin {
/// <https://html.spec.whatwg.org/multipage/#unicode-serialisation-of-an-origin>
pub fn unicode_serialization(&self) -> String {
match *self {
Origin::Opaque(_) => "null".to_owned(),
Origin::Tuple(ref scheme, ref host, port) => {
Self::Opaque(_) => "null".to_owned(),
Self::Tuple(ref scheme, ref host, port) => {
let host = match *host {
Host::Domain(ref domain) => {
let (domain, _errors) = idna::domain_to_unicode(domain);
Expand Down
16 changes: 8 additions & 8 deletions url/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ simple_enum_error! {
}

impl From<::idna::Errors> for ParseError {
fn from(_: ::idna::Errors) -> ParseError {
ParseError::IdnaError
fn from(_: ::idna::Errors) -> Self {
Self::IdnaError
}
}

Expand Down Expand Up @@ -165,20 +165,20 @@ pub enum SchemeType {

impl SchemeType {
pub fn is_special(&self) -> bool {
!matches!(*self, SchemeType::NotSpecial)
!matches!(*self, Self::NotSpecial)
}

pub fn is_file(&self) -> bool {
matches!(*self, SchemeType::File)
matches!(*self, Self::File)
}
}

impl<T: AsRef<str>> From<T> for SchemeType {
fn from(s: T) -> Self {
match s.as_ref() {
"http" | "https" | "ws" | "wss" | "ftp" => SchemeType::SpecialNotFile,
"file" => SchemeType::File,
_ => SchemeType::NotSpecial,
"http" | "https" | "ws" | "wss" | "ftp" => Self::SpecialNotFile,
"file" => Self::File,
_ => Self::NotSpecial,
}
}
}
Expand Down Expand Up @@ -365,7 +365,7 @@ impl<'a> Parser<'a> {
}
}

pub fn for_setter(serialization: String) -> Parser<'a> {
pub fn for_setter(serialization: String) -> Self {
Parser {
serialization,
base_url: None,
Expand Down
Loading