Skip to content

Commit 6d88323

Browse files
committed
auto_import: Removed Empty in favor of Partial(0)
auto_import: Removed unecessary lifetimes
1 parent 5580cf2 commit 6d88323

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

crates/ra_assists/src/auto_import.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ fn collect_path_segments(path: &ast::Path) -> Option<Vec<&ast::PathSegment>> {
4848
return Some(v);
4949
}
5050

51-
fn collect_path_segments_raw<'b, 'a: 'b>(
52-
segments: &'b mut Vec<&'a ast::PathSegment>,
51+
fn collect_path_segments_raw<'a>(
52+
segments: &mut Vec<&'a ast::PathSegment>,
5353
mut path: &'a ast::Path,
5454
) -> Option<usize> {
5555
let oldlen = segments.len();
@@ -105,8 +105,6 @@ fn fmt_segments_raw(segments: &[&ast::PathSegment], buf: &mut String) {
105105
enum PathSegmentsMatch {
106106
// Patch matches exactly
107107
Full,
108-
// None of the segments matched. It's a more explicit Partial(0)
109-
Empty,
110108
// When some of the segments matched
111109
Partial(usize),
112110
// When all the segments of the right path are matched against the left path,
@@ -129,11 +127,7 @@ fn compare_path_segments(
129127
if compare_path_segment(left, right) {
130128
matching += 1
131129
} else {
132-
return if matching == 0 {
133-
PathSegmentsMatch::Empty
134-
} else {
135-
PathSegmentsMatch::Partial(matching)
136-
};
130+
return PathSegmentsMatch::Partial(matching);
137131
}
138132
}
139133
EitherOrBoth::Left(_) => {
@@ -149,15 +143,15 @@ fn compare_path_segments(
149143

150144
fn compare_path_segment(a: &ast::PathSegment, b: &ast::PathSegment) -> bool {
151145
if let (Some(ka), Some(kb)) = (a.kind(), b.kind()) {
152-
return match (ka, kb) {
146+
match (ka, kb) {
153147
(ast::PathSegmentKind::Name(nameref_a), ast::PathSegmentKind::Name(nameref_b)) => {
154148
nameref_a.text() == nameref_b.text()
155149
}
156150
(ast::PathSegmentKind::SelfKw, ast::PathSegmentKind::SelfKw) => true,
157151
(ast::PathSegmentKind::SuperKw, ast::PathSegmentKind::SuperKw) => true,
158152
(ast::PathSegmentKind::CrateKw, ast::PathSegmentKind::CrateKw) => true,
159153
(_, _) => false,
160-
};
154+
}
161155
} else {
162156
false
163157
}
@@ -226,11 +220,11 @@ impl<'a> ImportAction<'a> {
226220

227221
// Find out the best ImportAction to import target path against current_use_tree.
228222
// If current_use_tree has a nested import the function gets called recursively on every UseTree inside a UseTreeList.
229-
fn walk_use_tree_for_best_action<'b, 'c, 'a: 'b + 'c>(
230-
current_path_segments: &'b mut Vec<&'a ast::PathSegment>, // buffer containing path segments
223+
fn walk_use_tree_for_best_action<'a>(
224+
current_path_segments: &mut Vec<&'a ast::PathSegment>, // buffer containing path segments
231225
current_parent_use_tree_list: Option<&'a ast::UseTreeList>, // will be Some value if we are in a nested import
232226
current_use_tree: &'a ast::UseTree, // the use tree we are currently examinating
233-
target: &'c [&'a ast::PathSegment], // the path we want to import
227+
target: &[&'a ast::PathSegment], // the path we want to import
234228
) -> ImportAction<'a> {
235229
// We save the number of segments in the buffer so we can restore the correct segments
236230
// before returning. Recursive call will add segments so we need to delete them.
@@ -295,7 +289,7 @@ fn walk_use_tree_for_best_action<'b, 'c, 'a: 'b + 'c>(
295289
ImportAction::Nothing
296290
}
297291
}
298-
PathSegmentsMatch::Empty => ImportAction::AddNewUse(
292+
PathSegmentsMatch::Partial(0) => ImportAction::AddNewUse(
299293
// e.g: target is std::fmt and we can have
300294
// use foo::bar
301295
// We add a brand new use statement
@@ -346,7 +340,7 @@ fn walk_use_tree_for_best_action<'b, 'c, 'a: 'b + 'c>(
346340
better_action
347341
}
348342
PathSegmentsMatch::PartialRight(n) => {
349-
// e.g: target std::fmt and we can have
343+
// e.g: target is std::fmt and we can have
350344
// use std::fmt::Debug;
351345
let segments_to_split = current_path_segments.split_at(prev_len + n).1;
352346
ImportAction::AddNestedImport(prev_len + n, path, Some(segments_to_split[0]), true)

0 commit comments

Comments
 (0)