Skip to content

Commit f244ed6

Browse files
author
Anatol Ulrich
committed
doxx
1 parent 2e0610e commit f244ed6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

crates/ide/src/rename.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ pub(crate) fn prepare_rename(
3636
let mut defs = find_definitions(&sema, syntax, position)?;
3737

3838
// 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.
4042
// - 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();
4344
let frange = sema.original_range(name_like.syntax());
4445
always!(frange.range.contains_inclusive(position.offset) && frange.file_id == position.file_id);
4546
Ok(RangeInfo::new(frange.range, ()))
@@ -168,7 +169,13 @@ fn find_definitions(
168169
match v {
169170
// remove duplicates
170171
// 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+
}
172179
Err(e) => Err(e),
173180
}
174181
}

0 commit comments

Comments
 (0)