Skip to content

Commit dbd5261

Browse files
ran cargo clippy --fix -- -Wclippy::use_self (#1048)
Co-authored-by: adamnemecek <[email protected]>
1 parent 9f6e92e commit dbd5261

File tree

12 files changed

+59
-59
lines changed

12 files changed

+59
-59
lines changed

data-url/src/forgiving_base64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<E: std::error::Error> std::error::Error for DecodeError<E> {}
5252

5353
impl<E> From<InvalidBase64Details> for DecodeError<E> {
5454
fn from(e: InvalidBase64Details) -> Self {
55-
DecodeError::InvalidBase64(InvalidBase64(e))
55+
Self::InvalidBase64(InvalidBase64(e))
5656
}
5757
}
5858

form_urlencoded/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ pub(crate) fn decode_utf8_lossy(input: Cow<'_, [u8]>) -> Cow<'_, str> {
414414

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

419419
// Given we know the original input bytes are valid UTF-8,
420420
// and we have ownership of those bytes, we re-use them and

idna/src/deprecated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub struct Config {
142142
/// The defaults are that of _beStrict=false_ in the [WHATWG URL Standard](https://url.spec.whatwg.org/#idna)
143143
impl Default for Config {
144144
fn default() -> Self {
145-
Config {
145+
Self {
146146
use_std3_ascii_rules: false,
147147
transitional_processing: false,
148148
check_hyphens: false,

idna/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub use crate::deprecated::{Config, Idna};
6666
pub struct Errors {}
6767

6868
impl From<Errors> for Result<(), Errors> {
69-
fn from(e: Errors) -> Result<(), Errors> {
69+
fn from(e: Errors) -> Self {
7070
Err(e)
7171
}
7272
}

idna/src/punycode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ pub(crate) enum PunycodeEncodeError {
350350

351351
impl From<core::fmt::Error> for PunycodeEncodeError {
352352
fn from(_: core::fmt::Error) -> Self {
353-
PunycodeEncodeError::Sink
353+
Self::Sink
354354
}
355355
}
356356

idna/src/uts46.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl AsciiDenyList {
319319
bits |= 1u128 << b;
320320
i += 1;
321321
}
322-
AsciiDenyList { bits }
322+
Self { bits }
323323
}
324324

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

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

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

354354
/// The _CheckHyphens_ mode.
@@ -434,7 +434,7 @@ pub enum ProcessingError {
434434

435435
impl From<core::fmt::Error> for ProcessingError {
436436
fn from(_: core::fmt::Error) -> Self {
437-
ProcessingError::SinkError
437+
Self::SinkError
438438
}
439439
}
440440

percent_encoding/src/ascii_set.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const BITS_PER_CHUNK: usize = 8 * mem::size_of::<Chunk>();
3737

3838
impl AsciiSet {
3939
/// An empty set.
40-
pub const EMPTY: AsciiSet = AsciiSet {
40+
pub const EMPTY: Self = Self {
4141
mask: [0; ASCII_RANGE_LEN / BITS_PER_CHUNK],
4242
};
4343

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

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

6868
/// Return the union of two sets.
@@ -73,13 +73,13 @@ impl AsciiSet {
7373
self.mask[2] | other.mask[2],
7474
self.mask[3] | other.mask[3],
7575
];
76-
AsciiSet { mask }
76+
Self { mask }
7777
}
7878

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

percent_encoding/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ fn decode_utf8_lossy(input: Cow<'_, [u8]>) -> Cow<'_, str> {
351351

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

356356
// Given we know the original input bytes are valid UTF-8,
357357
// and we have ownership of those bytes, we re-use them and

url/src/host.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ pub(crate) enum HostInternal {
3030
}
3131

3232
impl From<Host<Cow<'_, str>>> for HostInternal {
33-
fn from(host: Host<Cow<'_, str>>) -> HostInternal {
33+
fn from(host: Host<Cow<'_, str>>) -> Self {
3434
match host {
35-
Host::Domain(ref s) if s.is_empty() => HostInternal::None,
36-
Host::Domain(_) => HostInternal::Domain,
37-
Host::Ipv4(address) => HostInternal::Ipv4(address),
38-
Host::Ipv6(address) => HostInternal::Ipv6(address),
35+
Host::Domain(ref s) if s.is_empty() => Self::None,
36+
Host::Domain(_) => Self::Domain,
37+
Host::Ipv4(address) => Self::Ipv4(address),
38+
Host::Ipv6(address) => Self::Ipv6(address),
3939
}
4040
}
4141
}
@@ -175,9 +175,9 @@ impl<'a> Host<Cow<'a, str>> {
175175
impl<S: AsRef<str>> fmt::Display for Host<S> {
176176
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
177177
match *self {
178-
Host::Domain(ref domain) => domain.as_ref().fmt(f),
179-
Host::Ipv4(ref addr) => addr.fmt(f),
180-
Host::Ipv6(ref addr) => {
178+
Self::Domain(ref domain) => domain.as_ref().fmt(f),
179+
Self::Ipv4(ref addr) => addr.fmt(f),
180+
Self::Ipv6(ref addr) => {
181181
f.write_str("[")?;
182182
write_ipv6(addr, f)?;
183183
f.write_str("]")
@@ -192,9 +192,9 @@ where
192192
{
193193
fn eq(&self, other: &Host<T>) -> bool {
194194
match (self, other) {
195-
(Host::Domain(a), Host::Domain(b)) => a == b,
196-
(Host::Ipv4(a), Host::Ipv4(b)) => a == b,
197-
(Host::Ipv6(a), Host::Ipv6(b)) => a == b,
195+
(Self::Domain(a), Host::Domain(b)) => a == b,
196+
(Self::Ipv4(a), Host::Ipv4(b)) => a == b,
197+
(Self::Ipv6(a), Host::Ipv6(b)) => a == b,
198198
(_, _) => false,
199199
}
200200
}

url/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ impl Url {
338338
///
339339
/// [`ParseError`]: enum.ParseError.html
340340
#[inline]
341-
pub fn parse(input: &str) -> Result<Url, crate::ParseError> {
342-
Url::options().parse(input)
341+
pub fn parse(input: &str) -> Result<Self, crate::ParseError> {
342+
Self::options().parse(input)
343343
}
344344

345345
/// Parse an absolute URL from a string and add params to its query string.
@@ -368,14 +368,14 @@ impl Url {
368368
///
369369
/// [`ParseError`]: enum.ParseError.html
370370
#[inline]
371-
pub fn parse_with_params<I, K, V>(input: &str, iter: I) -> Result<Url, crate::ParseError>
371+
pub fn parse_with_params<I, K, V>(input: &str, iter: I) -> Result<Self, crate::ParseError>
372372
where
373373
I: IntoIterator,
374374
I::Item: Borrow<(K, V)>,
375375
K: AsRef<str>,
376376
V: AsRef<str>,
377377
{
378-
let mut url = Url::options().parse(input);
378+
let mut url = Self::options().parse(input);
379379

380380
if let Ok(ref mut url) = url {
381381
url.query_pairs_mut().extend_pairs(iter);
@@ -468,8 +468,8 @@ impl Url {
468468
/// [`ParseError`]: enum.ParseError.html
469469
/// [`make_relative`]: #method.make_relative
470470
#[inline]
471-
pub fn join(&self, input: &str) -> Result<Url, crate::ParseError> {
472-
Url::options().base_url(Some(self)).parse(input)
471+
pub fn join(&self, input: &str) -> Result<Self, crate::ParseError> {
472+
Self::options().base_url(Some(self)).parse(input)
473473
}
474474

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

792-
let other = Url::parse(self.as_str()).expect("Failed to parse myself?");
792+
let other = Self::parse(self.as_str()).expect("Failed to parse myself?");
793793
assert_eq!(&self.serialization, &other.serialization);
794794
assert_eq!(self.scheme_end, other.scheme_end);
795795
assert_eq!(self.username_end, other.username_end);
@@ -2543,11 +2543,11 @@ impl Url {
25432543
)
25442544
))]
25452545
#[allow(clippy::result_unit_err)]
2546-
pub fn from_file_path<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
2546+
pub fn from_file_path<P: AsRef<std::path::Path>>(path: P) -> Result<Self, ()> {
25472547
let mut serialization = "file://".to_owned();
25482548
let host_start = serialization.len() as u32;
25492549
let (host_end, host) = path_to_file_url_segments(path.as_ref(), &mut serialization)?;
2550-
Ok(Url {
2550+
Ok(Self {
25512551
serialization,
25522552
scheme_end: "file".len() as u32,
25532553
username_end: host_start,
@@ -2591,8 +2591,8 @@ impl Url {
25912591
)
25922592
))]
25932593
#[allow(clippy::result_unit_err)]
2594-
pub fn from_directory_path<P: AsRef<std::path::Path>>(path: P) -> Result<Url, ()> {
2595-
let mut url = Url::from_file_path(path)?;
2594+
pub fn from_directory_path<P: AsRef<std::path::Path>>(path: P) -> Result<Self, ()> {
2595+
let mut url = Self::from_file_path(path)?;
25962596
if !url.serialization.ends_with('/') {
25972597
url.serialization.push('/')
25982598
}
@@ -2771,16 +2771,16 @@ impl str::FromStr for Url {
27712771
type Err = ParseError;
27722772

27732773
#[inline]
2774-
fn from_str(input: &str) -> Result<Url, crate::ParseError> {
2775-
Url::parse(input)
2774+
fn from_str(input: &str) -> Result<Self, crate::ParseError> {
2775+
Self::parse(input)
27762776
}
27772777
}
27782778

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

27822782
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
2783-
Url::parse(s)
2783+
Self::parse(s)
27842784
}
27852785
}
27862786

@@ -2794,7 +2794,7 @@ impl fmt::Display for Url {
27942794

27952795
/// String conversion.
27962796
impl From<Url> for String {
2797-
fn from(value: Url) -> String {
2797+
fn from(value: Url) -> Self {
27982798
value.serialization
27992799
}
28002800
}

url/src/origin.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ pub enum Origin {
6363

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

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

7777
/// <https://html.spec.whatwg.org/multipage/#ascii-serialisation-of-an-origin>
7878
pub fn ascii_serialization(&self) -> String {
7979
match *self {
80-
Origin::Opaque(_) => "null".to_owned(),
81-
Origin::Tuple(ref scheme, ref host, port) => {
80+
Self::Opaque(_) => "null".to_owned(),
81+
Self::Tuple(ref scheme, ref host, port) => {
8282
if default_port(scheme) == Some(port) {
8383
format!("{}://{}", scheme, host)
8484
} else {
@@ -91,8 +91,8 @@ impl Origin {
9191
/// <https://html.spec.whatwg.org/multipage/#unicode-serialisation-of-an-origin>
9292
pub fn unicode_serialization(&self) -> String {
9393
match *self {
94-
Origin::Opaque(_) => "null".to_owned(),
95-
Origin::Tuple(ref scheme, ref host, port) => {
94+
Self::Opaque(_) => "null".to_owned(),
95+
Self::Tuple(ref scheme, ref host, port) => {
9696
let host = match *host {
9797
Host::Domain(ref domain) => {
9898
let (domain, _errors) = idna::domain_to_unicode(domain);

url/src/parser.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ simple_enum_error! {
9999
}
100100

101101
impl From<::idna::Errors> for ParseError {
102-
fn from(_: ::idna::Errors) -> ParseError {
103-
ParseError::IdnaError
102+
fn from(_: ::idna::Errors) -> Self {
103+
Self::IdnaError
104104
}
105105
}
106106

@@ -165,20 +165,20 @@ pub enum SchemeType {
165165

166166
impl SchemeType {
167167
pub fn is_special(&self) -> bool {
168-
!matches!(*self, SchemeType::NotSpecial)
168+
!matches!(*self, Self::NotSpecial)
169169
}
170170

171171
pub fn is_file(&self) -> bool {
172-
matches!(*self, SchemeType::File)
172+
matches!(*self, Self::File)
173173
}
174174
}
175175

176176
impl<T: AsRef<str>> From<T> for SchemeType {
177177
fn from(s: T) -> Self {
178178
match s.as_ref() {
179-
"http" | "https" | "ws" | "wss" | "ftp" => SchemeType::SpecialNotFile,
180-
"file" => SchemeType::File,
181-
_ => SchemeType::NotSpecial,
179+
"http" | "https" | "ws" | "wss" | "ftp" => Self::SpecialNotFile,
180+
"file" => Self::File,
181+
_ => Self::NotSpecial,
182182
}
183183
}
184184
}
@@ -350,7 +350,7 @@ pub enum Context {
350350
PathSegmentSetter,
351351
}
352352

353-
impl<'a> Parser<'a> {
353+
impl Parser<'_> {
354354
fn log_violation(&self, v: SyntaxViolation) {
355355
if let Some(f) = self.violation_fn {
356356
f(v)
@@ -365,7 +365,7 @@ impl<'a> Parser<'a> {
365365
}
366366
}
367367

368-
pub fn for_setter(serialization: String) -> Parser<'a> {
368+
pub fn for_setter(serialization: String) -> Self {
369369
Parser {
370370
serialization,
371371
base_url: None,

0 commit comments

Comments
 (0)