Skip to content

Commit 4066c8e

Browse files
Rollup merge of rust-lang#41957 - llogiq:clippy-libsyntax, r=petrochenkov
Fix some clippy warnings in libsyntax This is mostly removing stray ampersands, needless returns and lifetimes. Basically a lot of small changes.
2 parents 8f61055 + 282b402 commit 4066c8e

32 files changed

+504
-538
lines changed

src/libsyntax/ast.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ impl Stmt {
715715
StmtKind::Mac(mac) => StmtKind::Mac(mac.map(|(mac, _style, attrs)| {
716716
(mac, MacStmtStyle::Semicolon, attrs)
717717
})),
718-
node @ _ => node,
718+
node => node,
719719
};
720720
self
721721
}
@@ -1076,16 +1076,16 @@ impl LitKind {
10761076
pub fn is_unsuffixed(&self) -> bool {
10771077
match *self {
10781078
// unsuffixed variants
1079-
LitKind::Str(..) => true,
1080-
LitKind::ByteStr(..) => true,
1081-
LitKind::Byte(..) => true,
1082-
LitKind::Char(..) => true,
1083-
LitKind::Int(_, LitIntType::Unsuffixed) => true,
1084-
LitKind::FloatUnsuffixed(..) => true,
1079+
LitKind::Str(..) |
1080+
LitKind::ByteStr(..) |
1081+
LitKind::Byte(..) |
1082+
LitKind::Char(..) |
1083+
LitKind::Int(_, LitIntType::Unsuffixed) |
1084+
LitKind::FloatUnsuffixed(..) |
10851085
LitKind::Bool(..) => true,
10861086
// suffixed variants
1087-
LitKind::Int(_, LitIntType::Signed(..)) => false,
1088-
LitKind::Int(_, LitIntType::Unsigned(..)) => false,
1087+
LitKind::Int(_, LitIntType::Signed(..)) |
1088+
LitKind::Int(_, LitIntType::Unsigned(..)) |
10891089
LitKind::Float(..) => false,
10901090
}
10911091
}

src/libsyntax/attr.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ impl NestedMetaItem {
112112
/// Returns the MetaItem if self is a NestedMetaItemKind::MetaItem.
113113
pub fn meta_item(&self) -> Option<&MetaItem> {
114114
match self.node {
115-
NestedMetaItemKind::MetaItem(ref item) => Some(&item),
115+
NestedMetaItemKind::MetaItem(ref item) => Some(item),
116116
_ => None
117117
}
118118
}
119119

120120
/// Returns the Lit if self is a NestedMetaItemKind::Literal.
121121
pub fn literal(&self) -> Option<&Lit> {
122122
match self.node {
123-
NestedMetaItemKind::Literal(ref lit) => Some(&lit),
123+
NestedMetaItemKind::Literal(ref lit) => Some(lit),
124124
_ => None
125125
}
126126
}
@@ -259,7 +259,7 @@ impl MetaItem {
259259
match self.node {
260260
MetaItemKind::NameValue(ref v) => {
261261
match v.node {
262-
LitKind::Str(ref s, _) => Some((*s).clone()),
262+
LitKind::Str(ref s, _) => Some(*s),
263263
_ => None,
264264
}
265265
},
@@ -1217,9 +1217,10 @@ impl LitKind {
12171217
Token::Literal(token::Lit::Float(symbol), Some(Symbol::intern(ty.ty_to_string())))
12181218
}
12191219
LitKind::FloatUnsuffixed(symbol) => Token::Literal(token::Lit::Float(symbol), None),
1220-
LitKind::Bool(value) => Token::Ident(Ident::with_empty_ctxt(Symbol::intern(match value {
1221-
true => "true",
1222-
false => "false",
1220+
LitKind::Bool(value) => Token::Ident(Ident::with_empty_ctxt(Symbol::intern(if value {
1221+
"true"
1222+
} else {
1223+
"false"
12231224
}))),
12241225
}
12251226
}
@@ -1261,7 +1262,7 @@ impl<T: HasAttrs> HasAttrs for Spanned<T> {
12611262

12621263
impl HasAttrs for Vec<Attribute> {
12631264
fn attrs(&self) -> &[Attribute] {
1264-
&self
1265+
self
12651266
}
12661267
fn map_attrs<F: FnOnce(Vec<Attribute>) -> Vec<Attribute>>(self, f: F) -> Self {
12671268
f(self)
@@ -1270,7 +1271,7 @@ impl HasAttrs for Vec<Attribute> {
12701271

12711272
impl HasAttrs for ThinVec<Attribute> {
12721273
fn attrs(&self) -> &[Attribute] {
1273-
&self
1274+
self
12741275
}
12751276
fn map_attrs<F: FnOnce(Vec<Attribute>) -> Vec<Attribute>>(self, f: F) -> Self {
12761277
f(self.into()).into()

src/libsyntax/codemap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl CodeMap {
485485
match self.span_to_snippet(sp) {
486486
Ok(snippet) => {
487487
let snippet = snippet.split(c).nth(0).unwrap_or("").trim_right();
488-
if snippet.len() > 0 && !snippet.contains('\n') {
488+
if !snippet.is_empty() && !snippet.contains('\n') {
489489
Span { hi: BytePos(sp.lo.0 + snippet.len() as u32), ..sp }
490490
} else {
491491
sp
@@ -502,7 +502,7 @@ impl CodeMap {
502502
pub fn get_filemap(&self, filename: &str) -> Option<Rc<FileMap>> {
503503
for fm in self.files.borrow().iter() {
504504
if filename == fm.name {
505-
(self.dep_tracking_callback.borrow())(&fm);
505+
(self.dep_tracking_callback.borrow())(fm);
506506
return Some(fm.clone());
507507
}
508508
}

src/libsyntax/config.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'a> StripUnconfigured<'a> {
123123
return false;
124124
}
125125

126-
let mis = if !is_cfg(&attr) {
126+
let mis = if !is_cfg(attr) {
127127
return true;
128128
} else if let Some(mis) = attr.meta_item_list() {
129129
mis
@@ -150,7 +150,7 @@ impl<'a> StripUnconfigured<'a> {
150150
// flag the offending attributes
151151
for attr in attrs.iter() {
152152
if !self.features.map(|features| features.stmt_expr_attributes).unwrap_or(true) {
153-
let mut err = feature_err(&self.sess,
153+
let mut err = feature_err(self.sess,
154154
"stmt_expr_attributes",
155155
attr.span,
156156
GateIssue::Language,
@@ -258,7 +258,7 @@ impl<'a> StripUnconfigured<'a> {
258258
pub fn configure_struct_expr_field(&mut self, field: ast::Field) -> Option<ast::Field> {
259259
if !self.features.map(|features| features.struct_field_attributes).unwrap_or(true) {
260260
if !field.attrs.is_empty() {
261-
let mut err = feature_err(&self.sess,
261+
let mut err = feature_err(self.sess,
262262
"struct_field_attributes",
263263
field.span,
264264
GateIssue::Language,
@@ -290,7 +290,7 @@ impl<'a> StripUnconfigured<'a> {
290290
for attr in attrs.iter() {
291291
if !self.features.map(|features| features.struct_field_attributes).unwrap_or(true) {
292292
let mut err = feature_err(
293-
&self.sess,
293+
self.sess,
294294
"struct_field_attributes",
295295
attr.span,
296296
GateIssue::Language,

src/libsyntax/diagnostics/plugin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
120120

121121
// URLs can be unavoidably longer than the line limit, so we allow them.
122122
// Allowed format is: `[name]: https://www.rust-lang.org/`
123-
let is_url = |l: &str| l.starts_with('[') && l.contains("]:") && l.contains("http");
123+
let is_url = |l: &str| l.starts_with("[") && l.contains("]:") && l.contains("http");
124124

125125
if msg.lines().any(|line| line.len() > MAX_DESCRIPTION_WIDTH && !is_url(line)) {
126126
ecx.span_err(span, &format!(
@@ -177,7 +177,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
177177
if let Err(e) = output_metadata(ecx,
178178
&target_triple,
179179
&crate_name.name.as_str(),
180-
&diagnostics) {
180+
diagnostics) {
181181
ecx.span_bug(span, &format!(
182182
"error writing metadata for triple `{}` and crate `{}`, error: {}, \
183183
cause: {:?}",
@@ -227,7 +227,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
227227

228228
MacEager::items(SmallVector::many(vec![
229229
P(ast::Item {
230-
ident: name.clone(),
230+
ident: *name,
231231
attrs: Vec::new(),
232232
id: ast::DUMMY_NODE_ID,
233233
node: ast::ItemKind::Const(

src/libsyntax/ext/base.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,8 @@ pub struct ExpansionData {
635635
}
636636

637637
/// One of these is made during expansion and incrementally updated as we go;
638-
/// when a macro expansion occurs, the resulting nodes have the backtrace()
639-
/// -> expn_info of their expansion context stored into their span.
638+
/// when a macro expansion occurs, the resulting nodes have the `backtrace()
639+
/// -> expn_info` of their expansion context stored into their span.
640640
pub struct ExtCtxt<'a> {
641641
pub parse_sess: &'a parse::ParseSess,
642642
pub ecfg: expand::ExpansionConfig<'a>,
@@ -709,7 +709,7 @@ impl<'a> ExtCtxt<'a> {
709709
}
710710
ctxt = info.call_site.ctxt;
711711
last_macro = Some(info.call_site);
712-
return Some(());
712+
Some(())
713713
}).is_none() {
714714
break
715715
}
@@ -770,9 +770,9 @@ impl<'a> ExtCtxt<'a> {
770770
}
771771
pub fn trace_macros_diag(&self) {
772772
for (sp, notes) in self.expansions.iter() {
773-
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, &"trace_macro");
773+
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, "trace_macro");
774774
for note in notes {
775-
db.note(&note);
775+
db.note(note);
776776
}
777777
db.emit();
778778
}
@@ -795,7 +795,7 @@ impl<'a> ExtCtxt<'a> {
795795
v.push(self.ident_of(s));
796796
}
797797
v.extend(components.iter().map(|s| self.ident_of(s)));
798-
return v
798+
v
799799
}
800800
pub fn name_of(&self, st: &str) -> ast::Name {
801801
Symbol::intern(st)

src/libsyntax/ext/expand.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -415,19 +415,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
415415

416416
match *ext {
417417
MultiModifier(ref mac) => {
418-
let meta = panictry!(attr.parse_meta(&self.cx.parse_sess));
418+
let meta = panictry!(attr.parse_meta(self.cx.parse_sess));
419419
let item = mac.expand(self.cx, attr.span, &meta, item);
420420
kind.expect_from_annotatables(item)
421421
}
422422
MultiDecorator(ref mac) => {
423423
let mut items = Vec::new();
424-
let meta = panictry!(attr.parse_meta(&self.cx.parse_sess));
424+
let meta = panictry!(attr.parse_meta(self.cx.parse_sess));
425425
mac.expand(self.cx, attr.span, &meta, &item, &mut |item| items.push(item));
426426
items.push(item);
427427
kind.expect_from_annotatables(items)
428428
}
429429
SyntaxExtension::AttrProcMacro(ref mac) => {
430-
let item_toks = stream_for_item(&item, &self.cx.parse_sess);
430+
let item_toks = stream_for_item(&item, self.cx.parse_sess);
431431

432432
let span = Span { ctxt: self.cx.backtrace(), ..attr.span };
433433
let tok_result = mac.expand(self.cx, attr.span, attr.tokens, item_toks);
@@ -439,7 +439,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
439439
}
440440
_ => {
441441
let msg = &format!("macro `{}` may not be used in attributes", attr.path);
442-
self.cx.span_err(attr.span, &msg);
442+
self.cx.span_err(attr.span, msg);
443443
kind.dummy(attr.span)
444444
}
445445
}
@@ -454,7 +454,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
454454
};
455455
let path = &mac.node.path;
456456

457-
let ident = ident.unwrap_or(keywords::Invalid.ident());
457+
let ident = ident.unwrap_or_else(|| keywords::Invalid.ident());
458458
let marked_tts = noop_fold_tts(mac.node.stream(), &mut Marker(mark));
459459
let opt_expanded = match *ext {
460460
NormalTT(ref expandfun, exp_span, allow_internal_unstable) => {
@@ -591,7 +591,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
591591
}
592592
_ => {
593593
let msg = &format!("macro `{}` may not be used for derive attributes", attr.path);
594-
self.cx.span_err(span, &msg);
594+
self.cx.span_err(span, msg);
595595
kind.dummy(span)
596596
}
597597
}
@@ -749,19 +749,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
749749
fn check_attributes(&mut self, attrs: &[ast::Attribute]) {
750750
let features = self.cx.ecfg.features.unwrap();
751751
for attr in attrs.iter() {
752-
feature_gate::check_attribute(&attr, &self.cx.parse_sess, features);
752+
feature_gate::check_attribute(attr, self.cx.parse_sess, features);
753753
}
754754
}
755755
}
756756

757757
pub fn find_attr_invoc(attrs: &mut Vec<ast::Attribute>) -> Option<ast::Attribute> {
758-
for i in 0 .. attrs.len() {
759-
if !attr::is_known(&attrs[i]) && !is_builtin_attr(&attrs[i]) {
760-
return Some(attrs.remove(i));
761-
}
762-
}
763-
764-
None
758+
attrs.iter()
759+
.position(|a| !attr::is_known(a) && !is_builtin_attr(a))
760+
.map(|i| attrs.remove(i))
765761
}
766762

767763
// These are pretty nasty. Ideally, we would keep the tokens around, linked from
@@ -923,7 +919,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
923919
let result = noop_fold_item(item, self);
924920
self.cx.current_expansion.module = orig_module;
925921
self.cx.current_expansion.directory_ownership = orig_directory_ownership;
926-
return result;
922+
result
927923
}
928924
// Ensure that test functions are accessible from the test harness.
929925
ast::ItemKind::Fn(..) if self.cx.ecfg.should_test => {

src/libsyntax/ext/quote.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use tokenstream::{TokenStream, TokenTree};
2323
///
2424
/// This is registered as a set of expression syntax extension called quote!
2525
/// that lifts its argument token-tree to an AST representing the
26-
/// construction of the same token tree, with token::SubstNt interpreted
26+
/// construction of the same token tree, with `token::SubstNt` interpreted
2727
/// as antiquotes (splices).
2828
2929
pub mod rt {
@@ -389,7 +389,7 @@ pub fn unflatten(tts: Vec<TokenTree>) -> Vec<TokenTree> {
389389
result = results.pop().unwrap();
390390
result.push(tree);
391391
}
392-
tree @ _ => result.push(tree),
392+
tree => result.push(tree),
393393
}
394394
}
395395
result

src/libsyntax/ext/source_util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenT
150150
cx.span_err(sp,
151151
&format!("{} wasn't a utf-8 file",
152152
file.display()));
153-
return DummyResult::expr(sp);
153+
DummyResult::expr(sp)
154154
}
155155
}
156156
}
@@ -167,7 +167,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke
167167
Err(e) => {
168168
cx.span_err(sp,
169169
&format!("couldn't read {}: {}", file.display(), e));
170-
return DummyResult::expr(sp);
170+
DummyResult::expr(sp)
171171
}
172172
Ok(..) => {
173173
// Add this input file to the code map to make it available as

0 commit comments

Comments
 (0)