From 0ffd1fdbe4a7dd8707cb7eaf31c15dcd1d4fb101 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 12 Sep 2019 13:12:26 +0300 Subject: fix panic when fetching generics due to macro expansion, the root node is not always a file --- crates/ra_hir/src/impl_block.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 162ab02b1..d26a024ed 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; use ra_syntax::{ ast::{self, AstNode}, - AstPtr, SourceFile, + AstPtr, }; use crate::{ @@ -29,12 +29,12 @@ impl ImplSourceMap { } pub fn get(&self, source: &ModuleSource, impl_id: ImplId) -> ast::ImplBlock { - let file = match source { - ModuleSource::SourceFile(file) => file.clone(), - ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), + let root = match source { + ModuleSource::SourceFile(file) => file.syntax().clone(), + 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) } } -- cgit v1.2.3