4813: Simplify r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-06-09 11:22:38 +00:00 committed by GitHub
commit d4d384e4c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 9 deletions

View File

@ -337,15 +337,11 @@ pub fn get(&self, env: &str) -> Option<String> {
}
impl ExternSource {
pub fn extern_path(&self, path: impl AsRef<Path>) -> 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))
})
}

View File

@ -158,7 +158,7 @@ fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
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)