1
Fork 0

Fix some clippy lints

This commit is contained in:
Joshua Nelson 2020-12-03 17:06:58 -05:00
parent b7ebc6b0c1
commit 0ad3dce83a
9 changed files with 28 additions and 33 deletions

View file

@ -235,12 +235,10 @@ impl Annotatable {
pub fn derive_allowed(&self) -> bool { pub fn derive_allowed(&self) -> bool {
match *self { match *self {
Annotatable::Stmt(ref stmt) => match stmt.kind { Annotatable::Stmt(ref stmt) => match stmt.kind {
ast::StmtKind::Item(ref item) => match item.kind { ast::StmtKind::Item(ref item) => matches!(
ast::ItemKind::Struct(..) item.kind,
| ast::ItemKind::Enum(..) ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..)
| ast::ItemKind::Union(..) => true, ),
_ => false,
},
_ => false, _ => false,
}, },
Annotatable::Item(ref item) => match item.kind { Annotatable::Item(ref item) => match item.kind {

View file

@ -1134,7 +1134,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
if let Some(attr) = self.take_first_attr_no_derive(&mut expr) { if let Some(attr) = self.take_first_attr_no_derive(&mut expr) {
// Collect the invoc regardless of whether or not attributes are permitted here // Collect the invoc regardless of whether or not attributes are permitted here
// expansion will eat the attribute so it won't error later. // expansion will eat the attribute so it won't error later.
attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr)); if let Some(attr) = attr.0.as_ref() {
self.cfg.maybe_emit_expr_attr_err(attr)
}
// AstFragmentKind::Expr requires the macro to emit an expression. // AstFragmentKind::Expr requires the macro to emit an expression.
return self return self
@ -1231,7 +1233,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
self.cfg.configure_expr_kind(&mut expr.kind); self.cfg.configure_expr_kind(&mut expr.kind);
if let Some(attr) = self.take_first_attr_no_derive(&mut expr) { if let Some(attr) = self.take_first_attr_no_derive(&mut expr) {
attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr)); if let Some(attr) = attr.0.as_ref() {
self.cfg.maybe_emit_expr_attr_err(attr)
}
return self return self
.collect_attr(attr, Annotatable::Expr(P(expr)), AstFragmentKind::OptExpr) .collect_attr(attr, Annotatable::Expr(P(expr)), AstFragmentKind::OptExpr)

View file

@ -2401,7 +2401,7 @@ impl StructField<'_> {
// Still necessary in couple of places // Still necessary in couple of places
pub fn is_positional(&self) -> bool { pub fn is_positional(&self) -> bool {
let first = self.ident.as_str().as_bytes()[0]; let first = self.ident.as_str().as_bytes()[0];
first >= b'0' && first <= b'9' (b'0'..=b'9').contains(&first)
} }
} }

View file

@ -267,8 +267,8 @@ pub fn is_whitespace(c: char) -> bool {
pub fn is_id_start(c: char) -> bool { pub fn is_id_start(c: char) -> bool {
// This is XID_Start OR '_' (which formally is not a XID_Start). // This is XID_Start OR '_' (which formally is not a XID_Start).
// We also add fast-path for ascii idents // We also add fast-path for ascii idents
('a' <= c && c <= 'z') ('a'..='z').contains(&c)
|| ('A' <= c && c <= 'Z') || ('A'..='Z').contains(&c)
|| c == '_' || c == '_'
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_start(c)) || (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_start(c))
} }
@ -279,9 +279,9 @@ pub fn is_id_start(c: char) -> bool {
pub fn is_id_continue(c: char) -> bool { pub fn is_id_continue(c: char) -> bool {
// This is exactly XID_Continue. // This is exactly XID_Continue.
// We also add fast-path for ascii idents // We also add fast-path for ascii idents
('a' <= c && c <= 'z') ('a'..='z').contains(&c)
|| ('A' <= c && c <= 'Z') || ('A'..='Z').contains(&c)
|| ('0' <= c && c <= '9') || ('0'..='9').contains(&c)
|| c == '_' || c == '_'
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_continue(c)) || (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_continue(c))
} }

View file

@ -1859,7 +1859,7 @@ impl<T: Iterator<Item = char>> Parser<T> {
} }
let n2 = self.decode_hex_escape()?; let n2 = self.decode_hex_escape()?;
if n2 < 0xDC00 || n2 > 0xDFFF { if !(0xDC00..=0xDFFF).contains(&n2) {
return self.error(LoneLeadingSurrogateInHexEscape); return self.error(LoneLeadingSurrogateInHexEscape);
} }
let c = let c =

View file

@ -97,7 +97,7 @@ cfg_if::cfg_if! {
let ptr = src_bytes.as_ptr() as *const __m128i; let ptr = src_bytes.as_ptr() as *const __m128i;
// We don't know if the pointer is aligned to 16 bytes, so we // We don't know if the pointer is aligned to 16 bytes, so we
// use `loadu`, which supports unaligned loading. // use `loadu`, which supports unaligned loading.
let chunk = _mm_loadu_si128(ptr.offset(chunk_index as isize)); let chunk = _mm_loadu_si128(ptr.add(chunk_index));
// For character in the chunk, see if its byte value is < 0, which // For character in the chunk, see if its byte value is < 0, which
// indicates that it's part of a UTF-8 char. // indicates that it's part of a UTF-8 char.
@ -253,7 +253,7 @@ fn analyze_source_file_generic(
let pos = BytePos::from_usize(i) + output_offset; let pos = BytePos::from_usize(i) + output_offset;
if char_len > 1 { if char_len > 1 {
assert!(char_len >= 2 && char_len <= 4); assert!((2..=4).contains(&char_len));
let mbc = MultiByteChar { pos, bytes: char_len as u8 }; let mbc = MultiByteChar { pos, bytes: char_len as u8 };
multi_byte_chars.push(mbc); multi_byte_chars.push(mbc);
} }

View file

@ -1015,10 +1015,7 @@ pub enum ExternalSourceKind {
impl ExternalSource { impl ExternalSource {
pub fn is_absent(&self) -> bool { pub fn is_absent(&self) -> bool {
match self { !matches!(self, ExternalSource::Foreign { kind: ExternalSourceKind::Present(_), .. })
ExternalSource::Foreign { kind: ExternalSourceKind::Present(_), .. } => false,
_ => true,
}
} }
pub fn get_source(&self) -> Option<&Lrc<String>> { pub fn get_source(&self) -> Option<&Lrc<String>> {

View file

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

View file

@ -1362,15 +1362,13 @@ impl fmt::Display for IdentPrinter {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.is_raw { if self.is_raw {
f.write_str("r#")?; f.write_str("r#")?;
} else { } else if self.symbol == kw::DollarCrate {
if self.symbol == kw::DollarCrate { if let Some(span) = self.convert_dollar_crate {
if let Some(span) = self.convert_dollar_crate { let converted = span.ctxt().dollar_crate_name();
let converted = span.ctxt().dollar_crate_name(); if !converted.is_path_segment_keyword() {
if !converted.is_path_segment_keyword() { f.write_str("::")?;
f.write_str("::")?;
}
return fmt::Display::fmt(&converted, f);
} }
return fmt::Display::fmt(&converted, f);
} }
} }
fmt::Display::fmt(&self.symbol, f) fmt::Display::fmt(&self.symbol, f)