File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -36,10 +36,11 @@ pub(crate) fn prepare_rename(
36
36
let mut defs = find_definitions ( & sema, syntax, position) ?;
37
37
38
38
// TODO:
39
- // - is "No references found at position" the right error? (why does it not get caught by `find_definitions`... hmm)
39
+ // - `find_definitions` is implemented so that it returns a non-empty vec
40
+ // in the `Ok` case. But that's not expressed by the type signature, hence `unwrap()`
41
+ // here which ... wart.
40
42
// - is "just take the first `name_like`" correct? If not, what do?
41
- let ( name_like, _def) =
42
- defs. next ( ) . ok_or_else ( || format_err ! ( "No references found at position" ) ) ?;
43
+ let ( name_like, _def) = defs. next ( ) . unwrap ( ) ;
43
44
let frange = sema. original_range ( name_like. syntax ( ) ) ;
44
45
always ! ( frange. range. contains_inclusive( position. offset) && frange. file_id == position. file_id) ;
45
46
Ok ( RangeInfo :: new ( frange. range , ( ) ) )
@@ -168,7 +169,13 @@ fn find_definitions(
168
169
match v {
169
170
// remove duplicates
170
171
// TODO is "unique by `Definition`" correct?
171
- Ok ( v) => Ok ( v. into_iter ( ) . unique_by ( |t| t. 1 ) ) ,
172
+ Ok ( v) => {
173
+ if v. is_empty ( ) {
174
+ Err ( format_err ! ( "No references found at position" ) )
175
+ } else {
176
+ Ok ( v. into_iter ( ) . unique_by ( |t| t. 1 ) )
177
+ }
178
+ }
172
179
Err ( e) => Err ( e) ,
173
180
}
174
181
}
You can’t perform that action at this time.
0 commit comments