1827: fix panic when fetching generics r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2019-09-12 10:15:29 +00:00 committed by GitHub
commit dfcbdcb9a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,7 +4,7 @@ use std::sync::Arc;
use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
use ra_syntax::{ use ra_syntax::{
ast::{self, AstNode}, ast::{self, AstNode},
AstPtr, SourceFile, AstPtr,
}; };
use crate::{ use crate::{
@ -29,12 +29,12 @@ impl ImplSourceMap {
} }
pub fn get(&self, source: &ModuleSource, impl_id: ImplId) -> ast::ImplBlock { pub fn get(&self, source: &ModuleSource, impl_id: ImplId) -> ast::ImplBlock {
let file = match source { let root = match source {
ModuleSource::SourceFile(file) => file.clone(), ModuleSource::SourceFile(file) => file.syntax().clone(),
ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), ModuleSource::Module(m) => m.syntax().ancestors().last().unwrap(),
}; };
self.map[impl_id].to_node(file.syntax()).to_owned() self.map[impl_id].to_node(&root)
} }
} }