Skip to content

Commit 9c39363

Browse files
committed
Simplify
1 parent 3987bf5 commit 9c39363

File tree

9 files changed

+24
-33
lines changed

9 files changed

+24
-33
lines changed

crates/base_db/src/fixture.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl ChangeFixture {
218218
);
219219
roots.push(SourceRoot::new_library(fs));
220220

221-
change.change_file(proc_lib_file, Some(Arc::new(String::from(source))));
221+
change.change_file(proc_lib_file, Some(Arc::new(source)));
222222

223223
let all_crates = crate_graph.crates_in_topological_order();
224224

@@ -275,7 +275,7 @@ pub fn input_replace(attr: TokenStream, _item: TokenStream) -> TokenStream {
275275
expander: Arc::new(AttributeInputReplaceProcMacroExpander),
276276
},
277277
])
278-
.filter(|pm| proc_macros.iter().any(|name| name == &pm.name))
278+
.filter(|pm| proc_macros.iter().any(|name| name == pm.name))
279279
.collect();
280280
(proc_macros, source.into())
281281
}

crates/hir_ty/src/lower.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,12 @@ impl<'a> TyLoweringContext<'a> {
307307
let mut expander = self.expander.borrow_mut();
308308
if expander.is_some() {
309309
(Some(expander), false)
310+
} else if let Some(module_id) = self.resolver.module() {
311+
*expander =
312+
Some(Expander::new(self.db.upcast(), macro_call.file_id, module_id));
313+
(Some(expander), true)
310314
} else {
311-
if let Some(module_id) = self.resolver.module() {
312-
*expander = Some(Expander::new(
313-
self.db.upcast(),
314-
macro_call.file_id,
315-
module_id,
316-
));
317-
(Some(expander), true)
318-
} else {
319-
(None, false)
320-
}
315+
(None, false)
321316
}
322317
};
323318
let ty = if let Some(mut expander) = expander {

crates/ide_ssr/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'db> MatchFinder<'db> {
172172
for m in self.matches().matches {
173173
matches_by_file
174174
.entry(m.range.file_id)
175-
.or_insert_with(|| SsrMatches::default())
175+
.or_insert_with(SsrMatches::default)
176176
.matches
177177
.push(m);
178178
}
@@ -331,7 +331,7 @@ impl SsrMatches {
331331
fn flatten_into(self, out: &mut SsrMatches) {
332332
for mut m in self.matches {
333333
for p in m.placeholder_values.values_mut() {
334-
std::mem::replace(&mut p.inner_matches, SsrMatches::default()).flatten_into(out);
334+
std::mem::take(&mut p.inner_matches).flatten_into(out);
335335
}
336336
out.matches.push(m);
337337
}

crates/ide_ssr/src/matching.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
462462
let mut last_matched_token = child;
463463
// Read code tokens util we reach one equal to the next token from our pattern
464464
// or we reach the end of the token tree.
465-
while let Some(next) = children.next() {
465+
for next in &mut children {
466466
match &next {
467467
SyntaxElement::Token(t) => {
468468
if Some(t.to_string()) == next_pattern_token {
@@ -763,7 +763,7 @@ impl Iterator for PatternIterator {
763763
type Item = SyntaxElement;
764764

765765
fn next(&mut self) -> Option<SyntaxElement> {
766-
while let Some(element) = self.iter.next() {
766+
for element in &mut self.iter {
767767
if !element.kind().is_trivia() {
768768
return Some(element);
769769
}

crates/ide_ssr/src/nester.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn try_add_sub_match(m: Match, existing: &mut Match, sema: &hir::Semantics<ide_d
6565
// will have 0 and a few will have 1. More than that should hopefully be
6666
// exceptional.
6767
let mut collector = MatchCollector::default();
68-
for m in std::mem::replace(&mut p.inner_matches.matches, Vec::new()) {
68+
for m in std::mem::take(&mut p.inner_matches.matches) {
6969
collector.matches_by_node.insert(m.matched_node.clone(), m);
7070
}
7171
collector.add_match(m, sema);

crates/ide_ssr/src/resolving.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ impl<'db> ResolutionScope<'db> {
243243
use syntax::ast::AstNode;
244244
if let Some(path) = ast::Path::cast(path.clone()) {
245245
if let Some(qualifier) = path.qualifier() {
246-
if let Some(resolved_qualifier) = self.resolve_path(&qualifier) {
247-
if let hir::PathResolution::Def(hir::ModuleDef::Adt(adt)) = resolved_qualifier {
248-
return Some(adt.ty(self.scope.db));
249-
}
246+
if let Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) =
247+
self.resolve_path(&qualifier)
248+
{
249+
return Some(adt.ty(self.scope.db));
250250
}
251251
}
252252
}

crates/ide_ssr/src/search.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'db> MatchFinder<'db> {
8080
if let Some(path) =
8181
self.sema.find_node_at_offset_with_descend::<ast::Path>(file.syntax(), offset)
8282
{
83-
self.sema.ancestors_with_macros(path.syntax().clone()).skip(depth).next()
83+
self.sema.ancestors_with_macros(path.syntax().clone()).nth(depth)
8484
} else if let Some(path) =
8585
self.sema.find_node_at_offset_with_descend::<ast::MethodCallExpr>(file.syntax(), offset)
8686
{
@@ -96,8 +96,7 @@ impl<'db> MatchFinder<'db> {
9696
}
9797
self.sema
9898
.ancestors_with_macros(path.syntax().clone())
99-
.skip(depth - PATH_DEPTH_IN_CALL_EXPR)
100-
.next()
99+
.nth(depth - PATH_DEPTH_IN_CALL_EXPR)
101100
} else {
102101
None
103102
}

crates/proc_macro_api/src/msg/flat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'a> Writer<'a> {
246246

247247
fn enqueue(&mut self, subtree: &'a tt::Subtree) -> u32 {
248248
let idx = self.subtree.len();
249-
let delimiter_id = subtree.delimiter.map(|it| it.id).unwrap_or(TokenId::unspecified());
249+
let delimiter_id = subtree.delimiter.map(|it| it.id).unwrap_or_else(TokenId::unspecified);
250250
let delimiter_kind = subtree.delimiter.map(|it| it.kind);
251251
self.subtree.push(SubtreeRepr { id: delimiter_id, kind: delimiter_kind, tt: [!0, !0] });
252252
self.work.push_back((idx, subtree));
@@ -320,7 +320,7 @@ impl Reader {
320320
})
321321
.collect(),
322322
};
323-
res[i] = Some(s.into())
323+
res[i] = Some(s)
324324
}
325325

326326
res[0].take().unwrap()

crates/syntax/src/validation.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,10 @@ fn validate_numeric_name(name_ref: Option<ast::NameRef>, errors: &mut Vec<Syntax
211211
}
212212

213213
fn validate_visibility(vis: ast::Visibility, errors: &mut Vec<SyntaxError>) {
214-
if vis.in_token().is_none() {
215-
if vis.path().and_then(|p| p.as_single_name_ref()).and_then(|n| n.ident_token()).is_some() {
216-
errors.push(SyntaxError::new(
217-
"incorrect visibility restriction",
218-
vis.syntax.text_range(),
219-
));
220-
}
214+
let path_without_in_token = vis.in_token().is_none()
215+
&& vis.path().and_then(|p| p.as_single_name_ref()).and_then(|n| n.ident_token()).is_some();
216+
if path_without_in_token {
217+
errors.push(SyntaxError::new("incorrect visibility restriction", vis.syntax.text_range()));
221218
}
222219
let parent = match vis.syntax().parent() {
223220
Some(it) => it,

0 commit comments

Comments
 (0)