Skip to content

Commit 5cebbaa

Browse files
authored
Rollup merge of #79678 - jyn514:THE-PAPERCLIP-COMETH, r=varkor
Fix some clippy lints Happy to revert these if you think they're less readable, but personally I like them better now (especially the `else { if { ... } }` to `else if { ... }` change).
2 parents a2aa3d6 + 0ad3dce commit 5cebbaa

File tree

9 files changed

+28
-33
lines changed

9 files changed

+28
-33
lines changed

compiler/rustc_expand/src/base.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,10 @@ impl Annotatable {
235235
pub fn derive_allowed(&self) -> bool {
236236
match *self {
237237
Annotatable::Stmt(ref stmt) => match stmt.kind {
238-
ast::StmtKind::Item(ref item) => match item.kind {
239-
ast::ItemKind::Struct(..)
240-
| ast::ItemKind::Enum(..)
241-
| ast::ItemKind::Union(..) => true,
242-
_ => false,
243-
},
238+
ast::StmtKind::Item(ref item) => matches!(
239+
item.kind,
240+
ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..)
241+
),
244242
_ => false,
245243
},
246244
Annotatable::Item(ref item) => match item.kind {

compiler/rustc_expand/src/expand.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
11341134
if let Some(attr) = self.take_first_attr_no_derive(&mut expr) {
11351135
// Collect the invoc regardless of whether or not attributes are permitted here
11361136
// expansion will eat the attribute so it won't error later.
1137-
attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr));
1137+
if let Some(attr) = attr.0.as_ref() {
1138+
self.cfg.maybe_emit_expr_attr_err(attr)
1139+
}
11381140

11391141
// AstFragmentKind::Expr requires the macro to emit an expression.
11401142
return self
@@ -1231,7 +1233,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
12311233
self.cfg.configure_expr_kind(&mut expr.kind);
12321234

12331235
if let Some(attr) = self.take_first_attr_no_derive(&mut expr) {
1234-
attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr));
1236+
if let Some(attr) = attr.0.as_ref() {
1237+
self.cfg.maybe_emit_expr_attr_err(attr)
1238+
}
12351239

12361240
return self
12371241
.collect_attr(attr, Annotatable::Expr(P(expr)), AstFragmentKind::OptExpr)

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,7 @@ impl StructField<'_> {
24012401
// Still necessary in couple of places
24022402
pub fn is_positional(&self) -> bool {
24032403
let first = self.ident.as_str().as_bytes()[0];
2404-
first >= b'0' && first <= b'9'
2404+
(b'0'..=b'9').contains(&first)
24052405
}
24062406
}
24072407

compiler/rustc_lexer/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ pub fn is_whitespace(c: char) -> bool {
267267
pub fn is_id_start(c: char) -> bool {
268268
// This is XID_Start OR '_' (which formally is not a XID_Start).
269269
// We also add fast-path for ascii idents
270-
('a' <= c && c <= 'z')
271-
|| ('A' <= c && c <= 'Z')
270+
('a'..='z').contains(&c)
271+
|| ('A'..='Z').contains(&c)
272272
|| c == '_'
273273
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_start(c))
274274
}
@@ -279,9 +279,9 @@ pub fn is_id_start(c: char) -> bool {
279279
pub fn is_id_continue(c: char) -> bool {
280280
// This is exactly XID_Continue.
281281
// We also add fast-path for ascii idents
282-
('a' <= c && c <= 'z')
283-
|| ('A' <= c && c <= 'Z')
284-
|| ('0' <= c && c <= '9')
282+
('a'..='z').contains(&c)
283+
|| ('A'..='Z').contains(&c)
284+
|| ('0'..='9').contains(&c)
285285
|| c == '_'
286286
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_continue(c))
287287
}

compiler/rustc_serialize/src/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@ impl<T: Iterator<Item = char>> Parser<T> {
18591859
}
18601860

18611861
let n2 = self.decode_hex_escape()?;
1862-
if n2 < 0xDC00 || n2 > 0xDFFF {
1862+
if !(0xDC00..=0xDFFF).contains(&n2) {
18631863
return self.error(LoneLeadingSurrogateInHexEscape);
18641864
}
18651865
let c =

compiler/rustc_span/src/analyze_source_file.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ cfg_if::cfg_if! {
9797
let ptr = src_bytes.as_ptr() as *const __m128i;
9898
// We don't know if the pointer is aligned to 16 bytes, so we
9999
// use `loadu`, which supports unaligned loading.
100-
let chunk = _mm_loadu_si128(ptr.offset(chunk_index as isize));
100+
let chunk = _mm_loadu_si128(ptr.add(chunk_index));
101101

102102
// For character in the chunk, see if its byte value is < 0, which
103103
// indicates that it's part of a UTF-8 char.
@@ -253,7 +253,7 @@ fn analyze_source_file_generic(
253253
let pos = BytePos::from_usize(i) + output_offset;
254254

255255
if char_len > 1 {
256-
assert!(char_len >= 2 && char_len <= 4);
256+
assert!((2..=4).contains(&char_len));
257257
let mbc = MultiByteChar { pos, bytes: char_len as u8 };
258258
multi_byte_chars.push(mbc);
259259
}

compiler/rustc_span/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1015,10 +1015,7 @@ pub enum ExternalSourceKind {
10151015

10161016
impl ExternalSource {
10171017
pub fn is_absent(&self) -> bool {
1018-
match self {
1019-
ExternalSource::Foreign { kind: ExternalSourceKind::Present(_), .. } => false,
1020-
_ => true,
1021-
}
1018+
!matches!(self, ExternalSource::Foreign { kind: ExternalSourceKind::Present(_), .. })
10221019
}
10231020

10241021
pub fn get_source(&self) -> Option<&Lrc<String>> {

compiler/rustc_span/src/source_map.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ impl SourceMap {
623623
self.span_to_source(sp, |src, start_index, end_index| {
624624
src.get(start_index..end_index)
625625
.map(|s| s.to_string())
626-
.ok_or_else(|| SpanSnippetError::IllFormedSpan(sp))
626+
.ok_or(SpanSnippetError::IllFormedSpan(sp))
627627
})
628628
}
629629

@@ -640,9 +640,7 @@ impl SourceMap {
640640
/// Returns the source snippet as `String` before the given `Span`.
641641
pub fn span_to_prev_source(&self, sp: Span) -> Result<String, SpanSnippetError> {
642642
self.span_to_source(sp, |src, start_index, _| {
643-
src.get(..start_index)
644-
.map(|s| s.to_string())
645-
.ok_or_else(|| SpanSnippetError::IllFormedSpan(sp))
643+
src.get(..start_index).map(|s| s.to_string()).ok_or(SpanSnippetError::IllFormedSpan(sp))
646644
})
647645
}
648646

compiler/rustc_span/src/symbol.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1363,15 +1363,13 @@ impl fmt::Display for IdentPrinter {
13631363
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
13641364
if self.is_raw {
13651365
f.write_str("r#")?;
1366-
} else {
1367-
if self.symbol == kw::DollarCrate {
1368-
if let Some(span) = self.convert_dollar_crate {
1369-
let converted = span.ctxt().dollar_crate_name();
1370-
if !converted.is_path_segment_keyword() {
1371-
f.write_str("::")?;
1372-
}
1373-
return fmt::Display::fmt(&converted, f);
1366+
} else if self.symbol == kw::DollarCrate {
1367+
if let Some(span) = self.convert_dollar_crate {
1368+
let converted = span.ctxt().dollar_crate_name();
1369+
if !converted.is_path_segment_keyword() {
1370+
f.write_str("::")?;
13741371
}
1372+
return fmt::Display::fmt(&converted, f);
13751373
}
13761374
}
13771375
fmt::Display::fmt(&self.symbol, f)

0 commit comments

Comments
 (0)