From d8571e076c0bbb3219fb3ed250279b158d75e683 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Jun 2020 13:17:22 +0200 Subject: Simplify --- crates/ra_db/src/input.rs | 12 ++++-------- crates/ra_db/src/lib.rs | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'crates/ra_db') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 4d2d3b48a..a8d6466ea 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -337,15 +337,11 @@ impl Env { } impl ExternSource { - pub fn extern_path(&self, path: impl AsRef) -> Option<(ExternSourceId, RelativePathBuf)> { - let path = path.as_ref(); + pub fn extern_path(&self, path: &Path) -> Option<(ExternSourceId, RelativePathBuf)> { self.extern_paths.iter().find_map(|(root_path, id)| { - if let Ok(rel_path) = path.strip_prefix(root_path) { - let rel_path = RelativePathBuf::from_path(rel_path).ok()?; - Some((*id, rel_path)) - } else { - None - } + let rel_path = path.strip_prefix(root_path).ok()?; + let rel_path = RelativePathBuf::from_path(rel_path).ok()?; + Some((*id, rel_path)) }) } diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 91e0ee619..2ab314884 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -158,7 +158,7 @@ impl FileLoader for FileLoaderDelegate<&'_ T> { if std::path::Path::new(path).is_absolute() { let krate = *self.relevant_crates(anchor).get(0)?; let (extern_source_id, relative_file) = - self.0.crate_graph()[krate].extern_source.extern_path(path)?; + self.0.crate_graph()[krate].extern_source.extern_path(path.as_ref())?; let source_root = self.0.source_root(SourceRootId(extern_source_id.0)); source_root.file_by_relative_path(&relative_file) -- cgit v1.2.3