Skip to content

Commit 11ffcc0

Browse files
committed
Auto merge of rust-lang#15615 - shogo-nakano-desu:refactor/fix-clippy-lints, r=Veykril
Refactor/fix clippy lints As title says.
2 parents fccae08 + dd84306 commit 11ffcc0

File tree

6 files changed

+50
-55
lines changed

6 files changed

+50
-55
lines changed

Diff for: crates/intern/src/lib.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,10 @@ impl<T: Internable> Interned<T> {
3333
// - if not, box it up, insert it, and return a clone
3434
// This needs to be atomic (locking the shard) to avoid races with other thread, which could
3535
// insert the same object between us looking it up and inserting it.
36-
match shard.raw_entry_mut().from_key_hashed_nocheck(hash as u64, &obj) {
36+
match shard.raw_entry_mut().from_key_hashed_nocheck(hash, &obj) {
3737
RawEntryMut::Occupied(occ) => Self { arc: occ.key().clone() },
3838
RawEntryMut::Vacant(vac) => Self {
39-
arc: vac
40-
.insert_hashed_nocheck(hash as u64, Arc::new(obj), SharedValue::new(()))
41-
.0
42-
.clone(),
39+
arc: vac.insert_hashed_nocheck(hash, Arc::new(obj), SharedValue::new(())).0.clone(),
4340
},
4441
}
4542
}
@@ -54,13 +51,10 @@ impl Interned<str> {
5451
// - if not, box it up, insert it, and return a clone
5552
// This needs to be atomic (locking the shard) to avoid races with other thread, which could
5653
// insert the same object between us looking it up and inserting it.
57-
match shard.raw_entry_mut().from_key_hashed_nocheck(hash as u64, s) {
54+
match shard.raw_entry_mut().from_key_hashed_nocheck(hash, s) {
5855
RawEntryMut::Occupied(occ) => Self { arc: occ.key().clone() },
5956
RawEntryMut::Vacant(vac) => Self {
60-
arc: vac
61-
.insert_hashed_nocheck(hash as u64, Arc::from(s), SharedValue::new(()))
62-
.0
63-
.clone(),
57+
arc: vac.insert_hashed_nocheck(hash, Arc::from(s), SharedValue::new(())).0.clone(),
6458
},
6559
}
6660
}

Diff for: crates/parser/src/shortcuts.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,27 @@ impl LexedStr<'_> {
3232
let kind = self.kind(i);
3333
if kind.is_trivia() {
3434
was_joint = false
35+
} else if kind == SyntaxKind::IDENT {
36+
let token_text = self.text(i);
37+
let contextual_kw =
38+
SyntaxKind::from_contextual_keyword(token_text).unwrap_or(SyntaxKind::IDENT);
39+
res.push_ident(contextual_kw);
3540
} else {
36-
if kind == SyntaxKind::IDENT {
37-
let token_text = self.text(i);
38-
let contextual_kw = SyntaxKind::from_contextual_keyword(token_text)
39-
.unwrap_or(SyntaxKind::IDENT);
40-
res.push_ident(contextual_kw);
41-
} else {
42-
if was_joint {
41+
if was_joint {
42+
res.was_joint();
43+
}
44+
res.push(kind);
45+
// Tag the token as joint if it is float with a fractional part
46+
// we use this jointness to inform the parser about what token split
47+
// event to emit when we encounter a float literal in a field access
48+
if kind == SyntaxKind::FLOAT_NUMBER {
49+
if !self.text(i).ends_with('.') {
4350
res.was_joint();
44-
}
45-
res.push(kind);
46-
// Tag the token as joint if it is float with a fractional part
47-
// we use this jointness to inform the parser about what token split
48-
// event to emit when we encounter a float literal in a field access
49-
if kind == SyntaxKind::FLOAT_NUMBER {
50-
if !self.text(i).ends_with('.') {
51-
res.was_joint();
52-
} else {
53-
was_joint = false;
54-
}
5551
} else {
56-
was_joint = true;
52+
was_joint = false;
5753
}
54+
} else {
55+
was_joint = true;
5856
}
5957
}
6058
}

Diff for: crates/syntax/src/ast/edit_in_place.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub trait AttrsOwnerEdit: ast::HasAttrs {
224224
let after_attrs_and_comments = node
225225
.children_with_tokens()
226226
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
227-
.map_or(Position::first_child_of(node), |it| Position::before(it));
227+
.map_or(Position::first_child_of(node), Position::before);
228228

229229
ted::insert_all(
230230
after_attrs_and_comments,
@@ -433,7 +433,9 @@ impl ast::UseTree {
433433
if &path == prefix && self.use_tree_list().is_none() {
434434
if self.star_token().is_some() {
435435
// path$0::* -> *
436-
self.coloncolon_token().map(ted::remove);
436+
if let Some(a) = self.coloncolon_token() {
437+
ted::remove(a)
438+
}
437439
ted::remove(prefix.syntax());
438440
} else {
439441
// path$0 -> self
@@ -460,7 +462,9 @@ impl ast::UseTree {
460462
for p in successors(parent.parent_path(), |it| it.parent_path()) {
461463
p.segment()?;
462464
}
463-
prefix.parent_path().and_then(|p| p.coloncolon_token()).map(ted::remove);
465+
if let Some(a) = prefix.parent_path().and_then(|p| p.coloncolon_token()) {
466+
ted::remove(a)
467+
}
464468
ted::remove(prefix.syntax());
465469
Some(())
466470
}
@@ -976,7 +980,9 @@ enum Foo {
976980

977981
fn check_add_variant(before: &str, expected: &str, variant: ast::Variant) {
978982
let enum_ = ast_mut_from_text::<ast::Enum>(before);
979-
enum_.variant_list().map(|it| it.add_variant(variant));
983+
if let Some(it) = enum_.variant_list() {
984+
it.add_variant(variant)
985+
}
980986
let after = enum_.to_string();
981987
assert_eq_text!(&trim_indent(expected.trim()), &trim_indent(after.trim()));
982988
}

Diff for: crates/syntax/src/ast/make.rs

-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ pub fn record_field(
433433
ast_from_text(&format!("struct S {{ {visibility}{name}: {ty}, }}"))
434434
}
435435

436-
// TODO
437436
pub fn block_expr(
438437
stmts: impl IntoIterator<Item = ast::Stmt>,
439438
tail_expr: Option<ast::Expr>,

Diff for: crates/syntax/src/lib.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -182,29 +182,27 @@ impl ast::TokenTree {
182182
let kind = t.kind();
183183
if kind.is_trivia() {
184184
was_joint = false
185+
} else if kind == SyntaxKind::IDENT {
186+
let token_text = t.text();
187+
let contextual_kw =
188+
SyntaxKind::from_contextual_keyword(token_text).unwrap_or(SyntaxKind::IDENT);
189+
parser_input.push_ident(contextual_kw);
185190
} else {
186-
if kind == SyntaxKind::IDENT {
187-
let token_text = t.text();
188-
let contextual_kw = SyntaxKind::from_contextual_keyword(token_text)
189-
.unwrap_or(SyntaxKind::IDENT);
190-
parser_input.push_ident(contextual_kw);
191-
} else {
192-
if was_joint {
191+
if was_joint {
192+
parser_input.was_joint();
193+
}
194+
parser_input.push(kind);
195+
// Tag the token as joint if it is float with a fractional part
196+
// we use this jointness to inform the parser about what token split
197+
// event to emit when we encounter a float literal in a field access
198+
if kind == SyntaxKind::FLOAT_NUMBER {
199+
if !t.text().ends_with('.') {
193200
parser_input.was_joint();
194-
}
195-
parser_input.push(kind);
196-
// Tag the token as joint if it is float with a fractional part
197-
// we use this jointness to inform the parser about what token split
198-
// event to emit when we encounter a float literal in a field access
199-
if kind == SyntaxKind::FLOAT_NUMBER {
200-
if !t.text().ends_with('.') {
201-
parser_input.was_joint();
202-
} else {
203-
was_joint = false;
204-
}
205201
} else {
206-
was_joint = true;
202+
was_joint = false;
207203
}
204+
} else {
205+
was_joint = true;
208206
}
209207
}
210208
}

Diff for: crates/syntax/src/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use crate::{ast, fuzz, AstNode, SourceFile, SyntaxError};
1717

1818
#[test]
1919
fn parse_smoke_test() {
20-
let code = r##"
20+
let code = r#"
2121
fn main() {
2222
println!("Hello, world!")
2323
}
24-
"##;
24+
"#;
2525

2626
let parse = SourceFile::parse(code);
2727
// eprintln!("{:#?}", parse.syntax_node());

0 commit comments

Comments
 (0)